JuliusBrussee/caveman · error · Error
journal bytes do not match declared transaction state
Error message
journal bytes do not match declared transaction state
What it means
Beyond field types, the journal's declared state must be consistent with the actual byte snapshots it carries: marker bytes must parse as valid server markers for the declared agent/server, marker config_path must match the journal's config_path, and the action must agree with marker presence (install implies marker_after non-null). A mismatch means the journal bytes were tampered with or mixed from different transactions.
Solutions
- Delete the inconsistent journal and re-run the MCP install/update command to create a coherent one
- If repairing by hand, re-encode marker snapshots so they parse for the declared agent/server and match config_path, and align action with marker_after presence
- Restore a backup of the journal from before manual edits
- Verify hashes: recompute sha256 of the decoded base64 fields and ensure they equal the *_sha256 fields
Example fix
// before
{ "action": "install", "marker_after_base64": null }
// after
{ "action": "install", "marker_after_base64": "<base64 of valid marker for this agent/server>" } Defensive patterns
Strategy: validation
Validate before calling
import { createHash } from 'crypto';
function snapshotHashesMatch(j: Record<string, unknown>): boolean {
const h = (b: Buffer | null) => b === null ? null : 'sha256:' + createHash('sha256').update(b).digest('hex');
return h(j.config_before_base64 ? Buffer.from(j.config_before_base64 as string, 'base64') : null) === j.config_before_sha256;
} Type guard
function markerConsistentWithAction(j: { action: string; marker_after_base64: string | null }): boolean {
return (j.action === 'install') === (j.marker_after_base64 !== null);
} Try / catch
try {
const txn = loadPendingJournal(path);
} catch (e) {
if (e instanceof Error && e.message.includes('journal bytes do not match')) {
// journal inconsistent: delete and regenerate via the CLI
} else throw e;
} Prevention
- Edit journal fields as a set — always update snapshots together with config_path/server_name
- Recompute sha256 hashes whenever any base64 field changes
- Never merge fields across different transaction journals
- Verify action/marker_after agreement (install ⇔ marker present) after edits
When it happens
Trigger: Editing config_path or server_name in the journal without re-encoding the marker snapshots; combining fields from two different transactions; a journal where action='install' but marker_after_base64 is null (or vice versa); marker bytes that fail parseMcpServerMarkerBytes for the declared agent.
Common situations: Manual repair attempts that changed one field but not its dependent snapshots; restoring an old journal for a different server/config; interrupted multi-step edits leaving inconsistent state.
Understand the failure class
Background: Checksum mismatch errors: "checksum verification failed", "digest mismatch", "expected vs actual checksum" — what they mean and how to fix them — this error's family across 41 libraries.
Related errors
- : MCP ownership journal failed; native config may already…
- MCP transaction journal already exists; refusing overwrite
- MCP transaction journals disagree; refusing recovery
- cannot read pending transaction
- conflicting committed and pending integration journals for
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/49cdc95d184d0c36.
Report an issue: GitHub.
Appendix: source
Thrown at packages/cli/src/index.ts:12782
|| !validOptionalHash(value.config_after_sha256)
|| !validOptionalHash(value.marker_before_sha256)
|| !validOptionalHash(value.marker_after_sha256)) {
throw new Error(`pending ${label} transaction is malformed; refusing recovery`);
}
try {
const configBefore = decodePendingBytes(value.config_before_base64, "config_before_base64");
const markerBefore = decodePendingBytes(value.marker_before_base64, "marker_before_base64");
const markerAfter = decodePendingBytes(value.marker_after_base64, "marker_after_base64");
if (optionalBytesHash(configBefore) !== value.config_before_sha256
|| optionalBytesHash(markerBefore) !== value.marker_before_sha256
|| optionalBytesHash(markerAfter) !== value.marker_after_sha256
|| (markerBefore !== null && !validMcpMarkerBytes(markerBefore, journalAgent, journalServer))
|| (markerAfter !== null && !validMcpMarkerBytes(markerAfter, journalAgent, journalServer))
|| (markerBefore !== null && parseMcpServerMarkerBytes(journalAgent, journalServer, markerBefore)?.config_path !== undefined
&& parseMcpServerMarkerBytes(journalAgent, journalServer, markerBefore)?.config_path !== value.config_path)
|| (markerAfter !== null && parseMcpServerMarkerBytes(journalAgent, journalServer, markerAfter)?.config_path !== value.config_path)
|| (value.action === "install") !== (markerAfter !== null)) {
throw new Error("journal bytes do not match declared transaction state");
}
return {
journal: value as OwnedMcpPendingJournal,
configBefore,
markerBefore,
markerAfter,
path,
bytes,
};
} catch (error) {
throw new Error(`pending ${label} transaction is malformed: ${(error as Error).message}`);
}
}
function readOwnedMcpPendingLocator(agent: "kilo" | "qwen", serverName: string): ReadOwnedMcpPendingJournal | null {
const path = canonicalMcpConfigPath(mcpPendingJournalPath(agent, serverName));
return readOwnedMcpPendingJournalAt(path, { agent, serverName, locatorPath: path });
}View on GitHub (pinned to 3ee70a1026)