JuliusBrussee/caveman · error · Error

cannot read pending transaction

Error message

cannot read pending ${label} transaction: ${(error as Error).message}

What it means

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.

Solutions

  1. Fix filesystem permissions on the journal file so the current user can read it (chmod 600)
  2. Inspect the journal file; if it is truncated or corrupt and no transaction is in flight, remove it so recovery treats it as absent
  3. Re-run the original MCP command to rewrite a clean journal
  4. Check the underlying OS error appended to the message for the real cause (EACCES, EISDIR, etc.)

Example fix

// before: journal truncated mid-write, JSON.parse throws
// after: remove the corrupt journal and retry
rm ~/.local/share/kilo/pending-transaction.json
<re-run the mcp install/update command>
Defensive patterns

Strategy: try-catch

Validate before calling

import { accessSync, constants } from 'fs';
function journalReadable(path: string): boolean {
  try { accessSync(path, constants.R_OK); return true; } catch { return false; }
}

Type guard

function isJournalReadError(e: unknown): e is Error {
  return e instanceof Error && e.message.startsWith('cannot read pending');
}

Try / catch

try {
  recoverPendingTransaction(label, path);
} catch (e) {
  if (isJournalReadError(e)) {
    // inspect cause; if corrupt and no txn in flight, unlink journal and retry
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/374e9daac13d63c3. Report an issue: GitHub.

Appendix: source

Thrown at packages/cli/src/index.ts:12730

};

function ownedMcpPendingLabel(agent?: string, serverName?: string): string {
  return agent && serverName ? `${agent} ${serverName} MCP` : "owned MCP";
}

function readOwnedMcpPendingJournalAt(
  path: string,
  expected: { agent?: "kilo" | "qwen"; serverName?: string; configPath?: string; locatorPath?: string } = {},
): ReadOwnedMcpPendingJournal | null {
  const label = ownedMcpPendingLabel(expected.agent, expected.serverName);
  let bytes: Buffer;
  let value: Record<string, unknown>;
  try {
    bytes = readFileSync(path);
    value = JSON.parse(bytes.toString("utf8")) as Record<string, unknown>;
  } catch (error) {
    if ((error as NodeJS.ErrnoException).code === "ENOENT") return null;
    throw new Error(`cannot read pending ${label} transaction: ${(error as Error).message}`);
  }
  if (!value || typeof value !== "object" || Array.isArray(value)) {
    throw new Error(`pending ${label} transaction is malformed; refusing recovery`);
  }
  if (process.platform !== "win32" && (statSync(path).mode & 0o077) !== 0) {
    throw new Error(`pending ${label} transaction has unsafe permissions; refusing recovery`);
  }
  const keys = [
    "action", "agent", "config_after_sha256", "config_before_base64", "config_before_mode", "config_path",
    "config_before_sha256", "marker_after_base64", "marker_after_sha256", "marker_before_base64", "marker_before_mode",
    "marker_before_sha256", "marker_path", "schema_version", "server_name", "transaction_id",
  ].sort();
  const journalAgent = value.agent;
  const journalServer = value.server_name;
  if (Object.keys(value).sort().join("\0") !== keys.join("\0")
    || value.schema_version !== 1
    || typeof value.transaction_id !== "string"
    || !/^[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)

View on GitHub (pinned to 3ee70a1026)