Skip to content

Recover gracefully when default agent setup or launch fails - #10675

Open
baseman70 wants to merge 1 commit into
omacom:quattrofrom
baseman70:fix/agent-setup-error-recovery
Open

Recover gracefully when default agent setup or launch fails#10675
baseman70 wants to merge 1 commit into
omacom:quattrofrom
baseman70:fix/agent-setup-error-recovery

Conversation

@baseman70

@baseman70 baseman70 commented Sep 7, 2026

Copy link
Copy Markdown

Summary

When setting up or switching coding agents via omarchy-default-agent --install <agent> (or selecting an uninstalled agent in the Omarchy menu), the script writes the selection to ~/.config/omarchy/defaults/agent and executes omarchy-agent --inline inside a floating terminal for the initial onboarding session.

If the agent's authentication or startup fails (e.g. an expired token, missing credentials, deprecated OAuth endpoints, or a user aborting setup with Ctrl+C), the broken agent previously remained permanently set as the default, and the terminal would abruptly close with no graceful recourse.

Solution

  1. State Preservation: Capture previous_agent from ~/.config/omarchy/defaults/agent before updating the selection.
  2. Failure Recovery: Trap INT during inline execution and check the exit code of omarchy-agent --inline. If it fails:
    • Revert defaults/agent to previous_agent (or remove the file if no default was previously configured).
    • Print Could not launch <Agent> to stderr.
    • Prompt the user with gum confirm "Would you like to select a different agent?".
    • If confirmed, summon the agent picker (exec omarchy-menu summon setup.default.agent).
    • If declined, exit with status 1 with the clean reverted state preserved.
  3. Unit Tests:
    • Added assertions to test/shell.d/default-agent-test.sh covering:
      • Unset state reversion and menu reopening on confirmation.
      • Previous state restoration (pi) on confirmation.
      • User cancellation / SIGINT (Ctrl+C / exit code 130) state recovery.
      • Non-zero exit code (1) when alternate selection is declined.
      • Terminal clear-screen sequence (\033[2J\033[3J\033[H) verification before launch attempt.
      • Native package-managed agent failure recovery (OpenClaw).
    • Verified that all 50 unit tests in test/shell.d/default-agent-test.sh and 108 tests in ./test/cli pass.

When an uninstalled agent is chosen, omarchy-default-agent --install launches the agent inline inside a floating terminal for its initial session and onboarding. If agent authentication or startup exits with an error (or the user cancels), the broken agent previously remained saved as the permanent default, and the terminal would abruptly exit.

Revert ~/.config/omarchy/defaults/agent to its previous value (or remove it if none was set), report the failure, and offer to reopen the agent selection menu via gum confirm so the user can easily choose another.
@baseman70
baseman70 force-pushed the fix/agent-setup-error-recovery branch from cf729bb to b52bf7b Compare September 7, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant