{"record":{"id":"e954652c373dc3fc","repo":"JuliusBrussee/caveman","slug":"codex-caveman-config-block-changed-after-enable-r","errorCode":null,"errorMessage":"Codex Caveman config block changed after enable; refusing destructive disable","messagePattern":"Codex Caveman config block changed after enable; refusing destructive disable","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":8425,"sourceCode":"    if (typeof routeBlock !== \"string\" || !Array.isArray(previousRouteLines)) {\n      throw new Error(\"Hermes integration journal lacks owned routing block\");\n    }\n    if (!text.includes(routeBlock)) throw new Error(\"Hermes routing block changed after enable; refusing destructive disable\");\n    text = text.replace(routeBlock, previousRouteLines.filter((line): line is string => typeof line === \"string\").join(\"\\n\"));\n    for (const key of [\"plugin_block\", \"mcp_block\"] as const) {\n      const block = operation.owned?.[key];\n      if (block === null || block === undefined) continue;\n      if (typeof block !== \"string\" || !text.includes(block)) throw new Error(`Hermes ${key.replace(\"_block\", \"\")} block changed after enable; refusing destructive disable`);\n      text = text.replace(block, \"\");\n    }\n    return Buffer.from(text);\n  }\n  const rootBlock = operation.owned?.root_block;\n  const tablesBlock = operation.owned?.tables_block;\n  if (typeof rootBlock !== \"string\" || typeof tablesBlock !== \"string\") throw new Error(\"Codex integration journal lacks owned blocks\");\n  let text = current.toString(\"utf8\");\n  for (const [block, begin] of [[rootBlock, CODEX_NATIVE_ROOT_BEGIN], [tablesBlock, CODEX_NATIVE_TABLES_BEGIN]] as const) {\n    if (text.includes(begin) && !text.includes(block)) throw new Error(\"Codex Caveman config block changed after enable; refusing destructive disable\");\n    text = text.replace(`${block}\\n\\n`, \"\").replace(`\\n\\n${block}\\n`, \"\\n\").replace(block, \"\");\n  }\n  return Buffer.from(text);\n}\n\nfunction writeNativeRestoration(file: string, bytes: Buffer | null): void {\n  if (bytes) {\n    atomicWriteFile(file, bytes);\n    return;\n  }\n  try { unlinkSync(file); } catch (error) {\n    if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n  }\n}\n\nfunction restoreNativeJournalFiles(journal: NativeJournal): Array<{ file: string; bytes: Buffer | null }> {\n  // Resolve every merge/conflict before first write. A conflict therefore leaves\n  // all host files and the journal byte-identical.","sourceCodeStart":8407,"sourceCodeEnd":8443,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L8407-L8443","documentation":"During 'codex caveman disable', the CLI rewrites Codex's native config by removing the marker blocks (root and tables) that were journaled at enable time. If the file still contains the native begin markers but no longer contains the exact journaled block text, the config was hand-edited or reformatted after enable, and the CLI refuses to disable rather than corrupt the file.","triggerScenarios":"Running the caveman disable/repair command for the Codex agent when the user (or another tool) edited, reformatted, reordered, or partially deleted the Caveman-managed config blocks in the Codex config file after `caveman enable` recorded them in the integration journal.","commonSituations":"Manual edits to ~/.codex config (tweaking settings, re-indenting, merging blocks), running Codex-native config migrations/upgrades that rewrite the file, or re-enabling with a different Caveman version that renders blocks differently than the journaled copy.","solutions":["Open the Codex config file and either restore the exact Caveman block as journaled, or manually delete the Caveman-managed block (everything from CODEX_NATIVE_ROOT_BEGIN / CODEX_NATIVE_TABLES_BEGIN markers) then re-run disable","Re-run `caveman enable` (or the repair command) to regenerate and re-journal the current blocks, then run disable again","Restore the config file from a backup taken before the manual edit and retry disable"],"exampleFix":"// before (edited config breaks disable)\n# caveman:begin root\nmodel = gpt-5  // hand-tweaked line inside managed block\n# caveman:end\n// after: either revert the edit exactly, or manually remove the whole block between the begin/end markers, then re-run disable\n$ caveman codex disable","handlingStrategy":"validation","validationCode":"import { readFileSync } from 'node:fs';\nconst text = readFileSync(codexConfigPath, 'utf8');\nconst journal = readNativeJournal('codex');\nconst hasBegin = text.includes(CODEX_NATIVE_ROOT_BEGIN) || text.includes(CODEX_NATIVE_TABLES_BEGIN);\nconst blocksIntact = !hasBegin || (typeof journal?.root_block === 'string' && text.includes(journal.root_block) && typeof journal?.tables_block === 'string' && text.includes(journal.tables_block));\nif (!blocksIntact) throw new Error('Codex config was modified after enable; restore blocks or re-enable before disabling');","typeGuard":"function blocksIntact(text: string, journal: { root_block?: unknown; tables_block?: unknown } | null): boolean {\n  return typeof journal?.root_block === 'string' && typeof journal?.tables_block === 'string' && text.includes(journal.root_block) && text.includes(journal.tables_block);\n}","tryCatchPattern":"try {\n  await caveman.codex.disable();\n} catch (err) {\n  if (err instanceof Error && err.message.includes('config block changed after enable')) {\n    // restore journaled blocks or manually remove the managed block, then retry\n  } else throw err;\n}","preventionTips":["Do not hand-edit the Caveman-managed block between the begin/end markers in the Codex config","After editing Codex config manually, re-run `caveman enable` to refresh the journal before disabling","Keep a backup of the config from enable time so the exact blocks can be restored for disable"],"tags":["cli","codex","config-block","safety-guard"],"backgroundTag":"conflicting-config-options","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}