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

  1. Re-run `caveman-agent build` to regenerate a current lock, then run doctor again without concurrent builds.
  2. Ensure no other caveman process (dev watcher, CI build) is running against the same project simultaneously.
  3. If the lock is stale from an upgrade, delete .caveman/agent.lock.json and rebuild.
  4. 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

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


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)