{"record":{"id":"0035b271043949bd","repo":"JuliusBrussee/caveman","slug":"integration-backup-hash-mismatch-operation-back","errorCode":null,"errorMessage":"integration backup hash mismatch: ${operation.backup}","messagePattern":"integration backup hash mismatch: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":8201,"sourceCode":"      continue;\n    }\n    process.stderr.write(`${mark(\"ok\")} ${profile.display_name}: ${agent === \"aider\" ? \"shallow\" : \"native\"} Caveman enabled; run ${agent} normally\\n`);\n    if (agent !== \"aider\") process.stderr.write(dim(`→ host trust remains authoritative; approve Caveman hooks/plugin when ${profile.display_name} asks\\n`));\n    if (agent === \"codex\") process.stderr.write(dim(\"→ review/approve hook hashes through Codex /hooks; Caveman does not bypass native trust\\n\"));\n    if (agent === \"aider\") {\n      process.stderr.write(dim(`→ coding policy: Core ${NATIVE_PACK.version} static on; Aider cannot apply think.core live; \\`caveman disable aider\\` removes it\\n`));\n    } else {\n      const core = wrapRuntimeConfig().core;\n      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`));\n    }\n    process.stderr.write(dim(`→ undo: caveman disable ${agent}\\n`));\n  }\n}\n\nfunction nativeBackupBytes(operation: NativeJournal[\"operations\"][number]): Buffer | null {\n  if (!operation.before_exists) return null;\n  const bytes = readFileSync(operation.backup);\n  if (operation.before_sha256 && bytesHash(bytes) !== operation.before_sha256) throw new Error(`integration backup hash mismatch: ${operation.backup}`);\n  return bytes;\n}\n\nfunction removeNativeHookEntries(root: Record<string, unknown>, agent: \"claude\" | \"codex\" | \"gemini\"): Record<string, unknown> {\n  const hooks = root.hooks && typeof root.hooks === \"object\" && !Array.isArray(root.hooks)\n    ? root.hooks as Record<string, unknown>\n    : undefined;\n  if (!hooks) return root;\n  // `true` on purpose, unlike the writers: disable must withdraw a shrink entry\n  // an earlier install wrote, whatever the config says now.\n  const expected = nativeHooksDocument(agent, true).hooks as Record<string, unknown>;\n  const allowedManaged = new Set(\n    Object.values(expected)\n      .flatMap((raw) => Array.isArray(raw) ? raw as Array<Record<string, unknown>> : [])\n      .map(canonicalManagedHookEntry)\n      .filter(Boolean),\n  );\n  for (const event of Object.keys(hooks)) {","sourceCodeStart":8183,"sourceCodeEnd":8219,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L8183-L8219","documentation":"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.","triggerScenarios":"Any disable/restore path that calls `nativeBackupBytes(operation)` for an operation with `before_exists: true` where `bytesHash(readFileSync(operation.backup)) !== operation.before_sha256`.","commonSituations":"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.","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."],"exampleFix":"// verify before restore\nimport { createHash } from \"node:crypto\";\nconst backup = readFileSync(operation.backup);\nconst hash = createHash(\"sha256\").update(backup).digest(\"hex\");\nif (hash !== operation.before_sha256) {\n  // restore from git/external backup instead of trusting the journal\n}","handlingStrategy":"validation","validationCode":"import { createHash } from \"node:crypto\";\nimport { readFileSync, existsSync } from \"node:fs\";\nfunction backupIsIntact(op) {\n  if (!op.before_exists) return true;\n  if (!existsSync(op.backup)) return false;\n  const hash = createHash(\"sha256\").update(readFileSync(op.backup)).digest(\"hex\");\n  return hash === op.before_sha256;\n}\n// check every journal operation before running disable","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["integrity","hash-mismatch","backup","journal"],"backgroundTag":"checksum-mismatch","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"}