{"record":{"id":"ba03cba624f6f57a","repo":"JuliusBrussee/caveman","slug":"operation-file-changed-during-interrupted-age","errorCode":null,"errorMessage":"${operation.file} changed during interrupted ${agent} install; refusing recovery","messagePattern":"(.+?) changed during interrupted (.+?) install; refusing recovery","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":8084,"sourceCode":"  if (!pending) return false;\n  const committed = readNativeJournal(agent);\n  if (committed) {\n    if (JSON.stringify(committed) !== JSON.stringify(pending)) {\n      throw new Error(`conflicting committed and pending integration journals for ${agent}; refusing recovery`);\n    }\n    unlinkSync(nativePendingJournalPath(agent));\n    return false;\n  }\n  const current = pending.operations.map((operation) => ({ file: operation.file, bytes: fileBytes(operation.file) }));\n  const restored = pending.operations.map((operation) => {\n    const before = nativeBackupBytes(operation);\n    const now = fileBytes(operation.file);\n    const isInstalled = Boolean(now && bytesHash(now) === operation.after_sha256);\n    const isBefore = operation.before_exists\n      ? Boolean(now && operation.before_sha256 && bytesHash(now) === operation.before_sha256)\n      : now === null;\n    if (!isInstalled && !isBefore) {\n      throw new Error(`${operation.file} changed during interrupted ${agent} install; refusing recovery`);\n    }\n    return { file: operation.file, bytes: before };\n  });\n  try {\n    for (const item of restored) writeNativeRestoration(item.file, item.bytes);\n    unlinkSync(nativePendingJournalPath(agent));\n  } catch (error) {\n    for (const item of current) {\n      try { writeNativeRestoration(item.file, item.bytes); } catch { /* original error remains authority */ }\n    }\n    throw error;\n  }\n  process.stderr.write(`${mark(\"warn\")} recovered interrupted ${agent} integration change before continuing\\n`);\n  return true;\n}\n\nfunction nativeMutationsFor(agent: NativeAgent, gw: string, mcpBinary: string | undefined): NativeMutation[] {\n  return agent === \"claude\"","sourceCodeStart":8066,"sourceCodeEnd":8102,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L8066-L8102","documentation":"To roll back an interrupted install, each journaled operation's target file is hashed and compared against the journal's `after_sha256` (install applied) or `before_sha256`/absence (install not yet applied). If the file matches neither state, something modified it outside the journaled install, and replaying the rollback would destroy those changes, so recovery refuses.","triggerScenarios":"Recovery runs while a journaled operation's file was edited after the interrupted install — e.g. the user changed the agent config, another tool rewrote it, or the install itself wrote an unexpected byte sequence.","commonSituations":"User manually edits their agent config between the crash and the retry; a config sync tool overwrites files; the agent app rewrites its own config on startup before caveman recovery runs.","solutions":["Revert the file to either its pre-install content or the install's written content (check backups/editor history), then rerun recovery.","If the new content is wanted, delete the pending journal and manually apply or skip the corresponding change, then rerun the install.","Restore the file from version control or a backup so its hash matches the journaled before/after state.","Compare the file against `after_sha256`/`before_sha256` in the pending journal to see which state it should be in."],"exampleFix":"# before\nnano ~/.aider/config.yml  # edits during pending recovery\n# after\ngit checkout -- ~/.aider/config.yml && caveman doctor aider --fix","handlingStrategy":"try-catch","validationCode":"import { createHash } from \"node:crypto\";\nconst sha = (b: Buffer | null) => b ? createHash(\"sha256\").update(b).digest(\"hex\") : null;\nfor (const op of pendingOps) {\n  const h = sha(fileBytes(op.file));\n  if (h !== op.after_sha256 && h !== op.before_sha256) console.error(\"file drifted from journal:\", op.file);\n}","typeGuard":"const matchesJournalState = (h: string | null, op: { after_sha256: string; before_sha256?: string }) => h === op.after_sha256 || (op.before_sha256 != null && h === op.before_sha256);","tryCatchPattern":"try { install(agent); } catch (e) { if (String(e.message).includes(\"changed during interrupted\")) { restoreFileFromBackup(op.file) ?? discardPendingJournal(agent); } }","preventionTips":["Do not edit agent config files while an install/recovery is pending.","Run recovery (doctor --fix) promptly after a crash, before other tools touch configs.","Disable config-sync tools (dotfile managers) that might rewrite agent configs mid-install.","Keep the agent config under version control so drift can be reverted."],"tags":["journal","recovery","integrity"],"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"}