{"record":{"id":"374e9daac13d63c3","repo":"JuliusBrussee/caveman","slug":"cannot-read-pending-label-transaction-error","errorCode":null,"errorMessage":"cannot read pending ${label} transaction: ${(error as Error).message}","messagePattern":"cannot read pending (.+?) transaction: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":12730,"sourceCode":"};\n\nfunction ownedMcpPendingLabel(agent?: string, serverName?: string): string {\n  return agent && serverName ? `${agent} ${serverName} MCP` : \"owned MCP\";\n}\n\nfunction readOwnedMcpPendingJournalAt(\n  path: string,\n  expected: { agent?: \"kilo\" | \"qwen\"; serverName?: string; configPath?: string; locatorPath?: string } = {},\n): ReadOwnedMcpPendingJournal | null {\n  const label = ownedMcpPendingLabel(expected.agent, expected.serverName);\n  let bytes: Buffer;\n  let value: Record<string, unknown>;\n  try {\n    bytes = readFileSync(path);\n    value = JSON.parse(bytes.toString(\"utf8\")) as Record<string, unknown>;\n  } catch (error) {\n    if ((error as NodeJS.ErrnoException).code === \"ENOENT\") return null;\n    throw new Error(`cannot read pending ${label} transaction: ${(error as Error).message}`);\n  }\n  if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n    throw new Error(`pending ${label} transaction is malformed; refusing recovery`);\n  }\n  if (process.platform !== \"win32\" && (statSync(path).mode & 0o077) !== 0) {\n    throw new Error(`pending ${label} transaction has unsafe permissions; refusing recovery`);\n  }\n  const keys = [\n    \"action\", \"agent\", \"config_after_sha256\", \"config_before_base64\", \"config_before_mode\", \"config_path\",\n    \"config_before_sha256\", \"marker_after_base64\", \"marker_after_sha256\", \"marker_before_base64\", \"marker_before_mode\",\n    \"marker_before_sha256\", \"marker_path\", \"schema_version\", \"server_name\", \"transaction_id\",\n  ].sort();\n  const journalAgent = value.agent;\n  const journalServer = value.server_name;\n  if (Object.keys(value).sort().join(\"\\0\") !== keys.join(\"\\0\")\n    || value.schema_version !== 1\n    || typeof value.transaction_id !== \"string\"\n    || !/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(value.transaction_id)","sourceCodeStart":12712,"sourceCodeEnd":12748,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L12712-L12748","documentation":"When recovering a pending MCP transaction, the CLI reads and JSON-parses the journal file. Any read or parse failure other than ENOENT (file absent means no pending transaction) is wrapped in this error so the caller knows recovery could not even inspect the journal.","triggerScenarios":"Journal file exists but is unreadable (permission denied), is not valid JSON (truncated write, binary content), or the path is a directory. Any non-ENOENT errno or JSON.parse SyntaxError triggers this.","commonSituations":"A crash mid-write left a truncated/invalid journal; permissions changed after another user created the file; the journal path was replaced by a directory or symlink target.","solutions":["Fix filesystem permissions on the journal file so the current user can read it (chmod 600)","Inspect the journal file; if it is truncated or corrupt and no transaction is in flight, remove it so recovery treats it as absent","Re-run the original MCP command to rewrite a clean journal","Check the underlying OS error appended to the message for the real cause (EACCES, EISDIR, etc.)"],"exampleFix":"// before: journal truncated mid-write, JSON.parse throws\n// after: remove the corrupt journal and retry\nrm ~/.local/share/kilo/pending-transaction.json\n<re-run the mcp install/update command>","handlingStrategy":"try-catch","validationCode":"import { accessSync, constants } from 'fs';\nfunction journalReadable(path: string): boolean {\n  try { accessSync(path, constants.R_OK); return true; } catch { return false; }\n}","typeGuard":"function isJournalReadError(e: unknown): e is Error {\n  return e instanceof Error && e.message.startsWith('cannot read pending');\n}","tryCatchPattern":"try {\n  recoverPendingTransaction(label, path);\n} catch (e) {\n  if (isJournalReadError(e)) {\n    // inspect cause; if corrupt and no txn in flight, unlink journal and retry\n  } else throw e;\n}","preventionTips":["Let the CLI create journals; avoid third-party processes touching the journal path","Keep journal files owned by the running user with mode 600","Back up before manually editing journals; never truncate writes","Check disk health — ENOSPC or crashes mid-write commonly corrupt journals"],"tags":["journal","file-read","json-parse","mcp"],"backgroundTag":"file-read-failed","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"}