{"record":{"id":"1bf6ff2bed99f68e","repo":"JuliusBrussee/caveman","slug":"agent-native-setup-failed-error-as-error-mess","errorCode":null,"errorMessage":"agent-native setup failed: ${(error as Error).message}${rollbackErrors.length ? `; rollback incomplete: ${rollbackErrors.join(\"; \")}` : \"; changes rolled back\"}","messagePattern":"agent-native setup failed: (.+?)(.+?)` : \"; changes rolled back\"\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":2713,"sourceCode":"      try {\n        ensureAgentNativeIntegration(agentNative);\n        installAgentNativeCloudMcp(agentNative, cloudMcp);\n        cloudMcpApplied = true;\n        installAgentNativeBundleSkills(agentNative, journal);\n        verifyAgentNativeBundle(agentNative, journal, cloudMcp);\n        atomicWriteFile(agentNativeBundleJournalPath(agentNative), Buffer.from(JSON.stringify(journal, null, 2) + \"\\n\"));\n        unlinkSync(agentNativeBundleJournalPath(agentNative, true));\n      } catch (error) {\n        const rollbackErrors: string[] = [];\n        try { restoreAgentNativeBundleSkills(rollbackSkills); } catch (rollback) { rollbackErrors.push((rollback as Error).message); }\n        if (cloudMcpApplied) {\n          try { restoreAgentNativeCloudMcp(agentNative, rollbackCloudMcp); } catch (rollback) { rollbackErrors.push((rollback as Error).message); }\n        }\n        if (!nativeWasInstalled) {\n          try { disableNativeAgent(agentNative); } catch (rollback) { rollbackErrors.push((rollback as Error).message); }\n        }\n        try { unlinkSync(agentNativeBundleJournalPath(agentNative, true)); } catch { /* original error remains authority */ }\n        throw new Error(`agent-native setup failed: ${(error as Error).message}${rollbackErrors.length ? `; rollback incomplete: ${rollbackErrors.join(\"; \")}` : \"; changes rolled back\"}`);\n      }\n      const coreState = nativeCoreRuntimeState();\n      const coreLabel = coreState.active ? \"on\" : coreState.configured ? \"configured on; inactive under record mode/profile\" : \"off\";\n      console.error(`${mark(\"ok\")} ${agentNative}: complete agent-native bundle ready`);\n      console.error(dim(`→ coding policy: Core ${NATIVE_PACK.version} ${coreLabel}; change with \\`caveman tools config set think.core ${coreState.configured ? \"off\" : \"on\"}\\`; start new session to clear delivered context`));\n      console.error(dim(`→ remove complete bundle: \\`caveman setup --agent-native ${agentNative} --remove\\``));\n      console.error(dim(\"→ log in with `caveman login`; agent reads project context through existing CLI credentials\"));\n    });\n  }\n  if (install) return setupInstall(json);\n\n  const rows = GO_BINARIES.map((b) => ({ ...b, resolved: resolveGoBin(b.name, b.env) }));\n  const missingRequired = rows.filter((r) => r.required && !r.resolved);\n\n  if (json) {\n    print({\n      binaries: rows.map((row) => ({\n        name: row.name,","sourceCodeStart":2695,"sourceCodeEnd":2731,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/packages/cli/src/index.ts#L2695-L2731","documentation":"Top-level failure of the agent-native setup path: something threw after partial application (skill writes, caveman-cloud MCP registration, native enablement). The handler rolls back applied skills, the cloud MCP (if applied), disables the native agent if it was not previously installed, and drops the pending journal; the message reports whether rollback fully succeeded or lists rollback errors.","triggerScenarios":"Any exception during `caveman setup --agent-native claude|codex` after changes began: unwritable agent config, MCP registration mismatch detected mid-flight, native enablement failure. Rollback errors appear when the same filesystem conditions break restoration.","commonSituations":"Agent running and rewriting its config during setup; home directory permissions changed mid-run; partial disk failure. '; changes rolled back' suffix means clean state; '; rollback incomplete: ...' means manual repair needed.","solutions":["If the message ends with 'changes rolled back', fix the named original error and re-run setup","If rollback was incomplete, follow each rollback error: close the agent, repair permissions, then re-run setup — the recovery paths reconcile pending journals","As a last resort, restore the agent config from backup and delete the agent-native journals under the caveman state directory before re-running setup"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-flight for agent-native setup\nimport { accessSync, constants } from \"node:fs\";\naccessSync(join(homedir(), \".claude\"), constants.W_OK);\naccessSync(join(homedir(), \".codex\"), constants.W_OK);\nif (await isProcessRunning(\"claude\") || await isProcessRunning(\"codex\")) {\n  throw new Error(\"close running agents before agent-native setup\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  await setup([\"--agent-native\", agent]);\n} catch (error) {\n  const msg = (error as Error).message;\n  if (/agent-native setup failed/.test(msg)) {\n    if (/rollback incomplete/.test(msg)) {\n      // partial state on disk: next setup run reconciles via pending journals; fix causes first\n      await fixRollbackCauses(msg);\n      await setup([\"--agent-native\", agent]);\n    }\n    // 'changes rolled back' => environment clean; fix the original error then retry\n    else { await fixOriginalCause(msg); await setup([\"--agent-native\", agent]); }\n  } else throw error;\n}","preventionTips":["Always check for the 'changes rolled back' suffix — it means a clean retry is safe","'rollback incomplete' means never retry blindly; reconcile pending journals first","Close agents and verify writable home config before agent-native setup"],"tags":["setup","rollback","agent-native","transaction"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}