{"record":{"id":"374a422673bc0b08","repo":"JuliusBrussee/caveman","slug":"agent-caveman-cloud-mcp-postflight-mismatch","errorCode":null,"errorMessage":"${agent} caveman-cloud MCP postflight mismatch","messagePattern":"(.+?) caveman-cloud MCP postflight mismatch","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":2909,"sourceCode":"function installAgentNativeBundleSkills(agent: \"claude\" | \"codex\", journal: AgentNativeBundleJournal): void {\n  const originals = new Map(journal.skills.map((skill) => [skill.file, skill.before_base64]));\n  journal.skills = agentNativeSkillFiles(agent).map(({ file, body }) => {\n    mkdirSync(dirname(file), { recursive: true });\n    atomicWriteFile(file, Buffer.from(body));\n    return {\n      file,\n      before_base64: originals.get(file) ?? null,\n      after_sha256: bytesHash(Buffer.from(body)),\n    };\n  });\n}\n\nfunction verifyAgentNativeBundle(agent: \"claude\" | \"codex\", journal: AgentNativeBundleJournal, cloudMcp: { command: string; args: string[] }): void {\n  const status = nativeIntegrationStatus(agent);\n  if (status.state !== \"installed\") throw new Error(`${agent} native integration postflight is ${status.state}`);\n  const marker = readMcpServerMarker(agent, \"caveman-cloud\");\n  if (!marker || marker.command !== cloudMcp.command || JSON.stringify(marker.args) !== JSON.stringify(cloudMcp.args)) {\n    throw new Error(`${agent} caveman-cloud MCP postflight mismatch`);\n  }\n  if (!agentNativeCloudMcpMatches(agent, cloudMcp)) {\n    throw new Error(`${agent} caveman-cloud MCP registration failed exact postflight`);\n  }\n  for (const skill of journal.skills) {\n    const current = fileBytes(skill.file);\n    if (!current || bytesHash(current) !== skill.after_sha256) throw new Error(`${skill.file} failed skill postflight`);\n  }\n}\n\nfunction removeAgentNativeBundle(agent: \"claude\" | \"codex\"): void {\n  recoverPendingAgentNativeRemoval(agent);\n  recoverPendingAgentNativeBundle(agent);\n  const journal = readAgentNativeBundleJournal(agent);\n  if (!journal) {\n    process.stderr.write(`${mark(\"warn\")} ${agent}: no agent-native bundle journal found\\n`);\n    return;\n  }","sourceCodeStart":2891,"sourceCodeEnd":2927,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L2891-L2927","documentation":"Thrown by verifyAgentNativeBundle when the caveman-cloud MCP server marker read back from the agent's config either does not exist or does not exactly match the expected command and args that were supposed to be registered during setup. This is a postflight consistency check on the agent's MCP configuration.","triggerScenarios":"After setup, readMcpServerMarker(agent, \"caveman-cloud\") returns null, or the marker's command/args differ from the cloudMcp {command,args} the setup intended to write — e.g. the agent rewrote its config, or a stale entry points at an old command path.","commonSituations":"The agent CLI normalized or rewrote its MCP config on startup; a different tool also manages the same MCP server name and overwrote it; switching between dev/staging cloud commands left a stale marker; manual edits to the agent config.","solutions":["Re-run `caveman setup --agent-native <agent>` to rewrite the caveman-cloud MCP entry.","Inspect the agent's MCP config for the caveman-cloud entry and remove stale/conflicting registrations manually, then re-run setup.","Confirm no other tool (or an older caveman version) is managing the caveman-cloud server name in that agent's config.","Compare the marker's command/args with the expected values to spot path drift (e.g. node version path changed) and update."],"exampleFix":"// before: stale marker from an old install\n\"caveman-cloud\": { \"command\": \"/old/path/node\", \"args\": [\"old-cli.mjs\"] }\n// after: re-run setup or correct the entry\n\"caveman-cloud\": { \"command\": \"/current/path/node\", \"args\": [\"/current/caveman.mjs\", \"serve-cloud\"] }","handlingStrategy":"validation","validationCode":"const marker = readMcpServerMarker(agent, \"caveman-cloud\");\nif (!marker || marker.command !== expected.command || JSON.stringify(marker.args) !== JSON.stringify(expected.args)) {\n  console.error(\"caveman-cloud MCP entry missing or stale; re-run caveman setup --agent-native \" + agent);\n}","typeGuard":"function hasCloudMarker(m: unknown): m is { command: string; args: string[] } {\n  return !!m && typeof m === \"object\" && typeof (m as any).command === \"string\" && Array.isArray((m as any).args);\n}","tryCatchPattern":"try {\n  verifyAgentNativeBundle(agent, journal, cloudMcp);\n} catch (err) {\n  if (/(postflight mismatch)/.test((err as Error).message)) {\n    console.error(\"MCP entry drifted; re-running setup to rewrite it\");\n  }\n}","preventionTips":["Don't hand-edit the agent's MCP config while caveman manages the caveman-cloud entry.","Prevent other MCP managers from owning the same server name.","Re-run setup after agent CLI upgrades."],"tags":["postflight","mcp","config-drift","cli"],"backgroundTag":"unexpected-response-shape","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"}