{"record":{"id":"c1ed88c563807d45","repo":"JuliusBrussee/caveman","slug":"pending-label-transaction-is-malformed-erro","errorCode":null,"errorMessage":"pending ${label} transaction is malformed: ${(error as Error).message}","messagePattern":"pending (.+?) transaction is malformed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":12422,"sourceCode":"      || optionalBytesHash(markerAfter) !== value.marker_after_sha256\n      || (markerBefore !== null && !validMcpMarkerBytes(markerBefore, journalAgent, journalServer))\n      || (markerAfter !== null && !validMcpMarkerBytes(markerAfter, journalAgent, journalServer))\n      || (markerBefore !== null && parseMcpServerMarkerBytes(journalAgent, journalServer, markerBefore)?.config_path !== undefined\n        && parseMcpServerMarkerBytes(journalAgent, journalServer, markerBefore)?.config_path !== value.config_path)\n      || (markerAfter !== null && parseMcpServerMarkerBytes(journalAgent, journalServer, markerAfter)?.config_path !== value.config_path)\n      || (value.action === \"install\") !== (markerAfter !== null)) {\n      throw new Error(\"journal bytes do not match declared transaction state\");\n    }\n    return {\n      journal: value as OwnedMcpPendingJournal,\n      configBefore,\n      markerBefore,\n      markerAfter,\n      path,\n      bytes,\n    };\n  } catch (error) {\n    throw new Error(`pending ${label} transaction is malformed: ${(error as Error).message}`);\n  }\n}\n\nfunction readOwnedMcpPendingLocator(agent: \"kilo\" | \"qwen\", serverName: string): ReadOwnedMcpPendingJournal | null {\n  const path = canonicalMcpConfigPath(mcpPendingJournalPath(agent, serverName));\n  return readOwnedMcpPendingJournalAt(path, { agent, serverName, locatorPath: path });\n}\n\nfunction readOwnedMcpConfigPending(configPath: string): ReadOwnedMcpPendingJournal | null {\n  const canonicalPath = canonicalMcpConfigPath(configPath);\n  return readOwnedMcpPendingJournalAt(mcpConfigPendingJournalPath(canonicalPath), { configPath: canonicalPath });\n}\n\ntype OwnedMcpRecovery = \"none\" | \"discarded\" | \"finalized\" | \"rolled-back\";\n\nfunction recoverOwnedMcpTransaction(pending: ReadOwnedMcpPendingJournal | null): OwnedMcpRecovery {\n  if (!pending) return \"none\";\n  const { journal, configBefore, markerBefore } = pending;","sourceCodeStart":12404,"sourceCodeEnd":12440,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/5184b3d11ac6a1acb7d44b9bfaa31698157cff97/packages/cli/src/index.ts#L12404-L12440","documentation":"A wrapper thrown around any error raised inside the journal validation/decoding try-block (including errors 21, 22, 24, 26, 27 from decodePendingBytes and cross-field checks). It prefixes the original message with 'pending <label> transaction is malformed:' so callers know the pending journal for that transaction label is unusable and recovery was refused.","triggerScenarios":"Any of: non-string base64 field, non-canonical base64, non-object JSON, bad schema_version/action/mode/hash fields, or bytes-vs-state mismatch, surfaced while reading the pending journal for an MCP install/uninstall recovery.","commonSituations":"Same as the inner errors — corrupted or hand-edited journals, version-skewed writers, wrong server/agent pairing — seen through this outer wrapper in logs.","solutions":["Read the inner message after 'is malformed:' to identify the exact validation failure.","Fix the specific field or condition named by the inner message (see the underlying errors).","Delete the malformed .pending journals and re-run the MCP server transaction to regenerate valid ones.","If recurring, ensure only one CLI version writes journals and avoid manual edits or third-party rewrites."],"exampleFix":"// before (diagnosing blindly)\nkilo mcp recover\n// after\nnode -e 'const j=JSON.parse(require(\"fs\").readFileSync(\"x.pending\")); console.log(j)'  # inspect, fix inner cause, then recover","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { recoverPending(); } catch (e) {\n  const m = /is malformed: (.+)$/.exec(e.message);\n  if (m) { console.error('Inner cause:', m[1]); /* address inner cause or recreate journal */ }\n}","preventionTips":["Parse the inner message after 'is malformed:' to target the real fix.","Treat any malformed journal as unrecoverable: recreate it via a fresh transaction.","Avoid hand edits and version-mixed writers of journal files."],"tags":["journal-recovery","wrapper-error","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"5184b3d11ac6a1acb7d44b9bfaa31698157cff97","analyzedAt":"2026-09-06T12:00:26.372Z","contentChangedAt":"2026-09-06T12:00:26.372Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}