Skip to content

Protect account homes throughout CLI startup and sessions - #14656

Open
VykosMolt wants to merge 12 commits into
omacom:quattrofrom
VykosMolt:fix/account-session-lifetime
Open

VykosMolt wants to merge 12 commits into
omacom:quattrofrom
VykosMolt:fix/account-session-lifetime

Conversation

@VykosMolt

@VykosMolt VykosMolt commented Oct 9, 2026 •

Copy link
Copy Markdown

Account dispatch now claims the selected private home before starting Claude, Codex or Grok, and keeps that claim for the exact CLI process lifetime, including startup, terminal signals, descriptor cleanup and sessions that sanitize their environment. Explicit home overrides and inherited account pins retain their existing behavior. The registry lock is held only while selecting or changing an account.

Removal takes an exclusive claim before staging a private home, saving the registry and deleting its files. Failed saves restore the home; incomplete cleanup is reported with its recovery location. Expired sign-ins are excluded from automatic switching while temporarily paused limits remain eligible.

This revision preserves current Quattro's interrupted-sign-in receipts and recovery. A failed registration retains a tracked login that can be registered on retry without another sign-in. Registration and recovery now take exclusive nonblocking claims before moving, deleting or mutating a live login, including when the original add process has exited. The legacy process-environment guard also remains active for unwrapped CLI sessions.

omarchy-agent now hands the CLI it picked to omarchy-agent-account-exec itself, passing --binary for a user install from #14040, so the selected account no longer depends on PATH order. omarchy-agent-account-exec looks up the provider with mise's command-wrappers directory removed from PATH, so a direct call cannot loop through its own wrapper.

