JuliusBrussee/caveman · error · Error

cannot persist MCP ownership journal at

Error message

cannot persist ${agentId} ${serverName} MCP ownership journal at ${path}: ${(error as Error).message}

What it means

Persisting the MCP ownership journal uses a hardened write routine: it probes the parent directory with chmod/0o700, performs a durable atomic write of a probe file, unlinks it, and fsyncs the parent directory. If any step fails, the probe is cleaned up and this wrapped error is thrown, embedding the agent id, server name, target path, and the underlying error message.

Solutions

  1. Read the embedded underlying message and fix that cause first (permissions, disk space, mount state)
  2. Fix ownership of the parent directory: `sudo chown -R $(whoami) <dir>` and `chmod 700 <dir>`
  3. If the path is on a network/read-only mount, relocate your home/config to a local writable filesystem
  4. Avoid running installs with sudo, which leaves root-owned dirs that later fail

Example fix

# before
$ ls -ld ~/.config/opencode
drwx------ root root
# after
$ sudo chown $(whoami) ~/.config/opencode && chmod 700 ~/.config/opencode
Defensive patterns

Strategy: try-catch

Validate before calling

import { accessSync, constants, statSync } from "node:fs";
const dir = dirname(path);
accessSync(dir, constants.W_OK);
if (statSync(dir).uid !== process.getuid?.()) throw new Error(`${dir} not owned by current user`);

Try / catch

try {
  persistOwnershipJournal(agentId, serverName, path);
} catch (e) {
  const msg = (e as Error).message;
  if (msg.startsWith("cannot persist")) {
    const cause = msg.split(": ").slice(1).join(": ");
    console.error(`journal write failed: ${cause} — check ownership, disk space, mount`);
  } else throw e;
}

Prevention

When it happens

Trigger: Calling the ownership journal persistence where the parent directory cannot be chmod'd (owned by root/another user), the filesystem does not support the atomic write or fsync (some network mounts, read-only fs), or disk is full.

Common situations: ~/.config or agent config dir owned by root after a sudo-run install; read-only or noexec-mounted home on NFS/SMB; disk quota exceeded; SELinux/AppArmor blocking writes to the marker directory.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


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

Appendix: source

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

  return canonicalMcpConfigPath(path);
}

// A native MCP registration and its Caveman ownership journal form one logical
// write. Prove the journal directory is writable before touching agent config;
// otherwise Kilo/Qwen would refuse both a later upgrade and removal because the
// surviving registration has no trustworthy owner.
function preflightMcpServerMarker(agentId: string, serverName: string): void {
  const path = mcpServerMarkerPath(agentId, serverName);
  const probe = join(dirname(path), `.${basename(path)}.preflight-${process.pid}-${randomUUID()}`);
  try {
    mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
    chmodSync(dirname(path), 0o700);
    durableAtomicWriteFile(probe, Buffer.alloc(0));
    unlinkSync(probe);
    fsyncParentDirectory(probe);
  } catch (error) {
    try { unlinkSync(probe); } catch { /* no probe survived */ }
    throw new Error(`cannot persist ${agentId} ${serverName} MCP ownership journal at ${path}: ${(error as Error).message}`);
  }
}
function mcpMarkerPath(agentId: string): string {
  return mcpServerMarkerPath(agentId, "caveman");
}
function mcpServerInstalled(agentId: string, serverName: string): boolean {
  try {
    return statSync(mcpServerMarkerPath(agentId, serverName)).isFile();
  } catch {
    return false;
  }
}
function mcpInstalled(agentId: string, agentArgs: string[] = []): boolean {
  if (agentId === "kilo" || agentId === "qwen") return ownedMcpRegistration(agentId, agentArgs) !== null;
  return mcpServerInstalled(agentId, "caveman");
}

// configFileOverlayHasMcp asks whether the PROFILE would inject this MCP server

View on GitHub (pinned to 3ee70a1026)