JuliusBrussee/caveman · error · Error

pending transaction has unsafe permissions; refusing…

Error message

pending ${label} transaction has unsafe permissions; refusing recovery

What it means

Pending transaction journals must be private: on POSIX systems the file mode is checked and any group/other permission bits (mode & 0o077 != 0) cause recovery to refuse, because the journal embeds config contents and could leak data. Windows is exempt from this check.

Solutions

  1. chmod 600 <journal-file> to strip group/other permission bits and re-run recovery
  2. Set a restrictive umask (umask 077) before running the CLI so new journals are created private
  3. Check parent directory permissions if the tool keeps recreating files with wide modes

Example fix

// before
ls -l pending.json  # -rw-r--r-- (644)
// after
chmod 600 pending.json  # -rw------- (600)
Defensive patterns

Strategy: validation

Validate before calling

import { statSync } from 'fs';
function journalPermissionsSafe(path: string): boolean {
  if (process.platform === 'win32') return true;
  return (statSync(path).mode & 0o077) === 0;
}
// fix proactively: chmod 600 path

Type guard

function hasSafeJournalMode(path: string): boolean {
  try { return process.platform === 'win32' || (statSync(path).mode & 0o077) === 0; }
  catch { return false; }
}

Try / catch

try {
  recoverPendingTransaction(label, path);
} catch (e) {
  if (e instanceof Error && e.message.includes('unsafe permissions')) {
    chmodSync(path, 0o600);
    return recoverPendingTransaction(label, path); // retry once
  }
  throw e;
}

Prevention

When it happens

Trigger: The journal file was created or chmod'ed with group/other read/write bits set (e.g. mode 644 or 664 instead of 600), typically by a tool using a non-restrictive umask or a manual chmod.

Common situations: Copying the journal from another machine or archive that carried wider permissions; running with a permissive umask (e.g. umask 000) that affected file creation; a shared workspace resetting permissions.

Understand the failure class

Background: "You do not have permission" / 403 Forbidden errors: authenticated but not allowed — causes and fixes across open-source libraries — this error's family across 31 libraries.

Related errors


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

Appendix: source

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

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)
    || (journalAgent !== "kilo" && journalAgent !== "qwen")
    || typeof journalServer !== "string"
    || !mcpServerToolName(journalServer)
    || (expected.agent !== undefined && journalAgent !== expected.agent)
    || (expected.serverName !== undefined && journalServer !== expected.serverName)
    || (value.action !== "install" && value.action !== "uninstall")

View on GitHub (pinned to 3ee70a1026)