{"record":{"id":"b2a249c941593039","repo":"JuliusBrussee/caveman","slug":"lock-disappeared-during-validation","errorCode":null,"errorMessage":"lock disappeared during validation","messagePattern":"lock disappeared during validation","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/cli.ts","lineNumber":231,"sourceCode":"      status: \"warn\",\n      detail: `gateway not reachable at ${gatewayURL} — telemetry off, runs are observe-only`,\n      fix: \"npm i -g @caveman-ai/cli && caveman start\",\n    });\n\n  const configPath = resolve(root, \"caveman.config.ts\");\n  try {\n    await readFile(configPath);\n    const loaded = await loadBuildInputs(root, \"caveman.config.ts\");\n    await lowerBuildContext(root, loaded.agent);\n    checks.push({\n      id: \"project\",\n      status: \"pass\",\n      detail: `${loaded.agent.id}: config, entry, eval graph, and static Context IR load`,\n    });\n    try {\n      await readFile(resolve(root, \".caveman/agent.lock.json\"));\n      const lock = await validLockIdentity(root, loaded.config.entry, loaded.agent);\n      if (!lock) throw new Error(\"lock disappeared during validation\");\n      checks.push({\n        id: \"lock\",\n        status: \"pass\",\n        detail: `${lock.harness.id} build ${lock.build_sha256.slice(0, 12)} is current`,\n      });\n    } catch (error) {\n      if ((error as NodeJS.ErrnoException).code === \"ENOENT\") {\n        checks.push({\n          id: \"lock\",\n          status: \"warn\",\n          detail: \"no Cave Build lock; dev runs unlocked\",\n          fix: \"approve required evals, then run caveman-agent build\",\n        });\n      } else {\n        checks.push({\n          id: \"lock\",\n          status: \"fail\",\n          detail: safeDiagnostic(error),","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/cli.ts#L213-L249","documentation":"doctor's lock check validates the build lock (.caveman/agent.lock.json): it re-reads the lock file and runs validLockIdentity to confirm the lock still matches the current config, entry, and agent. If validation returns falsy after the file existed, it throws \"lock disappeared during validation\" — the lock was removed or invalidated between the read and validation.","triggerScenarios":"Running doctor while another process (a concurrent build, `caveman-agent dev` watcher, or a clean step) deletes or rewrites the lock file; validLockIdentity rejecting a stale/incompatible lock and returning null.","commonSituations":"A parallel `caveman-agent build` regenerating the lock during doctor; git checkout/clean switching branches mid-run; a lock from a different agent version that no longer validates.","solutions":["Re-run `caveman-agent build` to regenerate a current lock, then run doctor again without concurrent builds.","Ensure no other caveman process (dev watcher, CI build) is running against the same project simultaneously.","If the lock is stale from an upgrade, delete .caveman/agent.lock.json and rebuild.","Re-run doctor; a transient race usually clears on a second run."],"exampleFix":"// before\ncaveman-agent build & caveman-agent doctor  # concurrent build races the lock\n// after\ncaveman-agent build && caveman-agent doctor","handlingStrategy":"try-catch","validationCode":"import { readFile } from \"node:fs/promises\";\nasync function lockIsStable(root, ms = 500) {\n  const p = `${root}/.caveman/agent.lock.json`;\n  const a = await readFile(p, \"utf8\").catch(() => null);\n  await new Promise((r) => setTimeout(r, ms));\n  const b = await readFile(p, \"utf8\").catch(() => null);\n  return a !== null && a === b;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await runDoctor();\n} catch (e) {\n  if (e.message === \"lock disappeared during validation\") {\n    console.error(\"Lock changed during validation; ensure no concurrent build/dev is running, rebuild, and retry\");\n  } else throw e;\n}","preventionTips":["Never run doctor concurrently with caveman-agent build or an active dev watcher","Rebuild the lock after dependency or agent-definition changes","Serialize doctor/build steps in CI pipelines"],"tags":["lock","race-condition","diagnostics","build"],"backgroundTag":"invalid-state-transition","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"}