{"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":"Error","httpStatus":null,"severity":"critical","filePath":"packages/cli/src/index.ts","lineNumber":3033,"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":3015,"sourceCodeEnd":3051,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L3015-L3051","documentation":"Thrown when agent-native setup fails partway through; the CLI rolls back each completed step (cloud MCP restore, disabling the native agent, journal cleanup) and throws this aggregate error. If any rollback step itself failed, all rollback errors are appended after \"rollback incomplete:\"; otherwise it ends with \"; changes rolled back\".","triggerScenarios":"Any failure inside the setup --agent-native try block (skill write failure, MCP registration failure, postflight failure) triggers the catch: rollbackCloudMcp/disableNativeAgent/unlink of the journal run, then this error is thrown with the original message plus rollback outcomes.","commonSituations":"Disk full or permission denied while writing skills; agent CLI changed config schema mid-setup; native agent install step failed; multiple rollback steps failing when the filesystem is in a bad state (read-only, sync conflicts).","solutions":["Fix the root cause named before the semicolon (permissions, disk space, agent state), then re-run `caveman setup --agent-native <agent>`.","If the message says \"rollback incomplete\", address each appended rollback error — e.g. manually restore the previous cloud MCP entry or re-enable the native agent.","Close running agent processes and disable file sync on the agent config directory before retrying.","Use `caveman setup --agent-native <agent> --remove` to clear residual state, then set up fresh."],"exampleFix":"// before: setup fails on read-only config dir, rollback partially fails too\nagent-native setup failed: EACCES writing skills; rollback incomplete: EACCES restoring MCP\n// after\n$ chmod -R u+w ~/.claude\n$ caveman setup --agent-native claude","handlingStrategy":"try-catch","validationCode":"// Verify preconditions before setup\naccessSync(agentConfigDir, W_OK);\nstatfsSync(agentConfigDir); // ensure free space\nif (nativeIntegrationStatus(agent).state === \"installed\") console.error(\"Already installed; remove first or re-run to refresh\");","typeGuard":null,"tryCatchPattern":"try {\n  runAgentNativeSetup(agent);\n} catch (err) {\n  const msg = (err as Error).message;\n  if (msg.includes(\"rollback incomplete\")) {\n    console.error(`Manual recovery needed: ${msg}`);\n  } else {\n    console.error(`Setup failed but was rolled back cleanly: ${msg}`);\n  }\n}","preventionTips":["Ensure disk space and write permissions on the agent config dir before setup.","Don't upgrade the agent CLI concurrently with setup.","If a rollback is incomplete, fix each appended error before re-running setup."],"tags":["setup","rollback","atomicity","cli"],"backgroundTag":"rollback-incomplete","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"}