{"record":{"id":"fb1349fd8a03d087","repo":"JuliusBrussee/caveman","slug":"cave-tool-result-inline-limit","errorCode":"cave_tool_result_inline_limit","errorMessage":"cave_tool_result_inline_limit","messagePattern":"cave_tool_result_inline_limit","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/runtime.ts","lineNumber":3754,"sourceCode":"        ? await sandboxExecute(params, combined)\n        : await raceToolTimeout(\n          Promise.resolve(definition.execute(params, combined)),\n          definition.timeoutMs,\n        );\n      const text = typeof value === \"string\" ? value : JSON.stringify(value);\n      const raw = new TextEncoder().encode(text ?? \"null\");\n      const maxInlineBytes = definition.artifact === undefined\n        ? 32_768\n        : definition.artifact.maxInlineTokens * 4;\n      if (deferLockedToolResult) {\n        if (raw.byteLength > 16 * 1024 * 1024) throw new Error(\"cave_tool_result_limit\");\n        return {\n          content: [{ type: \"text\", text: text ?? \"null\" }],\n          details: { effect: definition.effect, resultPolicy: definition.result, lockedRoutePending: true },\n        };\n      }\n      if (definition.result === \"inline\") {\n        if (raw.byteLength > maxInlineBytes) throw new Error(\"cave_tool_result_inline_limit\");\n        return {\n          content: [{ type: \"text\", text: text ?? \"null\" }],\n          details: { effect: definition.effect, resultPolicy: definition.result },\n        };\n      }\n      const mustOffload = definition.result === \"page\" ||\n        definition.result === \"compress\" ||\n        definition.result === \"exact_ccr\" ||\n        raw.byteLength > maxInlineBytes;\n      if (!mustOffload) {\n        return {\n          content: [{ type: \"text\", text: text ?? \"null\" }],\n          details: { effect: definition.effect, resultPolicy: definition.result },\n        };\n      }\n      const transformed = await engineCompress(raw, engineBin);\n      if (!transformed.handle || !recoveryHandles) {\n        throw new Error(\"cave_tool_result_requires_recovery\");","sourceCodeStart":3736,"sourceCodeEnd":3772,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/runtime.ts#L3736-L3772","documentation":"When a tool definition declares result policy \"inline\", the serialized result must fit within maxInlineBytes — either 32,768 bytes by default or artifact.maxInlineTokens*4 when an artifact is configured. Exceeding it throws this error rather than silently truncating or offloading.","triggerScenarios":"A tool with definition.result === \"inline\" returns content whose encoded byteLength exceeds maxInlineBytes (32,768 default) at runtime.ts:3754.","commonSituations":"Registering a tool as inline but letting it return large outputs (long logs, big JSON); misconfigured maxInlineTokens on the artifact; version changes where outputs grew past the threshold.","solutions":["Change the tool definition's result policy from \"inline\" to \"page\" so large results are offloaded automatically.","Increase artifact.maxInlineTokens in the tool's artifact config if large outputs are expected.","Truncate/summarize the tool output before returning.","Move the bulk payload to an artifact and return a reference."],"exampleFix":"// before\n{ name: \"dumpLogs\", result: \"inline\" }\n// after\n{ name: \"dumpLogs\", result: \"page\", artifact: { maxInlineTokens: 8192 } }","handlingStrategy":"validation","validationCode":"const maxInlineBytes = definition.artifact ? definition.artifact.maxInlineTokens * 4 : 32768;\nif (new TextEncoder().encode(text).byteLength > maxInlineBytes) {\n  text = summarizeOrOffload(text);\n}","typeGuard":"function fitsInline(text: string, maxInlineBytes: number): boolean {\n  return new TextEncoder().encode(text).byteLength <= maxInlineBytes;\n}","tryCatchPattern":"try {\n  return await callTool(args);\n} catch (e) {\n  if (e?.message === 'cave_tool_result_inline_limit') {\n    return await callToolWithPaging(args);\n  }\n  throw e;\n}","preventionTips":["Declare result policy \"page\" for tools that can return big outputs.","Set artifact.maxInlineTokens to a realistic ceiling for the tool's normal output.","Keep the default 32 KiB inline budget in mind when designing tool outputs."],"tags":["limit-exceeded","tool-results","inline-result"],"backgroundTag":"payload-too-large","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"}