{"record":{"id":"8cc873b7244bf066","repo":"JuliusBrussee/caveman","slug":"cave-tool-result-requires-recovery","errorCode":"cave_tool_result_requires_recovery","errorMessage":"cave_tool_result_requires_recovery","messagePattern":"cave_tool_result_requires_recovery","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/runtime.ts","lineNumber":3772,"sourceCode":"        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\");\n      }\n      const recovered = await engineRetrieve(transformed.handle, undefined, engineBin);\n      if (!bytesEqual(recovered, raw)) throw new Error(\"cave_tool_result_recovery_mismatch\");\n      recoveryHandles.add(transformed.handle);\n      const compressed = new TextDecoder().decode(transformed.output);\n      return {\n        content: [{\n          type: \"text\",\n          text: [\n            compressed,\n            `<<cave_retrieve:${transformed.handle}>>`,\n            definition.result === \"page\"\n              ? \"Use cave_retrieve with a narrow query to page relevant detail.\"\n              : \"Use cave_retrieve for omitted detail.\",\n          ].join(\"\\n\"),\n        }],\n        details: {\n          effect: definition.effect,","sourceCodeStart":3754,"sourceCodeEnd":3790,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/runtime.ts#L3754-L3790","documentation":"For paged/offloaded tool results the runtime compresses the payload via the engine and requires a recovery handle plus a live recoveryHandles registry to allow later retrieval. If compression produced no handle or the recovery registry was not provided to the invocation, it throws this error instead of losing data.","triggerScenarios":"A tool result goes through the engineCompress path (definition.result \"page\"/offload) but either engineCompress returned no handle or recoveryHandles is undefined at runtime.ts:3772.","commonSituations":"Running the runtime without the recovery/engine backend configured (missing engine binary or recovery session not initialized); a engine version returning an empty handle; calling the tool pipeline outside the normal invocation bootstrap.","solutions":["Ensure the engine binary (engineBin) is configured and the recovery session is initialized before the invocation.","Verify the runtime is created through the normal entry point that supplies recoveryHandles, not a partially constructed state.","Check the engine output — if it omits a handle, upgrade/fix the engine installation.","Fall back to inline results for that tool if offload infrastructure is unavailable."],"exampleFix":"// before\nconst agent = createRuntime({ /* no engine configured */ });\n// after\nconst agent = createRuntime({ engineBin: \"/usr/local/bin/cave-engine\", recovery: { enabled: true } });","handlingStrategy":"validation","validationCode":"if (!engineBin) throw new Error('engine binary must be configured for paged tool results');\nif (!recovery || !recovery.enabled) throw new Error('recovery session must be enabled before invoking offloading tools');","typeGuard":"function recoveryReady(cfg: { engineBin?: string; recovery?: { enabled?: boolean } }): cfg is { engineBin: string; recovery: { enabled: true } } {\n  return typeof cfg.engineBin === 'string' && cfg.engineBin.length > 0 && cfg.recovery?.enabled === true;\n}","tryCatchPattern":"try {\n  return await runWithOffload(args);\n} catch (e) {\n  if (e?.message === 'cave_tool_result_requires_recovery') {\n    return await runInlineFallback(args);\n  }\n  throw e;\n}","preventionTips":["Always initialize the engine/recovery backend before invocations that offload results.","Smoke-test engineCompress/engineRetrieve round trips at startup.","Construct the runtime only through the standard bootstrap that wires recoveryHandles."],"tags":["recovery","tool-results","misconfiguration"],"backgroundTag":"missing-dependency","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"}