JuliusBrussee/caveman · error
integration backup hash mismatch
Error message
integration backup hash mismatch: ${operation.backup} What it means
During journal-based restore, `nativeBackupBytes` reads the pre-enable backup file recorded in an integration journal operation and verifies its SHA-256 against `operation.before_sha256`. If the hash no longer matches, the backup has been modified or corrupted since enable time, so the CLI refuses to trust or restore from it. This is a tamper/integrity guard preventing restoration from untrustworthy data.
Solutions
- Delete or move the corrupt backup and journal, then manually restore the agent config (recreate hooks/env/MCP entries by hand or re-run doctor --fix).
- Re-verify the backup: recompute `sha256` of the backup file and compare with the journal's `before_sha256` to confirm which side changed.
- Restore the original file from an external backup (git, editor history, Time Machine) instead of the journal backup.
- If the backup corruption is expected/acceptable, update the journal's `before_sha256` only if you are certain the current backup is the intended content.
Example fix
// verify before restore
import { createHash } from "node:crypto";
const backup = readFileSync(operation.backup);
const hash = createHash("sha256").update(backup).digest("hex");
if (hash !== operation.before_sha256) {
// restore from git/external backup instead of trusting the journal
} Defensive patterns
Strategy: validation
Validate before calling
import { createHash } from "node:crypto";
import { readFileSync, existsSync } from "node:fs";
function backupIsIntact(op) {
if (!op.before_exists) return true;
if (!existsSync(op.backup)) return false;
const hash = createHash("sha256").update(readFileSync(op.backup)).digest("hex");
return hash === op.before_sha256;
}
// check every journal operation before running disable Prevention
- Never edit or move the journal's backup files.
- Keep the journal and its backups together when copying project state between machines.
- Snapshot agent config files (e.g. with git) before enabling integrations so you have an independent restore path.
When it happens
Trigger: Any disable/restore path that calls `nativeBackupBytes(operation)` for an operation with `before_exists: true` where `bytesHash(readFileSync(operation.backup)) !== operation.before_sha256`.
Common situations: The backup file was edited by hand; disk corruption; the backup was overwritten by another tool or a second caveman run; copying the journal without the matching backup.
Understand the failure class
Background: Checksum mismatch errors: "checksum verification failed", "digest mismatch", "expected vs actual checksum" — what they mean and how to fix them — this error's family across 41 libraries.
Related errors
- cave_sandbox_tool_definition_mismatch
- conflicting committed and pending integration journals for
- journal bytes do not match declared transaction state
- changed during interrupted install; refusing recovery
- proposalrun: seq row_hash mismatch (tampered)
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/0035b271043949bd.
Report an issue: GitHub.
Appendix: source
Thrown at packages/cli/src/index.ts:8201
continue;
}
process.stderr.write(`${mark("ok")} ${profile.display_name}: ${agent === "aider" ? "shallow" : "native"} Caveman enabled; run ${agent} normally\n`);
if (agent !== "aider") process.stderr.write(dim(`→ host trust remains authoritative; approve Caveman hooks/plugin when ${profile.display_name} asks\n`));
if (agent === "codex") process.stderr.write(dim("→ review/approve hook hashes through Codex /hooks; Caveman does not bypass native trust\n"));
if (agent === "aider") {
process.stderr.write(dim(`→ coding policy: Core ${NATIVE_PACK.version} static on; Aider cannot apply think.core live; \`caveman disable aider\` removes it\n`));
} else {
const core = wrapRuntimeConfig().core;
process.stderr.write(dim(`→ coding policy: Core ${NATIVE_PACK.version} ${core ? "on" : "off"}; change with \`caveman tools config set think.core ${core ? "off" : "on"}\`; start new session to clear previously delivered context\n`));
}
process.stderr.write(dim(`→ undo: caveman disable ${agent}\n`));
}
}
function nativeBackupBytes(operation: NativeJournal["operations"][number]): Buffer | null {
if (!operation.before_exists) return null;
const bytes = readFileSync(operation.backup);
if (operation.before_sha256 && bytesHash(bytes) !== operation.before_sha256) throw new Error(`integration backup hash mismatch: ${operation.backup}`);
return bytes;
}
function removeNativeHookEntries(root: Record<string, unknown>, agent: "claude" | "codex" | "gemini"): Record<string, unknown> {
const hooks = root.hooks && typeof root.hooks === "object" && !Array.isArray(root.hooks)
? root.hooks as Record<string, unknown>
: undefined;
if (!hooks) return root;
// `true` on purpose, unlike the writers: disable must withdraw a shrink entry
// an earlier install wrote, whatever the config says now.
const expected = nativeHooksDocument(agent, true).hooks as Record<string, unknown>;
const allowedManaged = new Set(
Object.values(expected)
.flatMap((raw) => Array.isArray(raw) ? raw as Array<Record<string, unknown>> : [])
.map(canonicalManagedHookEntry)
.filter(Boolean),
);
for (const event of Object.keys(hooks)) {View on GitHub (pinned to 3ee70a1026)