Validation against Quattro 14abc0762: account lifecycle suite (43 checks, including concurrency, exact process lifetime, SIGPIPE and rollback), real mise 2026.10.3 dispatch (40, including a user-installed Claude and a real Claude ahead of mise's wrapper), recovery (7), autoswitch (16), copy (6), default agent (50), and CLI all pass. Independent adversarial review reproduced and then verified the fix for an orphaned CLI whose environment no longer reveals its pending home; regressions also cover direct registration, incomplete logins, retained receipts and recovery after session exit. At 9868831 on Quattro 60cb9bf3, autoswitch (17) and recovery (8) each gain a case: an expired active account over the threshold is still switched away from, and registration waits up to a second for a finished login's guardian to release its claim. The mise dispatch suite was not re-run at this head.

@greptile-apps

greptile-apps Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; both previous findings are addressed and no new actionable issue was established.

Summary

This PR protects private account homes from CLI startup until the selected process exits.

  • Agent sessions select and protect their account home when the CLI starts.
  • Account changes protect live logins and preserve files when saving fails.
  • Automatic account switching skips sign-ins that have expired.

Diagram

sequenceDiagram
  participant Launcher
  participant Registry
  participant Guardian
  participant CLI
  participant Removal
  Launcher->>Registry: Lock and select account
  Launcher->>Guardian: Share home claim and exact process lifetime
  Guardian-->>Launcher: Ready
  Launcher->>Registry: Release registry lock
  Launcher->>CLI: Replace launcher with chosen CLI
  Removal->>Registry: Lock registry
  Removal->>Guardian: Try exclusive home claim
  Guardian-->>Removal: Busy while CLI lives
  CLI-->>Guardian: Process exits
  Guardian->>Guardian: Exit and release claim
Loading

Reviews (4) · Last reviewed commit: "Give a finished login's guardian a momen..." · Reviewed by Greptile

@omarchybot omarchybot added bug Something isn't working verified Omarchy Triage has verified that this issue is ready for final review labels Oct 16, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at ec1b442 against quattro 84cfb93, on a disposable Omarchy VM.

The bug is real, and this fixes it. On quattro, omarchy-agent picks the account home before the terminal starts and passes it in the command. If that account is removed in the meantime, the CLI starts with CLAUDE_CONFIG_DIR pointing at the deleted directory and recreates it, empty and unregistered. I reproduced this with the real omarchy-agent and a stand-in terminal that removes the account before running the command. On quattro the CLI started in the removed home and recreated it. On this branch it started on Main and the home stayed gone.

One regression. bin/omarchy-agent:162 now clears the home and pin and relies on claude/codex/grok on PATH being mise's account wrapper. When a real binary comes first (a user mise config overriding the wrapper in etc/mise/conf.d/omarchy-agent-accounts.toml, which that file invites, or a PATH reordered after env-bootstrap), the selected account is silently ignored. With Side selected and a real claude ahead of the wrapper, quattro starts Side and this branch starts Main. Calling omarchy-agent-account-exec explicitly, as omarchy-agent-account-add now does, would make this independent of PATH order.

Scope. The reproduced bug needs account resolution moved to dispatch time, plus the refusal of a managed home that is no longer registered. Both are in this PR and are small. Most of the ~290 source lines are something else: a lock file and a guardian process, forked and kept alive for every CLI session, which protect a running session whose environment no longer names its home. The tests model that with a process that re-execs itself without CLAUDE_CONFIG_DIR. Neither review found a real Claude, Codex or Grok that does this. The PR also carries two separate changes: autoswitch skipping "Sign-in expired" accounts, and staging and restoring a removed home when the registry save fails. Both look correct. Each would be easier to take as its own pull request. Whether the guardian is worth carrying is the maintainer's call.

Tests. The account suites passed on the worker (agent-account 40, agent-account-exec 38, agent-account-recovery 7, agent-account-autoswitch 16, agent-account-copy 6, default-agent 52), and so did ./test/cli. The full ./test/shell run had 6411 passes and 7 failures, all in shell rendering, lock-timing and sudo-grant tests. All 7 fail identically on quattro on the same worker. I also checked that register, run straight after a sign-in exits, does not find the guardian still holding the login's claim: it never did in 300 runs, with or without CPU load.

Second opinion. Codex Medium reviewed the same diff. It found the PATH regression above, which I then confirmed on the worker. It agreed that the startup bug is real and the guardian is unproven; independence is not guaranteed. It found no lock-ordering, descriptor or signal-handling defect. Two of its findings I did not keep. First, a race between the guardian releasing its claim and register: it measured the claim still held at the instant of exit, but register never met a held claim in the 300 real-timing runs above. Second, an unregistered custom home deliberately placed inside omarchy's own accounts directory now being refused: that is not a setup anyone reaches without going out of their way.

Waiting on the author for the PATH regression, and on the maintainer for whether the guardian and the two bundled changes belong here.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 31, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Re-checked at ec1b442, which is unchanged since the review above, against quattro bbfdfdd. This branch no longer merges cleanly, and I took the verified label off for that reason.

The bug is still on quattro. bin/omarchy-agent:254-257 on quattro still picks the account home before the terminal starts, so this fix is still needed.

Two conflicts, both mechanical.

  • bin/omarchy-agent-account-exec: Give agents mise shims so they find tools installed after launch #16593 added a block that puts mise's shims back on PATH, in the same spot where this branch adds its omarchy-agent-account-state exec routing. Keep quattro's PATH block in place of the old export PATH= line, then put this branch's routing after it. Quattro's install logic for declared tools, just above, has to stay too.
  • test/shell.d/agent-account-test.sh: quattro added a Grok settings-cache test where this branch added its failed-registry-save test. Keep both.

The PATH regression from the earlier review gets worse after the merge. #14040 lets bin/omarchy-agent run the user's own ~/.local/bin/<agent> directly (quattro bin/omarchy-agent:227-234). On quattro that still works with accounts, because the selected home is passed in the command. That file merges with no conflict, but the result swaps the home for env -u (merged lines 253-255). So a user-installed claude, codex or grok would now start on the default account and never reach omarchy-agent-account-exec, and the selected account would be ignored. This no longer needs an unusual PATH, just a user install, which is supported. I found this by reading the merged code and did not run it on a worker. The fix suggested earlier still covers it: have the launcher call omarchy-agent-account-exec explicitly, passing it the binary it chose, rather than relying on what comes first on PATH.

What I checked. I ran a trial merge with git on the coordinator, ran none of the code, and compared quattro's account-script changes since 84cfb93. #14099, #14100 and #14103 do not overlap with this branch's account-protection changes. No other open pull request fixes the same bug. Because the head has not moved, the earlier worker results still describe this commit.

Second opinion. Codex Medium and muse-wonder (via pi, thinking high) reviewed the conflicts and the quattro changes. Both agreed on the two conflicts and how to resolve them, and that the bug is still present. Independence is not guaranteed. Both raised the #14040 interaction, which I had not caught myself, and I then confirmed it in the merged launcher.

Waiting on the author to merge quattro and fix the account selection in the launcher. The question from the earlier review, whether the guardian and the two bundled changes belong in this PR, is still the maintainer's.

VykosMolt and others added 2 commits November 6, 2026 23:14
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… on PATH order

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread bin/omarchy-agent-account-state Resolved
Comment thread bin/omarchy-agent-account-state Resolved
@VykosMolt

Copy link
Copy Markdown
Author

Merged current quattro (ff13cf8) and fixed the launcher (5892b6a). omarchy-agent no longer relies on PATH order: for Claude, Codex and Grok it now runs omarchy-agent-account-exec <agent> itself, passing --binary ~/.local/bin/<agent> when #14040's user install is the CLI it picked. omarchy-agent-account-exec looks up the provider with mise's command-wrappers directory taken off PATH, so a direct call can't recurse through its own wrapper; under mise that directory is already gone and nothing changes.

Two new checks in agent-account-exec-test.sh run real mise: a user-installed claude and a real claude ahead of the wrapper both start on Side now, and both start on Main at ff13cf8. Account suites pass (43/40/7/16/6, default-agent 50) and ./test/cli passes. The full ./test/shell fails the same 12 files as clean quattro on this machine, which lacks quickshell, mise and tmux.

VykosMolt and others added 3 commits November 13, 2026 19:48
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dropping it left decide() with no current usage, so new sessions stayed on
the expired account even with a healthy one to move to.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The guardian drops its claim just after the CLI exits, so the add command's
register could meet it and report a completed sign-in as still running.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot omarchybot removed the bug Something isn't working label Nov 17, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Re-checked at 9868831, which now merges cleanly with quattro 3b36b9e. Since the last review you merged quattro, made omarchy-agent call omarchy-agent-account-exec itself with the CLI it picked (5892b6a), kept an expired active account's usage for the switch check (cacbfae), and gave a finished login's guardian a second to release before register (9868831). I read those three commits. That last one answers a race the first review here set aside: 300 timed register runs never hit it, but your direct probe found the claim still held right after exit every time, and the probe is the better test.

The classification is unsettled. The head moved, so it was classified again. Two models were asked separately, from the PR alone. Claude (Opus 5.5) called it a bug: on quattro a removed account's home is still recreated when the removal lands while a session is starting, and this PR fixes that. Codex Medium called it an enhancement. Both readings fit what the diff holds. A small part fixes the startup bug, which was reproduced earlier. Most of it adds new behaviour: the per-session guardian, expired sign-ins dropped as autoswitch destinations, and restoring a removed home when the registry save fails. Since the two models disagree, I took the bug label off and did no further review or verification at this head. Nothing was run on a worker for these commits, so the earlier worker results describe ec1b442, not this head.

Waiting on the maintainer, both to settle what this PR is and to decide whether the guardian and the two bundled changes belong here. That question from the earlier reviews is still open.

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.

2 participants