JuliusBrussee/caveman · error
cave_tool_result_limit
cave_tool_result_limit
Error message
cave_tool_result_limit
What it means
In deferred/locked-route mode a tool result may be kept inline only if its UTF-8 encoding is at most 16 MiB; larger payloads throw this error instead of being silently passed. The library enforces an absolute ceiling on tool result bytes even in the deferred path where normal inline/artifact limits do not apply.
Solutions
- Make the tool return a handle/path/reference instead of embedding the full payload in the result text.
- Truncate or paginate the tool's output before returning it.
- Configure the tool definition with an artifact (maxInlineTokens) so large results go through the offload path rather than the deferred inline path.
- If 16 MiB is genuinely needed, compress the payload before returning.
Example fix
// before
return { text: giantLogContents };
// after
return { text: `log archived at ${writeArtifact(giantLogContents)} (${giantLogContents.length} bytes)` }; Defensive patterns
Strategy: validation
Validate before calling
const bytes = new TextEncoder().encode(JSON.stringify(result)).byteLength;
if (bytes > 16 * 1024 * 1024) {
result = `payload too large (${bytes} bytes); see artifact at ${offload(result)}`;
} Type guard
function fitsDeferredLimit(value: unknown): boolean {
const text = typeof value === 'string' ? value : JSON.stringify(value);
return new TextEncoder().encode(text ?? 'null').byteLength <= 16 * 1024 * 1024;
} Prevention
- Never return raw file dumps or DB dumps from tools; return references.
- Truncate or summarize large outputs inside the tool itself.
- Prefer the artifact/offload path for anything likely to exceed a few MB.
When it happens
Trigger: A tool marked with lockedRoutePending/deferred results returns a string or JSON-serializable value whose TextEncoder byte length exceeds 16*1024*1024 at runtime.ts:3747.
Common situations: A tool dumps a huge file, log archive, or database dump as its result while the definition routes through the deferred lock path; accidental serialization of binary blobs into the result text.
Understand the failure class
Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.
Related errors
- cave_tool_result_inline_limit
- cave_input_too_large
- cave_memory_too_large
- cave_subagent_invocation_limit
- cave_tool_result_requires_recovery
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/60d550718da825ad.
Report an issue: GitHub.
Appendix: source
Thrown at packages/agent/src/runtime.ts:3747
// The worker path is bounded by killing its process; the IN-PROCESS
// (host/fixture) path is a closure this process cannot preempt, so a
// closure that ignores `combined` would hang the run forever. Race it
// against a hard deadline so the run stops waiting at timeoutMs with
// cave_tool_timeout (the closure keeps running in the background — JS
// cannot preempt it — but it no longer blocks the run).
const value = sandboxExecute
? await sandboxExecute(params, combined)
: await raceToolTimeout(
Promise.resolve(definition.execute(params, combined)),
definition.timeoutMs,
);
const text = typeof value === "string" ? value : JSON.stringify(value);
const raw = new TextEncoder().encode(text ?? "null");
const maxInlineBytes = definition.artifact === undefined
? 32_768
: definition.artifact.maxInlineTokens * 4;
if (deferLockedToolResult) {
if (raw.byteLength > 16 * 1024 * 1024) throw new Error("cave_tool_result_limit");
return {
content: [{ type: "text", text: text ?? "null" }],
details: { effect: definition.effect, resultPolicy: definition.result, lockedRoutePending: true },
};
}
if (definition.result === "inline") {
if (raw.byteLength > maxInlineBytes) throw new Error("cave_tool_result_inline_limit");
return {
content: [{ type: "text", text: text ?? "null" }],
details: { effect: definition.effect, resultPolicy: definition.result },
};
}
const mustOffload = definition.result === "page" ||
definition.result === "compress" ||
definition.result === "exact_ccr" ||
raw.byteLength > maxInlineBytes;
if (!mustOffload) {
return {View on GitHub (pinned to 3ee70a1026)