{"record":{"id":"812fc8f4ca9b2390","repo":"JuliusBrussee/caveman","slug":"existing-codex-caveman-block-is-corrupted-run-ca","errorCode":null,"errorMessage":"existing Codex Caveman block is corrupted; run `caveman doctor codex`","messagePattern":"existing Codex Caveman block is corrupted; run `caveman doctor codex`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":6452,"sourceCode":"      kind: \"aider-config\",\n      owned: { route, route_block: native.routeBlock, previous_route_line: native.previousRouteLine, read_block: native.readBlock, core_path: corePath },\n    },\n    {\n      file: corePath,\n      before: coreBefore,\n      after: Buffer.from(core),\n      kind: \"aider-core\",\n      owned: { marker: AIDER_NATIVE_CORE_MARKER },\n    },\n  ];\n}\n\nfunction codexNativeConfig(source: string, gw: string, subscription: boolean, mcpBinary: string): { text: string; rootBlock: string; tablesBlock: string } {\n  let stripped = stripCodexCavemanMcpToml(stripCodexCavemanProviderToml(source));\n  for (const [begin, end] of [[CODEX_NATIVE_ROOT_BEGIN, CODEX_NATIVE_ROOT_END], [CODEX_NATIVE_TABLES_BEGIN, CODEX_NATIVE_TABLES_END]] as const) {\n    const start = stripped.indexOf(begin);\n    const finish = stripped.indexOf(end);\n    if ((start === -1) !== (finish === -1)) throw new Error(\"existing Codex Caveman block is corrupted; run `caveman doctor codex`\");\n    if (start !== -1) stripped = `${stripped.slice(0, start)}${stripped.slice(finish + end.length)}`.trim();\n  }\n  const rootBlock = `${CODEX_NATIVE_ROOT_BEGIN}\\nmodel_provider = \"caveman\"\\n${CODEX_NATIVE_ROOT_END}`;\n  const providerLines = codexCavemanProviderToml(gw, subscription).split(\"\\n\").slice(1).join(\"\\n\");\n  const tablesBlock = [\n    CODEX_NATIVE_TABLES_BEGIN,\n    providerLines,\n    \"\",\n    \"[mcp_servers.caveman]\",\n    `command = ${JSON.stringify(mcpBinary)}`,\n    CODEX_NATIVE_TABLES_END,\n  ].join(\"\\n\");\n  const middle = stripped ? `\\n\\n${stripped}` : \"\";\n  return { text: `${rootBlock}${middle}\\n\\n${tablesBlock}\\n`, rootBlock, tablesBlock };\n}\n\nfunction codexNativeMutations(gw: string, mcpBinary: string): NativeMutation[] {\n  const hooksPath = codexHooksPath();","sourceCodeStart":6434,"sourceCodeEnd":6470,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/packages/cli/src/index.ts#L6434-L6470","documentation":"codexNativeConfig() strips previously stamped Caveman blocks from ~/.codex/config.toml (via stripCodexCavemanMcpToml/ProviderToml, then CODEX_NATIVE_ROOT/TABLES BEGIN/END pairs). For each marker pair it throws when BEGIN exists without END (or vice versa) — the managed TOML block was partially deleted or reordered and cannot be safely re-stamped.","triggerScenarios":"Native Codex install when config.toml contains a CODEX_NATIVE_ROOT_BEGIN or CODEX_NATIVE_TABLES_BEGIN marker without its matching END marker (asymmetric presence check per pair).","commonSituations":"Manual cleanup that deleted half the marked block; editor truncation; uninstall that removed only the END line; merge conflict resolution in dotfiles.","solutions":["Run `caveman doctor codex` to repair the corrupted block","Or hand-edit ~/.codex/config.toml: remove the orphaned marker line and any partial block content between it and the next section, leaving no Caveman markers","Re-run the codex native install"],"exampleFix":"# before — ~/.codex/config.toml\n# <<< CAVEMAN NATIVE ROOT BEGIN <<<\nmodel_provider = \"caveman\"\n# (END marker missing)\n\n# after — marker block fully removed (or `caveman doctor codex`), then reinstall re-stamps both markers","handlingStrategy":"validation","validationCode":"import { readFileSync } from \"node:fs\";\nfunction codexMarkersBalanced(path: string, pairs: [string, string][]): boolean {\n  let src: string;\n  try { src = readFileSync(path, \"utf8\"); } catch { return true; }\n  return pairs.every(([b, e]) => {\n    const bi = src.indexOf(b), ei = src.indexOf(e);\n    return (bi === -1) === (ei === -1) && (bi === -1 || ei > bi);\n  });\n}","typeGuard":null,"tryCatchPattern":"try { nativeInstallCodex(); } catch (e) {\n  if (e instanceof Error && /Codex Caveman block is corrupted/.test(e.message)) {\n    spawnSync(\"caveman\", [\"doctor\", \"codex\"], { stdio: \"inherit\" });\n    nativeInstallCodex();\n  } else throw e;\n}","preventionTips":["Delete Caveman marker blocks whole (BEGIN through END) when editing config.toml","Run caveman doctor codex after any manual cleanup of managed TOML","Review the full block before saving partial deletions"],"tags":["codex","toml","markers","corruption","merge-safety"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}