JuliusBrussee/caveman · error · Error

is a symlink; refusing transactional ownership mutation

Error message

${path} is a symlink; refusing transactional ownership mutation

What it means

Before mutating MCP ownership markers transactionally for the kilo/qwen agents, the CLI resolves the canonical marker path and refuses to proceed if the marker path itself is a symbolic link. Mutating through a symlink could write outside the intended location, so it is treated as a safety violation. ENOENT (marker not yet created) is tolerated.

Solutions

  1. Remove the symlink at the reported path and replace it with a real file (copy the target's content, then `unlink` the link and write the file)
  2. Exclude the CLI's marker paths from your dotfile symlink management so they are real files
  3. Re-run the install/uninstall command after the path is a regular file

Example fix

# before
$ ls -l ~/.kilo/markers/caveman
caveman -> /mnt/backup/caveman-marker
# after
$ cp --remove-destination "$(readlink ~/.kilo/markers/caveman)" ~/.kilo/markers/caveman
Defensive patterns

Strategy: validation

Validate before calling

import { lstatSync } from "node:fs";
const marker = mcpServerMarkerPath(agent, serverName);
try { if (lstatSync(marker).isSymbolicLink()) throw new Error("marker is a symlink; fix before transaction"); } catch (e) { if ((e as any).code !== "ENOENT") throw e; }

Type guard

function isRegularFile(p: string): boolean {
  try { return lstatSync(p).isFile(); } catch { return false; }
}

Try / catch

try {
  await runOwnershipTransaction(agent, serverName);
} catch (e) {
  if ((e as Error).message.includes("is a symlink")) {
    console.error("Replace the symlinked marker with a real file, then retry.");
  } else throw e;
}

Prevention

When it happens

Trigger: Calling an ownership transaction (install/uninstall MCP ownership journal) where `lstatSync(markerPath)` reports the existing marker is a symlink — typically because a user replaced the marker file with a link, or a dotfile manager symlinked config/marker directories.

Common situations: Dotfile management (stow, chezmoi, nix home-manager) symlinking ~/.config subtrees where the CLI writes markers; restoring markers from a backup tool that converted files to links; moving a marker to another disk with a symlink.

Understand the failure class

Background: Path traversal blocked: "path escapes the workspace" and "outside site root" errors when a path will not stay inside its allowed directory — this error's family across 26 libraries.

Related errors


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

Appendix: source

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

// bare name so callers' existing missing-binary handling still triggers.
function cavemanBin(name: string, envVar: string): string {
  const explicit = process.env[envVar];
  if (explicit) return explicit;
  const onPath = which(name);
  if (onPath) return onPath;
  const local = join(cavemanHome(), "bin", binaryInstallFilename(name));
  if (isExecutable(local)) return local;
  return name;
}
function mcpServerMarkerPath(agentId: string, serverName: string): string {
  return join(cavemanHome(), "mcp", serverName === "caveman" ? `${agentId}.json` : `${agentId}.${serverName}.json`);
}

function canonicalOwnedMcpMarkerPath(agent: "kilo" | "qwen", serverName: string): string {
  const path = mcpServerMarkerPath(agent, serverName);
  try {
    if (lstatSync(path).isSymbolicLink()) {
      throw new Error(`${path} is a symlink; refusing transactional ownership mutation`);
    }
  } catch (error) {
    if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
  }
  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));

View on GitHub (pinned to 3ee70a1026)