JuliusBrussee/caveman · error
lock disappeared during validation
Error message
lock disappeared during validation
What it means
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.
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.
Example fix
// before caveman-agent build & caveman-agent doctor # concurrent build races the lock // after caveman-agent build && caveman-agent doctor
Defensive patterns
Strategy: try-catch
Validate before calling
import { readFile } from "node:fs/promises";
async function lockIsStable(root, ms = 500) {
const p = `${root}/.caveman/agent.lock.json`;
const a = await readFile(p, "utf8").catch(() => null);
await new Promise((r) => setTimeout(r, ms));
const b = await readFile(p, "utf8").catch(() => null);
return a !== null && a === b;
} Try / catch
try {
await runDoctor();
} catch (e) {
if (e.message === "lock disappeared during validation") {
console.error("Lock changed during validation; ensure no concurrent build/dev is running, rebuild, and retry");
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- adapter-specific build_sha256 values must differ
- agent conformance fixtures must cover claude and pi
- agent conformance mismatch
- MCP config target changed while acquiring lock; refusing…
- MCP rollback postflight mismatch
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/b2a249c941593039.
Report an issue: GitHub.
Appendix: source
Thrown at packages/agent/src/cli.ts:231
status: "warn",
detail: `gateway not reachable at ${gatewayURL} — telemetry off, runs are observe-only`,
fix: "npm i -g @caveman-ai/cli && caveman start",
});
const configPath = resolve(root, "caveman.config.ts");
try {
await readFile(configPath);
const loaded = await loadBuildInputs(root, "caveman.config.ts");
await lowerBuildContext(root, loaded.agent);
checks.push({
id: "project",
status: "pass",
detail: `${loaded.agent.id}: config, entry, eval graph, and static Context IR load`,
});
try {
await readFile(resolve(root, ".caveman/agent.lock.json"));
const lock = await validLockIdentity(root, loaded.config.entry, loaded.agent);
if (!lock) throw new Error("lock disappeared during validation");
checks.push({
id: "lock",
status: "pass",
detail: `${lock.harness.id} build ${lock.build_sha256.slice(0, 12)} is current`,
});
} catch (error) {
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
checks.push({
id: "lock",
status: "warn",
detail: "no Cave Build lock; dev runs unlocked",
fix: "approve required evals, then run caveman-agent build",
});
} else {
checks.push({
id: "lock",
status: "fail",
detail: safeDiagnostic(error),View on GitHub (pinned to 3ee70a1026)