{"record":{"id":"82ee0637813d8aee","repo":"JuliusBrussee/caveman","slug":"caveman-build-cyclic-agent-definition-is-not-lock","errorCode":null,"errorMessage":"caveman build: cyclic agent definition is not lockable","messagePattern":"caveman build: cyclic agent definition is not lockable","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/build.ts","lineNumber":584,"sourceCode":"}\n\nexport function contextIRSHA256(contextIR: ContextIR): string {\n  return sha256(stableStringify(contextIRToWire(contextIR)));\n}\n\nfunction lockableValue(value: unknown, seen: WeakSet<object>): unknown {\n  if (value === null || typeof value === \"string\" || typeof value === \"boolean\" ||\n      typeof value === \"number\") {\n    return value;\n  }\n  if (typeof value === \"bigint\") return { cave_bigint: value.toString() };\n  if (typeof value === \"function\" || typeof value === \"undefined\" || typeof value === \"symbol\") {\n    return undefined;\n  }\n  if (typeof value !== \"object\") {\n    throw new Error(\"caveman build: agent definition contains an unsupported value\");\n  }\n  if (seen.has(value)) throw new Error(\"caveman build: cyclic agent definition is not lockable\");\n  seen.add(value);\n  try {\n    if (Array.isArray(value)) {\n      return value.map((item) => lockableValue(item, seen) ?? null);\n    }\n    const projected: Record<string, unknown> = {};\n    for (const [key, item] of Object.entries(value)) {\n      const locked = lockableValue(item, seen);\n      if (locked !== undefined) projected[key] = locked;\n    }\n    const implementationSource = Reflect.get(\n      value,\n      Symbol.for(\"@caveman-ai/agent:tool-implementation-source\"),\n    );\n    if (typeof implementationSource === \"string\") {\n      projected.cave_tool_implementation_sha256 = sha256(implementationSource);\n    }\n    return projected;","sourceCodeStart":566,"sourceCodeEnd":602,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/build.ts#L566-L602","documentation":"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.","triggerScenarios":"Thrown at packages/agent/src/build.ts:584 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Break the cycle in the agent definition by removing the back-reference","Refer to shared objects by identifier instead of nesting them","Flatten the definition into plain acyclic JSON data before building"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}