JuliusBrussee/caveman · error

caveman build: cyclic agent definition is not lockable

Error message

caveman build: cyclic agent definition is not lockable

What it means

Thrown by lockableValue when the agent definition contains a reference cycle (an object reachable from itself). The seen WeakSet detects the loop, since a cyclic structure has no finite stable serialization and cannot be hashed into the build lock.

Solutions

  1. Break the cycle in the agent definition by removing the back-reference
  2. Refer to shared objects by identifier instead of nesting them
  3. Flatten the definition into plain acyclic JSON data before building
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/agent/src/build.ts:584 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/82ee0637813d8aee. Report an issue: GitHub.

Appendix: source

Thrown at packages/agent/src/build.ts:584

}

export function contextIRSHA256(contextIR: ContextIR): string {
  return sha256(stableStringify(contextIRToWire(contextIR)));
}

function lockableValue(value: unknown, seen: WeakSet<object>): unknown {
  if (value === null || typeof value === "string" || typeof value === "boolean" ||
      typeof value === "number") {
    return value;
  }
  if (typeof value === "bigint") return { cave_bigint: value.toString() };
  if (typeof value === "function" || typeof value === "undefined" || typeof value === "symbol") {
    return undefined;
  }
  if (typeof value !== "object") {
    throw new Error("caveman build: agent definition contains an unsupported value");
  }
  if (seen.has(value)) throw new Error("caveman build: cyclic agent definition is not lockable");
  seen.add(value);
  try {
    if (Array.isArray(value)) {
      return value.map((item) => lockableValue(item, seen) ?? null);
    }
    const projected: Record<string, unknown> = {};
    for (const [key, item] of Object.entries(value)) {
      const locked = lockableValue(item, seen);
      if (locked !== undefined) projected[key] = locked;
    }
    const implementationSource = Reflect.get(
      value,
      Symbol.for("@caveman-ai/agent:tool-implementation-source"),
    );
    if (typeof implementationSource === "string") {
      projected.cave_tool_implementation_sha256 = sha256(implementationSource);
    }
    return projected;

View on GitHub (pinned to 3ee70a1026)