JuliusBrussee/caveman · error · Error

is not a valid Caveman ownership journal; refusing overwrite

Error message

${markerPath} is not a valid Caveman ownership journal; refusing overwrite

What it means

Before installing/uninstalling, the CLI reads the ownership marker file for the agent+server pair. If the marker exists but its bytes are not a valid Caveman ownership journal (validMcpMarkerBytes fails), it cannot prove Caveman owns that registration and refuses to overwrite or delete it, protecting markers created or corrupted by other tools.

Solutions

  1. Verify the marker file's content; if it is clearly not a Caveman journal (or is garbage), back it up and delete it, then re-run the mcp command.
  2. If the marker belongs to another tool, move it aside rather than deleting, and let caveman create a fresh marker.
  3. Check the marker corresponds to the right agent+server (wrong serverName resolves a different marker path).
  4. Reinstall/upgrade caveman if the marker came from a much older schema version.

Example fix

// before: corrupt marker blocks install
error: ~/.caveman/markers/... is not a valid Caveman ownership journal
// after: back up and remove, then re-run
mv <markerPath> <markerPath>.bak && caveman mcp install kilo
Defensive patterns

Strategy: validation

Validate before calling

import { readFileSync, existsSync } from 'node:fs';
if (existsSync(markerPath)) {
  const raw = readFileSync(markerPath, 'utf8');
  if (!raw.trimStart().startsWith('{')) console.warn(`${markerPath} is not a caveman marker — back it up and remove it`);
}

Type guard

function looksLikeCavemanMarker(raw: string): boolean {
  try { const v = JSON.parse(raw); return typeof v === 'object' && v !== null && 'agent' in v && 'server_name' in v; }
  catch { return false; }
}

Try / catch

try {
  runMcpCommand();
} catch (e) {
  if (String(e.message).includes('not a valid Caveman ownership journal')) {
    backup(markerPath); rmSafe(markerPath);
    runMcpCommand(); // recreates a fresh marker
  }
}

Prevention

When it happens

Trigger: Thrown in transactOwnedMcpConfig when markerBefore !== null && !validMcpMarkerBytes(markerBefore, agent, serverName) — the file at canonicalOwnedMcpMarkerPath(agent, serverName) exists but is corrupt, foreign, hand-edited, or from an incompatible schema.

Common situations: User deleted/truncated the marker manually; another MCP manager wrote its own file at the same path; a previous interrupted write left a partial marker; copying state between machines corrupted encoding; very old caveman versions wrote an incompatible marker format.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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

Appendix: source

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

function transactOwnedMcpConfig(
  agent: "kilo" | "qwen",
  serverName: string,
  action: "install" | "uninstall",
  mcp?: { command: string; args: string[] },
  lockedConfigPath?: string,
): boolean {
  const plan = action === "install"
    ? agent === "kilo" ? planMcpKiloJson(mcp!, serverName) : planMcpQwenJson(mcp!, serverName)
    : agent === "kilo" ? planRemoveMcpKiloJson(serverName) : planRemoveMcpQwenJson(serverName);
  if (!plan) return false;
  if (lockedConfigPath && plan.path !== canonicalMcpConfigPath(lockedConfigPath)) {
    throw new Error(`${agent} ${serverName} MCP config target changed while acquiring lock; refusing mutation`);
  }

  const markerPath = canonicalOwnedMcpMarkerPath(agent, serverName);
  const markerBefore = fileBytes(markerPath);
  if (markerBefore !== null && !validMcpMarkerBytes(markerBefore, agent, serverName)) {
    throw new Error(`${markerPath} is not a valid Caveman ownership journal; refusing overwrite`);
  }
  const markerBeforeMode = markerBefore === null ? 0o600 : statSync(markerPath).mode & 0o777;
  if (!optionalBytesEqual(fileBytes(markerPath), markerBefore)) {
    throw new Error(`${markerPath} changed while planning MCP update; refusing overwrite`);
  }
  const markerAfter = action === "install" ? mcpMarkerBytes(mcp!, mcpServerToolName(serverName)!, plan.path) : null;
  if (!plan.changed && optionalBytesEqual(markerBefore, markerAfter)) return true;

  const journal: OwnedMcpPendingJournal = {
    schema_version: 1,
    transaction_id: randomUUID(),
    agent,
    server_name: serverName,
    action,
    config_path: plan.path,
    marker_path: markerPath,
    config_before_base64: plan.before?.toString("base64") ?? null,
    config_before_mode: plan.beforeMode,

View on GitHub (pinned to 3ee70a1026)