JuliusBrussee/caveman · error
engine_changed_bytes_without_recovery
engine_changed_bytes_without_recovery
Error message
engine_changed_bytes_without_recovery
What it means
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.
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.
Example fix
// before (engine stdout)
summary text only, no recovery_handle in report
// after (engine must emit)
{ "recovery_handle": "rcv-123", "tokens_before": 5000, "tokens_after": 800 } Defensive patterns
Strategy: try-catch
Validate before calling
const report = JSON.parse(engineReportJson);
const bytesChanged = !bytesEqual(result.stdout, input);
if (bytesChanged && !(typeof report.recovery_handle === "string" && report.recovery_handle.length > 0)) {
throw new Error("engine will violate contract: changed bytes without recovery_handle");
} Type guard
function hasRecoveryHandle(report: unknown): report is { recovery_handle: string } {
return typeof report === "object" && report !== null &&
typeof (report as any).recovery_handle === "string" && (report as any).recovery_handle.length > 0;
} Try / catch
try {
const proof = await runEngineTransform(input, engineBin);
} catch (err) {
if (err instanceof Error && err.message === "engine_changed_bytes_without_recovery") {
// treat as engine failure: fall back to the unmodified input or a different engine version
} else throw err;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- cave_recovery_handle_out_of_scope
- caveman-cloud MCP changed during interrupted setup…
- caveman-cloud MCP changed during interrupted removal…
- MCP config or ownership journal changed during interrupted…
- MCP transaction failed and safe recovery was blocked: …
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/3529ae550e75178c.
Report an issue: GitHub.
Appendix: source
Thrown at packages/agent/src/runtime.ts:2777
async function engineCompress(
input: Uint8Array,
engineBin: string | undefined,
contentType = "text",
signal?: AbortSignal,
): Promise<{ output: Uint8Array; handle?: string; tokensBefore?: number; tokensAfter?: number }> {
const result = await runEngine(engineBin, ["compress", "--type", contentType], input, signal);
const lastLine = result.stderr.trim().split("\n").pop() ?? "{}";
const report = JSON.parse(lastLine) as {
recovery_handle?: unknown;
tokens_before?: unknown;
tokens_after?: unknown;
};
const handle = typeof report.recovery_handle === "string" && report.recovery_handle.length > 0
? report.recovery_handle
: undefined;
if (!handle && !bytesEqual(result.stdout, input)) {
throw new Error("engine_changed_bytes_without_recovery");
}
const tokensBefore = validEngineTokenCount(report.tokens_before);
const tokensAfter = validEngineTokenCount(report.tokens_after);
return {
output: result.stdout,
...(handle === undefined ? {} : { handle }),
...(tokensBefore === undefined ? {} : { tokensBefore }),
...(tokensAfter === undefined ? {} : { tokensAfter }),
};
}
function engineContentType(transformID: string): string {
const match = /^caveman\.engine\.([a-z0-9-]+)\.v1$/.exec(transformID);
if (!match) throw new Error(`cave_unknown_transform:${transformID}`);
return match[1]!;
}
View on GitHub (pinned to 3ee70a1026)