JuliusBrussee/caveman · error

Codex Caveman config block changed after enable; refusing…

Error message

Codex Caveman config block changed after enable; refusing destructive disable

What it means

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.

Solutions

  1. 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
  2. Re-run `caveman enable` (or the repair command) to regenerate and re-journal the current blocks, then run disable again
  3. Restore the config file from a backup taken before the manual edit and retry disable

Example fix

// before (edited config breaks disable)
# caveman:begin root
model = gpt-5  // hand-tweaked line inside managed block
# caveman:end
// after: either revert the edit exactly, or manually remove the whole block between the begin/end markers, then re-run disable
$ caveman codex disable
Defensive patterns

Strategy: validation

Validate before calling

import { readFileSync } from 'node:fs';
const text = readFileSync(codexConfigPath, 'utf8');
const journal = readNativeJournal('codex');
const hasBegin = text.includes(CODEX_NATIVE_ROOT_BEGIN) || text.includes(CODEX_NATIVE_TABLES_BEGIN);
const blocksIntact = !hasBegin || (typeof journal?.root_block === 'string' && text.includes(journal.root_block) && typeof journal?.tables_block === 'string' && text.includes(journal.tables_block));
if (!blocksIntact) throw new Error('Codex config was modified after enable; restore blocks or re-enable before disabling');

Type guard

function blocksIntact(text: string, journal: { root_block?: unknown; tables_block?: unknown } | null): boolean {
  return typeof journal?.root_block === 'string' && typeof journal?.tables_block === 'string' && text.includes(journal.root_block) && text.includes(journal.tables_block);
}

Try / catch

try {
  await caveman.codex.disable();
} catch (err) {
  if (err instanceof Error && err.message.includes('config block changed after enable')) {
    // restore journaled blocks or manually remove the managed block, then retry
  } else throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/e954652c373dc3fc. Report an issue: GitHub.

Appendix: source

Thrown at packages/cli/src/index.ts:8425

    if (typeof routeBlock !== "string" || !Array.isArray(previousRouteLines)) {
      throw new Error("Hermes integration journal lacks owned routing block");
    }
    if (!text.includes(routeBlock)) throw new Error("Hermes routing block changed after enable; refusing destructive disable");
    text = text.replace(routeBlock, previousRouteLines.filter((line): line is string => typeof line === "string").join("\n"));
    for (const key of ["plugin_block", "mcp_block"] as const) {
      const block = operation.owned?.[key];
      if (block === null || block === undefined) continue;
      if (typeof block !== "string" || !text.includes(block)) throw new Error(`Hermes ${key.replace("_block", "")} block changed after enable; refusing destructive disable`);
      text = text.replace(block, "");
    }
    return Buffer.from(text);
  }
  const rootBlock = operation.owned?.root_block;
  const tablesBlock = operation.owned?.tables_block;
  if (typeof rootBlock !== "string" || typeof tablesBlock !== "string") throw new Error("Codex integration journal lacks owned blocks");
  let text = current.toString("utf8");
  for (const [block, begin] of [[rootBlock, CODEX_NATIVE_ROOT_BEGIN], [tablesBlock, CODEX_NATIVE_TABLES_BEGIN]] as const) {
    if (text.includes(begin) && !text.includes(block)) throw new Error("Codex Caveman config block changed after enable; refusing destructive disable");
    text = text.replace(`${block}\n\n`, "").replace(`\n\n${block}\n`, "\n").replace(block, "");
  }
  return Buffer.from(text);
}

function writeNativeRestoration(file: string, bytes: Buffer | null): void {
  if (bytes) {
    atomicWriteFile(file, bytes);
    return;
  }
  try { unlinkSync(file); } catch (error) {
    if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
  }
}

function restoreNativeJournalFiles(journal: NativeJournal): Array<{ file: string; bytes: Buffer | null }> {
  // Resolve every merge/conflict before first write. A conflict therefore leaves
  // all host files and the journal byte-identical.

View on GitHub (pinned to 3ee70a1026)