{"record":{"id":"a6beedd070e0274a","repo":"JuliusBrussee/caveman","slug":"agent-servername-mcp-transaction-failed-and-rolled-back","errorCode":null,"errorMessage":"${agent} ${serverName} MCP transaction failed and rolled back: ${(error as Error).message}","messagePattern":"(.+?) (.+?) MCP transaction failed and rolled back: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":12949,"sourceCode":"    } else {\n      if (!optionalBytesEqual(markerBefore, markerAfter)) durableReplaceFileIfUnchanged(markerPath, markerBefore, markerAfter);\n      if (plan.changed) durableReplaceFileIfUnchanged(plan.path, plan.before, plan.after, plan.beforeMode);\n    }\n    if (optionalBytesHash(fileBytes(plan.path)) !== journal.config_after_sha256\n      || optionalBytesHash(fileBytes(markerPath)) !== journal.marker_after_sha256) {\n      throw new Error(`${agent} ${serverName} MCP transaction postflight mismatch`);\n    }\n    durableUnlink(configPendingPath);\n    durableUnlink(locatorPath);\n    return true;\n  } catch (error) {\n    try {\n      const recovery = recoverOwnedMcpTransaction(readOwnedMcpConfigPending(plan.path) ?? readOwnedMcpPendingLocator(agent, serverName));\n      if (recovery === \"finalized\") return true;\n    } catch (recoveryError) {\n      throw new Error(`${agent} ${serverName} MCP transaction failed and safe recovery was blocked: ${(recoveryError as Error).message}; original error: ${(error as Error).message}`);\n    }\n    throw new Error(`${agent} ${serverName} MCP transaction failed and rolled back: ${(error as Error).message}`);\n  }\n}\n\nfunction withOwnedMcpTransactionLock<T>(\n  agent: \"kilo\" | \"qwen\",\n  serverName: string,\n  run: (lockedConfigPath: string) => T,\n): T {\n  const markerPath = canonicalOwnedMcpMarkerPath(agent, serverName);\n  return withMcpConfigLock(markerPath, () => {\n    const activeConfigPath = () => canonicalMcpConfigPath(agent === \"kilo\" ? kiloConfigPath() : qwenConfigPath());\n    const resourcePath = () => readOwnedMcpPendingLocator(agent, serverName)?.journal.config_path\n      ?? readMcpServerMarker(agent, serverName)?.config_path\n      ?? activeConfigPath();\n    for (let attempt = 0; attempt < 8; attempt++) {\n      const lockPath = canonicalMcpConfigPath(resourcePath());\n      const outcome = withMcpConfigLock<{ retry: true } | { retry: false; value: T }>(lockPath, () => {\n        const locatorPending = readOwnedMcpPendingLocator(agent, serverName);","sourceCodeStart":12931,"sourceCodeEnd":12967,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L12931-L12967","documentation":"Thrown when a kilo/qwen MCP config transaction fails but the ownership journal successfully rolled the change back ('failed and rolled back'). The original error is preserved in the message; the native config should be in its pre-transaction state.","triggerScenarios":"Any failure inside the kilo/qwen MCP install/remove transaction body (write error, spawn failure, validation failure) where recoverOwnedMcpTransaction succeeded in finalizing/rolling back.","commonSituations":"Agent binary rejected the config change; native config file read-only; schema change in the agent's config format broke a mid-transaction step.","solutions":["Read the original error embedded in the message and fix that root cause","Verify the agent's native config was rolled back and re-run the install command","Ensure the agent process is not holding the config file open/locked during install","Check disk space and file permissions on the config directory"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"assertWritable(mcpConfigDir(agent));","typeGuard":null,"tryCatchPattern":"try { installMcp(agent, serverName) } catch (e) {\n  // message ends with 'rolled back'; log original cause and retry after fixing\n  console.error(String(e));\n}","preventionTips":["Close the target agent before changing its MCP config","Back up the native config before install","Keep CLI and agent versions compatible"],"tags":["mcp","config","transaction","rollback"],"backgroundTag":"invalid-state-transition","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"}