JuliusBrussee/caveman · error

cave_transform_trace_limit

cave_transform_trace_limit

Error message

cave_transform_trace_limit

What it means

`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.

Solutions

  1. Reduce transform churn: batch or dedupe transforms so one run produces at most 64 trace entries.
  2. Catch the error where the trace is serialized and persist the trace in chunks of ≤64 entries instead of one string.
  3. 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.
  4. Shorten the run (more frequent compaction checkpoints, smaller sessions) so fewer transforms accumulate.

Example fix

// before
const text = serializeTransformTrace(trace); // throws when trace.length > 64
// after
const text = trace.length > 64
  ? JSON.stringify(trace.slice(-64).map(t => ({ id: t.transformID, outcome: t.outcome })))
  : serializeTransformTrace(trace);
Defensive patterns

Strategy: try-catch

Validate before calling

if (trace.length > 64) console.warn(`transform trace ${trace.length} exceeds 64-entry serializer limit`);

Type guard

null

Try / catch

try {
  persistTrace(serializeTransformTrace(trace));
} catch (e) {
  if ((e as Error).message === "cave_transform_trace_limit") {
    persistTrace(JSON.stringify(trace.slice(-64)));
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

Thrown at packages/agent/src/runtime.ts:3673

  return value !== null && typeof value === "object" && !Array.isArray(value);
}

function volatileStablePrefix(instructions: string, tools: readonly ToolDefinition[]): boolean {
  const value = `${instructions}\n${stableStringify(tools.map((item) => ({
    name: item.name,
    description: item.description,
    input: item.input,
  })))}`;
  return [
    /\b20[0-9]{2}-[01][0-9]-[0-3][0-9][T ][0-2][0-9]:[0-5][0-9]/,
    /\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,
    /["'](?:run|request|build|trace|span)[_-]?id["']\s*:/i,
    /["']nonce["']\s*:/i,
  ].some((pattern) => pattern.test(value));
}

function serializeTransformTrace(trace: readonly TransformTrace[]): string {
  if (trace.length > 64) throw new Error("cave_transform_trace_limit");
  const value = trace.map((item) => [
    item.transformID,
    item.segmentKind,
    item.safetyClass,
    item.outcome,
    item.beforeTokens,
    item.afterTokens,
    item.recoveryKind,
    item.recoveryUsed ? 1 : 0,
    item.latencyMs,
  ].join("|")).join(",");
  if (value.length > 8_192) throw new Error("cave_transform_trace_limit");
  return value;
}

function mergeHeaders(first: ProviderHeaders | undefined, second: ProviderHeaders): ProviderHeaders {
  return { ...(first ?? {}), ...second };
}

View on GitHub (pinned to 3ee70a1026)