{"record":{"id":"d008cb036f390983","repo":"JuliusBrussee/caveman","slug":"caveman-code-no-tool-output-recorded-yet-to-prove","errorCode":null,"errorMessage":"caveman-code: no tool output recorded yet to prove recovery on","messagePattern":"caveman-code: no tool output recorded yet to prove recovery on","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/code.ts","lineNumber":957,"sourceCode":"  ];\n}\n\n// ---------------------------------------------------------------------------\n// Recovery proof\n// ---------------------------------------------------------------------------\n\nexport interface CodingRecoveryProof extends SegmentRecoveryProof {\n  segment: string;\n}\n\n/**\n * Take the largest raw tool output this session produced, push it through the\n * same engine compress/retrieve pair the plan and `cave_retrieve` use, and\n * compare bytes. This is the reversibility proof, not a savings claim.\n */\nexport async function proveRecovery(session: CodingSession): Promise<CodingRecoveryProof> {\n  const sample = session.agent.samples[0];\n  if (!sample) throw new Error(\"caveman-code: no tool output recorded yet to prove recovery on\");\n  const proof = await proveSegmentRecovery({\n    body: new TextEncoder().encode(sample.text),\n    transformID: TOOL_RESULT_TRANSFORM,\n    ...(session.options.engineBin === undefined ? {} : { engineBin: session.options.engineBin }),\n  });\n  return { ...proof, segment: sample.label };\n}\n\nexport function formatRecoveryProof(proof: CodingRecoveryProof): string {\n  if (proof.outcome === \"recovered\") {\n    return `recovery proof: ${proof.segment} round-trip OK (sha256 match ${proof.originalSHA256.slice(0, 12)})`;\n  }\n  if (proof.outcome === \"not_smaller\") {\n    return `recovery proof: ${proof.segment} not compressed — the engine kept the original bytes, nothing to recover`;\n  }\n  return `recovery proof: ${proof.segment} FAILED (sha256 mismatch) — the plan falls back to the original body`;\n}\n","sourceCodeStart":939,"sourceCodeEnd":975,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/code.ts#L939-L975","documentation":"proveRecovery demonstrates that engine compression is reversible by round-tripping the session's largest recorded tool output through compress/retrieve. If the session has not recorded any tool output samples yet, there is nothing to prove recovery on, so it throws.","triggerScenarios":"Calling proveRecovery immediately after creating a CodingSession before any tool has run; a session whose tool executions all failed to record samples; calling it on a fresh/empty session object.","commonSituations":"Writing a smoke test that checks recovery before running any tools; integrating the proof step into a pipeline that runs before the agent loop executes tool calls.","solutions":["Run at least one tool call in the session before calling proveRecovery","Check session.agent.samples.length > 0 before invoking the proof","Guard the proof step behind completion of a real agent run"],"exampleFix":"// before\nconst session = createSession(opts);\nconst proof = await proveRecovery(session);\n// after\nconst session = await runAgentTask(opts, task);\nif (session.agent.samples.length === 0) throw new Error(\"no tool output to prove\");\nconst proof = await proveRecovery(session);","handlingStrategy":"validation","validationCode":"if (!session.agent.samples.length) {\n  throw new Error(\"proveRecovery requires at least one recorded tool output; run a tool first\");\n}","typeGuard":"const hasSamples = (s: CodingSession): boolean => s.agent.samples.length > 0;","tryCatchPattern":"try {\n  const proof = await proveRecovery(session);\n} catch (err) {\n  if ((err as Error).message.includes(\"no tool output recorded yet\")) {\n    console.warn(\"Skipping recovery proof: session has no tool output\");\n  } else throw err;\n}","preventionTips":["Only call proveRecovery after a completed agent run that executed tools","Gate the proof step on session.agent.samples.length > 0","In tests, run a trivial tool-producing task before asserting on recovery proofs"],"tags":["state","session","precondition"],"backgroundTag":"empty-result-set","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"}