{"record":{"id":"3529ae550e75178c","repo":"JuliusBrussee/caveman","slug":"engine-changed-bytes-without-recovery","errorCode":"engine_changed_bytes_without_recovery","errorMessage":"engine_changed_bytes_without_recovery","messagePattern":"engine_changed_bytes_without_recovery","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/runtime.ts","lineNumber":2777,"sourceCode":"\nasync function engineCompress(\n  input: Uint8Array,\n  engineBin: string | undefined,\n  contentType = \"text\",\n  signal?: AbortSignal,\n): Promise<{ output: Uint8Array; handle?: string; tokensBefore?: number; tokensAfter?: number }> {\n  const result = await runEngine(engineBin, [\"compress\", \"--type\", contentType], input, signal);\n  const lastLine = result.stderr.trim().split(\"\\n\").pop() ?? \"{}\";\n  const report = JSON.parse(lastLine) as {\n    recovery_handle?: unknown;\n    tokens_before?: unknown;\n    tokens_after?: unknown;\n  };\n  const handle = typeof report.recovery_handle === \"string\" && report.recovery_handle.length > 0\n    ? report.recovery_handle\n    : undefined;\n  if (!handle && !bytesEqual(result.stdout, input)) {\n    throw new Error(\"engine_changed_bytes_without_recovery\");\n  }\n  const tokensBefore = validEngineTokenCount(report.tokens_before);\n  const tokensAfter = validEngineTokenCount(report.tokens_after);\n  return {\n    output: result.stdout,\n    ...(handle === undefined ? {} : { handle }),\n    ...(tokensBefore === undefined ? {} : { tokensBefore }),\n    ...(tokensAfter === undefined ? {} : { tokensAfter }),\n  };\n}\n\nfunction engineContentType(transformID: string): string {\n  const match = /^caveman\\.engine\\.([a-z0-9-]+)\\.v1$/.exec(transformID);\n  if (!match) throw new Error(`cave_unknown_transform:${transformID}`);\n  return match[1]!;\n}\n\n","sourceCodeStart":2759,"sourceCodeEnd":2795,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/runtime.ts#L2759-L2795","documentation":"Thrown when the external compaction engine returns output whose bytes differ from the input but reports no recovery_handle. The contract is: either the engine returns the input unchanged, or it must provide a recovery_handle so evicted content can be retrieved later. Any other combination is a protocol violation by the engine binary.","triggerScenarios":"Running the engine transform over a segment and the resulting stdout bytes != input bytes while report.recovery_handle is empty/missing — i.e. the engine modified or dropped content without registering a recovery artifact.","commonSituations":"A buggy or mismatched engine binary version that violates the output contract; engine crashes mid-transform emitting partial output; hand-written or third-party engine wrappers that don't emit recovery_handle.","solutions":["Check the engine binary version matches what the runtime expects and upgrade/downgrade accordingly.","Inspect engine stderr/exit status for a crashed or partial run that produced corrupt stdout.","Fix the engine wrapper so it emits a recovery_handle whenever it changes bytes.","Retry the transform; if reproducible, report the engine contract violation."],"exampleFix":"// before (engine stdout)\nsummary text only, no recovery_handle in report\n// after (engine must emit)\n{ \"recovery_handle\": \"rcv-123\", \"tokens_before\": 5000, \"tokens_after\": 800 }","handlingStrategy":"try-catch","validationCode":"const report = JSON.parse(engineReportJson);\nconst bytesChanged = !bytesEqual(result.stdout, input);\nif (bytesChanged && !(typeof report.recovery_handle === \"string\" && report.recovery_handle.length > 0)) {\n  throw new Error(\"engine will violate contract: changed bytes without recovery_handle\");\n}","typeGuard":"function hasRecoveryHandle(report: unknown): report is { recovery_handle: string } {\n  return typeof report === \"object\" && report !== null &&\n    typeof (report as any).recovery_handle === \"string\" && (report as any).recovery_handle.length > 0;\n}","tryCatchPattern":"try {\n  const proof = await runEngineTransform(input, engineBin);\n} catch (err) {\n  if (err instanceof Error && err.message === \"engine_changed_bytes_without_recovery\") {\n    // treat as engine failure: fall back to the unmodified input or a different engine version\n  } else throw err;\n}","preventionTips":["Pin and test the engine binary version against the runtime's expected contract.","Validate engine output (handle present iff bytes changed) in engine CI tests.","Capture engine stderr and exit codes to catch crashed/partial runs.","Wrap third-party engine implementations with a contract-conformance test."],"tags":["engine","protocol-violation","recovery","agent-runtime"],"backgroundTag":"unexpected-response-shape","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"}