{"record":{"id":"29cc3dfd03c226dc","repo":"JuliusBrussee/caveman","slug":"markerpath-is-not-a-valid-caveman-ownership-jou","errorCode":null,"errorMessage":"${markerPath} is not a valid Caveman ownership journal; refusing overwrite","messagePattern":"(.+?) is not a valid Caveman ownership journal; refusing overwrite","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":12886,"sourceCode":"function transactOwnedMcpConfig(\n  agent: \"kilo\" | \"qwen\",\n  serverName: string,\n  action: \"install\" | \"uninstall\",\n  mcp?: { command: string; args: string[] },\n  lockedConfigPath?: string,\n): boolean {\n  const plan = action === \"install\"\n    ? agent === \"kilo\" ? planMcpKiloJson(mcp!, serverName) : planMcpQwenJson(mcp!, serverName)\n    : agent === \"kilo\" ? planRemoveMcpKiloJson(serverName) : planRemoveMcpQwenJson(serverName);\n  if (!plan) return false;\n  if (lockedConfigPath && plan.path !== canonicalMcpConfigPath(lockedConfigPath)) {\n    throw new Error(`${agent} ${serverName} MCP config target changed while acquiring lock; refusing mutation`);\n  }\n\n  const markerPath = canonicalOwnedMcpMarkerPath(agent, serverName);\n  const markerBefore = fileBytes(markerPath);\n  if (markerBefore !== null && !validMcpMarkerBytes(markerBefore, agent, serverName)) {\n    throw new Error(`${markerPath} is not a valid Caveman ownership journal; refusing overwrite`);\n  }\n  const markerBeforeMode = markerBefore === null ? 0o600 : statSync(markerPath).mode & 0o777;\n  if (!optionalBytesEqual(fileBytes(markerPath), markerBefore)) {\n    throw new Error(`${markerPath} changed while planning MCP update; refusing overwrite`);\n  }\n  const markerAfter = action === \"install\" ? mcpMarkerBytes(mcp!, mcpServerToolName(serverName)!, plan.path) : null;\n  if (!plan.changed && optionalBytesEqual(markerBefore, markerAfter)) return true;\n\n  const journal: OwnedMcpPendingJournal = {\n    schema_version: 1,\n    transaction_id: randomUUID(),\n    agent,\n    server_name: serverName,\n    action,\n    config_path: plan.path,\n    marker_path: markerPath,\n    config_before_base64: plan.before?.toString(\"base64\") ?? null,\n    config_before_mode: plan.beforeMode,","sourceCodeStart":12868,"sourceCodeEnd":12904,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L12868-L12904","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","If the marker belongs to another tool, move it aside rather than deleting, and let caveman create a fresh marker.","Check the marker corresponds to the right agent+server (wrong serverName resolves a different marker path).","Reinstall/upgrade caveman if the marker came from a much older schema version."],"exampleFix":"// before: corrupt marker blocks install\nerror: ~/.caveman/markers/... is not a valid Caveman ownership journal\n// after: back up and remove, then re-run\nmv <markerPath> <markerPath>.bak && caveman mcp install kilo","handlingStrategy":"validation","validationCode":"import { readFileSync, existsSync } from 'node:fs';\nif (existsSync(markerPath)) {\n  const raw = readFileSync(markerPath, 'utf8');\n  if (!raw.trimStart().startsWith('{')) console.warn(`${markerPath} is not a caveman marker — back it up and remove it`);\n}","typeGuard":"function looksLikeCavemanMarker(raw: string): boolean {\n  try { const v = JSON.parse(raw); return typeof v === 'object' && v !== null && 'agent' in v && 'server_name' in v; }\n  catch { return false; }\n}","tryCatchPattern":"try {\n  runMcpCommand();\n} catch (e) {\n  if (String(e.message).includes('not a valid Caveman ownership journal')) {\n    backup(markerPath); rmSafe(markerPath);\n    runMcpCommand(); // recreates a fresh marker\n  }\n}","preventionTips":["Don't hand-edit or truncate ownership marker files","Check which tool owns marker files at ~/.caveman marker paths before overwriting","Keep caveman up to date to avoid old-schema marker incompatibilities","Restore state via caveman's own commands rather than copying markers between machines"],"tags":["mcp","marker","validation","ownership"],"backgroundTag":"schema-validation-failed","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}