{"record":{"id":"c8890eb8d864399d","repo":"JuliusBrussee/caveman","slug":"cave-transform-trace-limit","errorCode":"cave_transform_trace_limit","errorMessage":"cave_transform_trace_limit","messagePattern":"cave_transform_trace_limit","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/runtime.ts","lineNumber":3673,"sourceCode":"  return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction volatileStablePrefix(instructions: string, tools: readonly ToolDefinition[]): boolean {\n  const value = `${instructions}\\n${stableStringify(tools.map((item) => ({\n    name: item.name,\n    description: item.description,\n    input: item.input,\n  })))}`;\n  return [\n    /\\b20[0-9]{2}-[01][0-9]-[0-3][0-9][T ][0-2][0-9]:[0-5][0-9]/,\n    /\\b[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\\b/i,\n    /[\"'](?:run|request|build|trace|span)[_-]?id[\"']\\s*:/i,\n    /[\"']nonce[\"']\\s*:/i,\n  ].some((pattern) => pattern.test(value));\n}\n\nfunction serializeTransformTrace(trace: readonly TransformTrace[]): string {\n  if (trace.length > 64) throw new Error(\"cave_transform_trace_limit\");\n  const value = trace.map((item) => [\n    item.transformID,\n    item.segmentKind,\n    item.safetyClass,\n    item.outcome,\n    item.beforeTokens,\n    item.afterTokens,\n    item.recoveryKind,\n    item.recoveryUsed ? 1 : 0,\n    item.latencyMs,\n  ].join(\"|\")).join(\",\");\n  if (value.length > 8_192) throw new Error(\"cave_transform_trace_limit\");\n  return value;\n}\n\nfunction mergeHeaders(first: ProviderHeaders | undefined, second: ProviderHeaders): ProviderHeaders {\n  return { ...(first ?? {}), ...second };\n}","sourceCodeStart":3655,"sourceCodeEnd":3691,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/runtime.ts#L3655-L3691","documentation":"`serializeTransformTrace` throws `cave_transform_trace_limit` when the transform trace being serialized has more than 64 entries. The trace records one entry per content-transform applied during a run, and the serializer refuses to emit an unbounded audit trail, so an oversized trace is rejected instead of silently truncated.","triggerScenarios":"A run that applies more than 64 content transforms — e.g. very long runs with many tool results/history segments each triggering a compression route — followed by trace serialization.","commonSituations":"Marathon agent sessions with heavy compaction/transform activity; a route-resolver bug producing a transform per segment with no dedup; stress tests with thousands of tool results.","solutions":["Reduce transform churn: batch or dedupe transforms so one run produces at most 64 trace entries.","Catch the error where the trace is serialized and persist the trace in chunks of ≤64 entries instead of one string.","If this happens in ordinary runs, report/investigate — it usually signals a route-resolution loop, since 64 transforms is far above the one-route-per-live-zone design.","Shorten the run (more frequent compaction checkpoints, smaller sessions) so fewer transforms accumulate."],"exampleFix":"// before\nconst text = serializeTransformTrace(trace); // throws when trace.length > 64\n// after\nconst text = trace.length > 64\n  ? JSON.stringify(trace.slice(-64).map(t => ({ id: t.transformID, outcome: t.outcome })))\n  : serializeTransformTrace(trace);","handlingStrategy":"try-catch","validationCode":"if (trace.length > 64) console.warn(`transform trace ${trace.length} exceeds 64-entry serializer limit`);","typeGuard":"null","tryCatchPattern":"try {\n  persistTrace(serializeTransformTrace(trace));\n} catch (e) {\n  if ((e as Error).message === \"cave_transform_trace_limit\") {\n    persistTrace(JSON.stringify(trace.slice(-64)));\n  } else throw e;\n}","preventionTips":["Watch for runs that accumulate >64 transforms — usually a route-resolution loop; investigate rather than only truncating.","Persist traces incrementally per transform instead of serializing one giant trace at the end.","Cap transform churn by compacting in smaller, more frequent checkpoints."],"tags":["transform","audit-trace","size-limit"],"backgroundTag":"value-out-of-range","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"}