JuliusBrussee/caveman · error

cave_tool_result_requires_recovery

cave_tool_result_requires_recovery

Error message

cave_tool_result_requires_recovery

What it means

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.

Solutions

  1. Ensure the engine binary (engineBin) is configured and the recovery session is initialized before the invocation.
  2. Verify the runtime is created through the normal entry point that supplies recoveryHandles, not a partially constructed state.
  3. Check the engine output — if it omits a handle, upgrade/fix the engine installation.
  4. Fall back to inline results for that tool if offload infrastructure is unavailable.

Example fix

// before
const agent = createRuntime({ /* no engine configured */ });
// after
const agent = createRuntime({ engineBin: "/usr/local/bin/cave-engine", recovery: { enabled: true } });
Defensive patterns

Strategy: validation

Validate before calling

if (!engineBin) throw new Error('engine binary must be configured for paged tool results');
if (!recovery || !recovery.enabled) throw new Error('recovery session must be enabled before invoking offloading tools');

Type guard

function recoveryReady(cfg: { engineBin?: string; recovery?: { enabled?: boolean } }): cfg is { engineBin: string; recovery: { enabled: true } } {
  return typeof cfg.engineBin === 'string' && cfg.engineBin.length > 0 && cfg.recovery?.enabled === true;
}

Try / catch

try {
  return await runWithOffload(args);
} catch (e) {
  if (e?.message === 'cave_tool_result_requires_recovery') {
    return await runInlineFallback(args);
  }
  throw e;
}

Prevention

When it happens

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

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

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


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

Appendix: source

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

        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 {
          content: [{ type: "text", text: text ?? "null" }],
          details: { effect: definition.effect, resultPolicy: definition.result },
        };
      }
      const transformed = await engineCompress(raw, engineBin);
      if (!transformed.handle || !recoveryHandles) {
        throw new Error("cave_tool_result_requires_recovery");
      }
      const recovered = await engineRetrieve(transformed.handle, undefined, engineBin);
      if (!bytesEqual(recovered, raw)) throw new Error("cave_tool_result_recovery_mismatch");
      recoveryHandles.add(transformed.handle);
      const compressed = new TextDecoder().decode(transformed.output);
      return {
        content: [{
          type: "text",
          text: [
            compressed,
            `<<cave_retrieve:${transformed.handle}>>`,
            definition.result === "page"
              ? "Use cave_retrieve with a narrow query to page relevant detail."
              : "Use cave_retrieve for omitted detail.",
          ].join("\n"),
        }],
        details: {
          effect: definition.effect,

View on GitHub (pinned to 3ee70a1026)