{"record":{"id":"fa42eacb985ef99a","repo":"JuliusBrussee/caveman","slug":"opencode-caveman-mcp-entry-changed-after-enable-r","errorCode":null,"errorMessage":"OpenCode caveman MCP entry changed after enable; refusing destructive disable","messagePattern":"OpenCode caveman MCP entry changed after enable; refusing destructive disable","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":8372,"sourceCode":"    const previousRoutes = operation.owned?.previous_routes && typeof operation.owned.previous_routes === \"object\" && !Array.isArray(operation.owned.previous_routes) ? operation.owned.previous_routes as Record<string, unknown> : {};\n    for (const providerID of [\"openai\", \"anthropic\"]) {\n      const provider = providers[providerID] && typeof providers[providerID] === \"object\" && !Array.isArray(providers[providerID]) ? providers[providerID] as Record<string, unknown> : {};\n      const options = provider.options && typeof provider.options === \"object\" && !Array.isArray(provider.options) ? provider.options as Record<string, unknown> : {};\n      if (options.baseURL !== undefined && options.baseURL !== routes[providerID]) {\n        throw new Error(`OpenCode ${providerID} baseURL changed after enable; refusing destructive disable`);\n      }\n      if (previousRoutes[providerID] === null || previousRoutes[providerID] === undefined) delete options.baseURL;\n      else options.baseURL = previousRoutes[providerID];\n      if (Object.keys(options).length > 0) provider.options = options;\n      else delete provider.options;\n      if (Object.keys(provider).length > 0) providers[providerID] = provider;\n      else delete providers[providerID];\n    }\n    if (Object.keys(providers).length > 0) root.provider = providers;\n    else delete root.provider;\n    const mcp = root.mcp && typeof root.mcp === \"object\" && !Array.isArray(root.mcp) ? root.mcp as Record<string, unknown> : {};\n    if (mcp.caveman !== undefined && JSON.stringify(mcp.caveman) !== JSON.stringify(operation.owned?.installed_mcp)) {\n      throw new Error(\"OpenCode caveman MCP entry changed after enable; refusing destructive disable\");\n    }\n    if (mcp.caveman !== undefined) {\n      if (operation.owned?.previous_mcp === null || operation.owned?.previous_mcp === undefined) delete mcp.caveman;\n      else mcp.caveman = operation.owned.previous_mcp;\n    }\n    if (Object.keys(mcp).length > 0) root.mcp = mcp;\n    else delete root.mcp;\n    return jsonBytes(root);\n  }\n  if (operation.kind === \"aider-config\") {\n    let text = current.toString(\"utf8\");\n    const routeBlock = operation.owned?.route_block;\n    const readBlock = operation.owned?.read_block;\n    const previousRouteLine = operation.owned?.previous_route_line;\n    if (typeof routeBlock !== \"string\" || typeof readBlock !== \"string\") {\n      throw new Error(\"Aider integration journal lacks owned blocks\");\n    }\n    if (!text.includes(routeBlock) || !text.includes(readBlock)) {","sourceCodeStart":8354,"sourceCodeEnd":8390,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L8354-L8390","documentation":"The disable path checks that the mcp.caveman entry in the OpenCode config is byte-identical (JSON.stringify comparison) to what was installed during enable. If it differs, the tool throws rather than deleting an entry the user may have customized. This prevents destroying user modifications to the MCP registration.","triggerScenarios":"Running disable when root.mcp.caveman exists but JSON.stringify(mcp.caveman) !== JSON.stringify(operation.owned.installed_mcp) — i.e. the caveman MCP entry was edited, reformatted with different field order/values, or overwritten by another tool.","commonSituations":"User manually added args/env to the caveman MCP server entry; another extension rewrote the mcp map; JSON was re-serialized with different key ordering or added fields after enable.","solutions":["Revert the mcp.caveman entry to match the originally installed value (operation.owned.installed_mcp), then re-run disable.","Manually delete the mcp.caveman key from the OpenCode config file.","Re-run enable to refresh the journal snapshot, then disable."],"exampleFix":"// before: hand-edited entry\n\"mcp\": { \"caveman\": { \"command\": \"npx\", \"args\": [\"caveman\", \"mcp\", \"--verbose\"] } }\n// after: restore installed form before disabling\n\"mcp\": { \"caveman\": { \"command\": \"npx\", \"args\": [\"caveman\", \"mcp\"] } }","handlingStrategy":"validation","validationCode":"const cfg = JSON.parse(fs.readFileSync(opencodeConfig, 'utf8'));\nconst installed = journal.owned?.installed_mcp;\nif (cfg?.mcp?.caveman && JSON.stringify(cfg.mcp.caveman) !== JSON.stringify(installed)) {\n  throw new Error('mcp.caveman differs from installed snapshot; resolve before disable');\n}","typeGuard":"const mcpUnchanged = (cfg, installed) =>\n  cfg?.mcp?.caveman === undefined ||\n  JSON.stringify(cfg.mcp.caveman) === JSON.stringify(installed);","tryCatchPattern":"try {\n  await caveman.disable(['opencode']);\n} catch (err) {\n  if (err.message.includes('caveman MCP entry changed')) {\n    console.error('Revert or hand-delete the mcp.caveman entry, then retry.');\n  } else throw err;\n}","preventionTips":["Treat mcp.caveman as tool-managed; don't add args/env to it manually.","Register additional MCP servers under their own keys, not inside caveman.","Keep the config under version control to spot unintended rewrites.","Re-run enable after intentional edits so the journal snapshot is fresh."],"tags":["config","disable-safety","mcp"],"backgroundTag":"conflicting-config-options","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"}