Repository navigation
fix(codex): tell the user when a resumed pane is pinned to another account - #10804
Merged
brennanb2025 merged 8 commits intoJul 27, 2026
Conversation
…e pane's launch account
Dismissing the Codex restart prompt deleted the notice record, and
`previousAccountLabel` on that record is the renderer's only memory of the
account the pane actually launched under. With it gone, re-selecting the pane's
original account read as a fresh switch and created an inverted notice
{previous: B, next: A} — and since `isCodexPaneStale` treats any notice as
stale, that false notice silently dropped every keystroke in the pane.
Keep the record and mark it `dismissed` instead. Two shared predicates
(`blocksCodexPaneInput`, `awaitsCodexRestartAnswer`) hold the deliberate
asymmetry between the two answered states in one place: a queued restart still
blocks input because the pane runs under the old account until it relaunches,
while a dismissal frees the keyboard immediately because keeping that account is
what the user asked for. A dismissal is not carried across a later switch, so a
genuinely different third account still prompts.
`isCodexPaneStale` consulted the tab-level `tab.ptyId` even when the pane held its own notice record. In a split tab `tab.ptyId` is whichever pane bound last, so a pane the user had answered "Keep old account" for kept a dead keyboard because a sibling still held an unanswered notice — with no prompt of its own to explain it, which is the exact outcome the dismissed marker exists to prevent. The panes drift apart in practice: dismissal forgets the pane's launch record, and a later switch only re-marks panes whose foreground process is Codex right then, so a sibling can pick up a fresh notice while this pane keeps its dismissal. The pane's own record is now the last word; the tab lookup stays as the reconnect-race fallback it was written for, used only when the pane has no record. Also strips `dismissed` when `queueCodexPaneRestarts` sets `restartRequested`, mirroring the strip already in `dismissCodexRestartNotices`. Both queue call sites filter dismissed panes out today, so this is unreachable rather than a live bug, but the combined state resolves as "dismissed wins" in `blocksCodexPaneInput` — input flowing freely in a pane that is still on the old account with a restart queued.
… pane A pane with no notice of its own still fell through to the tab-level `tab.ptyId` check, so in a split tab a plain shell inherited whichever pane bound last. Once that sibling's restart was requested the prompt is gone, so the innocent pane's keyboard went dead with nothing on screen to answer. The fallback is only needed for a pane whose transport has not bound: both transports refuse writes while their pty binding is null (pty-transport sendInput, remote-runtime sendInput gate on it), so the tab's persisted id is the only evidence of which shell that pane will reach. A bound pane's own ptyId is exactly where its keystrokes go, so its own record is authoritative.
Adding a Codex account and reauthenticating the active one both re-mark every live pane with the active account unchanged. Once a dismissed notice survives as launch-account memory, that re-mark rebuilt the record without the marker, resurrecting a prompt the user had answered and re-blocking the pane's keyboard. Carry `dismissed` forward when the target account is the one the dismissal already answered.
Both were added by this PR onto the gate whose false positives silently kill a pane's keyboard, so a wrong mental model here is expensive. `tab.ptyId` does not name the pane that bound last: `updateTabPtyId` keeps the first binder (`currentTabPtyId ?? nextPtyIds[0]`, "later split-pane spawns must not steal it") and only `clearTabPtyId` demotes it to the last survivor. And a keystroke on an unbound pane does not arm recovery against `tab.ptyId` — `requestTerminalPaneRecovery` targets `ptyIdsByTabId[tabId][0]`, which diverges from `tab.ptyId` in split tabs. The reasoning the fixes rest on is unchanged: `tab.ptyId` holds *some sibling's* id rather than this pane's, which is what makes it wrong to gate a bound pane on. Comments only — no behavior change.
…count An automatic session resume overrides the current account selection on purpose: `prepareCodexSessionResumeForLaunch` pins CODEX_HOME to the home that owns the rollout so Orca never resumes a session under a different account. But `recordCodexPaneAccountForSpawn` read that pin as "intentional, nothing to say" and forgot the pane, so a cold-restored pane silently came back on the account the user had already switched away from — the reporter's `0% left` TUI under a `78% left` status bar (#10757). Record the account that actually owns the pinned home instead of forgetting it. The existing stale-pane sweep and CodexRestartChip then name it without any new UI: "Codex is still signed in as A. Restart this session to use B." A home is attributed only when Orca can prove who owns it — the real system home maps to the system-default account, a managed home maps to its account on the same selection lane, and anything else (notably the shared runtime mirror, which hot-swaps to whichever account is selected) stays unrecorded. That asymmetry is deliberate: a restart notice blocks every keystroke in its pane, so a guess would turn a correctly-signed-in terminal into one that silently ignores typing.
…ording The runtime controller's spawn path repeats the same recordCodexPaneAccountForSpawn call the ipc handler makes, but nothing exercised it: reverting either pinnedByResume or launchCodexHomePath at that site left all 392 tests green. That site is the CLI/relay resume path (terminal.ts accepts resumeProviderSession, orca-runtime threads it into ptyController.spawn), so an unnoticed revert there would silently restore the bug for those clients. Also corrects the guard's rationale. The shared runtime mirror only hot-swaps to the current selection on the legacy flag-OFF lane; with the real-home routing that ships unconditionally, syncForCurrentSelection early-returns through syncSelfContainedManagedSelection and never rewrites the mirror's auth.json. Declining to attribute is still right — an unowned home cannot be named — but not for the stated reason, and a pane resumed into the mirror after the per-account rollout is genuinely stale and stays unreported.
brennanb2025
force-pushed
the
brennanb2025/codex-resume-pinned-account-notice
branch
from
July 27, 2026 01:29
2a5631c to
6ba25c6
Compare
The previous commit corrected this rationale in the module but left an identical copy in the test that asserts the same behavior.
brennanb2025
changed the base branch from
brennanb2025/codex-notice-dismissed-state
to
brennanb2025/fix-codex-account-switch
July 27, 2026 04:46
brennanb2025
merged commit Jul 27, 2026
fef8717
into
brennanb2025/fix-codex-account-switch
3 checks passed
This was referenced Jul 27, 2026
brennanb2025
added a commit
that referenced
this pull request
Jul 28, 2026
…count switch (#10770) Fixes #10757. Switching Codex accounts broke three ways, all rooted in the self-contained per-account CODEX_HOME from #9501. HISTORY DISAPPEARED. Codex's own /resume picker only lists rollouts under the launch CODEX_HOME, and nothing bridged history into a per-account home — only the AI Vault's discovery scan knew about the other homes. Every other Orca-visible home's rollouts are now hardlinked in, on selection and again at launch, so one physical log is listed everywhere. THE RESTART PANEL STUCK. A queued restart was only drained by a mounted TerminalPane, but the prompt covered every stale pane in the worktree including parked and cold-deferred tabs. Requesting a restart now answers the prompt immediately while the pane keeps its pending restart, and a pane drains it when its reconnected PTY binds. PANES STAYED ON THE OLD ACCOUNT. CODEX_HOME is fixed in a shell's environment at spawn and the daemon keeps those shells alive across app restarts, while the restart notices are renderer state and are discarded. Each PTY's launch account is now recorded on disk and compared against the current selection at startup. Also merged in: #10802 (a dismissed notice no longer kills the pane's keyboard), #10803 (the sweep arms on real PTY binds, and launcher Codex panes are no longer filtered out by Windows deepest-process reporting), #10804 (a resume-pinned pane now says which account it is on), #10870 (the restart card no longer parks focus on its destructive Restart button), #10853 (the retry ladder is widened past the Windows worst case). Six independent reviews found real defects in every original PR, several of them dead-keyboard bugs and three introduced by the fix for another defect in the same loop. Live QA on macOS covered every PR; Windows was validated three times. WINDOWS: pass 1 found two defects that made the stale-account fix a no-op there (the sweep fired before any PTY was bound and never retried; launcher panes were filtered out). Pass 3 at the merged head: the prompt appears on its own after a restart — warm ~3.7-4.2s, cold ~21s needing rung 4, so #10853's widening was load-bearing rather than precautionary; an ordinary sentence typed into a healthy pane while another pane's card is up reaches that pane and kills nothing; a pane running vim after exiting Codex gets no card, still none 45s later. auth.json byte-identical across every pass. KNOWN GAPS, stated rather than implied: #10804 is unverified on Windows (auto-resume could not be manufactured there); cross-volume Windows is untested and expected to yield no bridged history (EXDEV, and Codex ignores symlinked rollouts); a cold-parked pane never binds so the sweep never covers it; the subagent-deepest launcher shape could not be reproduced on Windows, so that branch is fixture-verified only; WSL passed isolation but the resume mechanism is host-lane only. A host-account switch also marks and mutes live SSH remote panes — confirmed pre-existing on main by two independent QA runs — tracked separately in #10992. Related pre-existing defect filed as #10863.
enrick-dev
pushed a commit
to enrick-dev/orca
that referenced
this pull request
Oct 15, 2026
…count switch (stablyai#10770) Fixes stablyai#10757. Switching Codex accounts broke three ways, all rooted in the self-contained per-account CODEX_HOME from stablyai#9501. HISTORY DISAPPEARED. Codex's own /resume picker only lists rollouts under the launch CODEX_HOME, and nothing bridged history into a per-account home — only the AI Vault's discovery scan knew about the other homes. Every other Orca-visible home's rollouts are now hardlinked in, on selection and again at launch, so one physical log is listed everywhere. THE RESTART PANEL STUCK. A queued restart was only drained by a mounted TerminalPane, but the prompt covered every stale pane in the worktree including parked and cold-deferred tabs. Requesting a restart now answers the prompt immediately while the pane keeps its pending restart, and a pane drains it when its reconnected PTY binds. PANES STAYED ON THE OLD ACCOUNT. CODEX_HOME is fixed in a shell's environment at spawn and the daemon keeps those shells alive across app restarts, while the restart notices are renderer state and are discarded. Each PTY's launch account is now recorded on disk and compared against the current selection at startup. Also merged in: stablyai#10802 (a dismissed notice no longer kills the pane's keyboard), stablyai#10803 (the sweep arms on real PTY binds, and launcher Codex panes are no longer filtered out by Windows deepest-process reporting), stablyai#10804 (a resume-pinned pane now says which account it is on), stablyai#10870 (the restart card no longer parks focus on its destructive Restart button), stablyai#10853 (the retry ladder is widened past the Windows worst case). Six independent reviews found real defects in every original PR, several of them dead-keyboard bugs and three introduced by the fix for another defect in the same loop. Live QA on macOS covered every PR; Windows was validated three times. WINDOWS: pass 1 found two defects that made the stale-account fix a no-op there (the sweep fired before any PTY was bound and never retried; launcher panes were filtered out). Pass 3 at the merged head: the prompt appears on its own after a restart — warm ~3.7-4.2s, cold ~21s needing rung 4, so stablyai#10853's widening was load-bearing rather than precautionary; an ordinary sentence typed into a healthy pane while another pane's card is up reaches that pane and kills nothing; a pane running vim after exiting Codex gets no card, still none 45s later. auth.json byte-identical across every pass. KNOWN GAPS, stated rather than implied: stablyai#10804 is unverified on Windows (auto-resume could not be manufactured there); cross-volume Windows is untested and expected to yield no bridged history (EXDEV, and Codex ignores symlinked rollouts); a cold-parked pane never binds so the sweep never covers it; the subagent-deepest launcher shape could not be reproduced on Windows, so that branch is fixture-verified only; WSL passed isolation but the resume mechanism is host-lane only. A host-account switch also marks and mutes live SSH remote panes — confirmed pre-existing on main by two independent QA runs — tracked separately in stablyai#10992. Related pre-existing defect filed as stablyai#10863.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #10802 (base:
brennanb2025/codex-notice-dismissed-state), which is itself stacked on #10770. Review only the top commit.Root cause
Issue #10757's reporter sees a Codex TUI reading
0% left(old account) under an Orca status bar reading78% left(new one), "no matter how many times I restart the application." There are two independent mechanisms behind that. #10770 fixes the first (CODEX_HOME baked into a daemon-kept shell). This is the second.prepareCodexSessionResumeForLaunch(src/main/index.ts) ends with:That value becomes
codexResumeHome.codexHomePath, whichsrc/main/ipc/pty.tsthen uses asselectedCodexHomePath, overriding the current account selection. This is deliberate — Orca refuses to resume a rollout under an account that does not own it, "to avoid using a different account."The bug is that it happens silently.
recordCodexPaneAccountForSpawnread the pin as "intentional, nothing to say" and calledforgetCodexPaneAccount, so the pane was never reported bylistStaleCodexPanesand the startup sweep never raised a prompt. The user switched accounts, the pane cold-restored, and it came back on the old account with no indication.The pin is not changing. Resume still follows the originating account. This PR only makes Orca say so.
The fix
Record the account that actually owns the pinned home instead of forgetting the pane. No new UI —
CodexRestartChipalready renders exactly the right message ("Codex is still signed in as {previous}. Restart this session to use {next}."), it just never fired for these panes.New
src/main/codex/codex-pane-launch-account.tsmaps an effective CODEX_HOME back to an account id:null)migrated.useRealCodexHome)null)codexManagedAccounts[].managedHomePathon the same selection laneThe last row is the load-bearing one. A restart notice blocks all pane input (
isCodexPaneStale→pty-connection.ts:819), so a wrong attribution turns a correctly-signed-in terminal into one that silently ignores typing. The shared runtime mirror (codex-runtime-home/home) hot-swaps to whichever account is selected, so a pane resumed into it is not on a different account — guessing "system default" there would be a false positive. Under the flag-OFF lane every host account launches from that mirror, so those installs keep today's behavior exactly.Lane matching (
getCodexSelectionLaneKey) means a WSL pane is only ever attributed to an account on its own per-distro lane. (In practiceprepareCodexSessionResumeForLaunchreturnsnullfor WSL targets today, so this is belt-and-braces against that changing.)recordCodexPaneAccountForSpawnnow passes the effectiveselectedCodexHomePathrather than the raw resume home, so a home dropped bygetCompatibleSelectedCodexHomePath(host/WSL incompatibility) is attributed to what the shell will really run against, not to what was requested.Mutation proof
Every new test was mutation-proved. Five separate reverts, each run against the new suites:
null(the pre-fixforgetCodexPaneAccountbehavior)recordCodexPaneAccountcalls[]vs['pty-resumed', {accountId: 'account-a'}])if (args.pinnedByResume) { forget; return }guard inpty.tsdoes not let a host account answer for a WSL pane on the same pathmaps a resume redirected to the real system home to the system-default accountnullinstead ofundefinedfor an unowned home (guess system default)refuses to attribute a resume home no account owns, the WSL-lane test, andtolerates settings that carry no managed account rosterAll 9 unit tests and both integration tests are covered by at least one mutation. The four tests that survive mutation A are the false-positive guards — they assert
nullon both sides of A by design, and mutations C/D/E are what discriminate them.Gates
All run locally, all green:
npx tsc --noEmit -p config/tsconfig.node.jsonnpx tsc --noEmit -p config/tsconfig.tc.cli.jsonnpx tsc --noEmit -p config/tsconfig.tc.web.jsonnpx oxlint(exit 0; warnings are pre-existing, none in changed files)node config/scripts/check-max-lines-ratchet.mjs— OK, no new bypassesnpx vitest run --config config/vitest.config.ts src/main/codex/ src/main/ipc/pty.test.ts— 39 files, 964 passedsrc/main/ipc/codex-accounts.test.ts,codex-restart-chip{,-inputs}.test.ts,codex-session-restart.test.ts,codex-restart-notice-lifecycle.test.ts— 44 passedNo new file is reachable from the CLI graph (
pty.tsandcodex-pane-account-registry.tsare not inconfig/tsconfig.cli.json), so no explicit-file-list change was needed. No user-facing strings added.Restart loop — checked, not assumed
The obvious hazard is that the chip's Restart re-triggers the same auto-resume, re-pins to the old account, and the chip comes straight back. Traced end to end:
CODEX_ACCOUNT_RESTART_STARTUPis{ command: 'codex', startupCommandDelivery: 'shell-ready' }— noresumeProviderSession, nolaunchConfig. An existingtoEqualassertion incodex-session-restart.test.tspins that shape.handleRestartCodexPanecallsclearTabPtyIdand passes norestoredLeafId/restoredPtyIdByLeafId(neither is ever passed fromTerminalPanein production), sorestoredSessionId,detachedLivePtyId, anddetachedRemoteLeafPtyIdall resolvenull→ the fresh-spawn branch.sleptRemoteColdRestoreStartup || hasSleepingAgentSession. The former needs a remote-runtime restored session id (nullhere); the latter needs a sleeping record for the pane key, which the earlier cold restore consumed viaclearSleepingRecordAfterColdRestoreSpawn.So in the acceptance scenario the restart spawns plain
codexunder the new account and the chip does not return.One narrow residual, pre-existing and reported rather than fixed:
clearSleepingRecordAfterColdRestoreSpawnonly clears when!startup.useLiveEntry(pty-connection.ts:4613). If a live agent-status entry and a stale sleeping record coexist for one pane key (the hibernation-wake path), the record survives and a subsequent chip Restart would rebuild a resume and re-pin. This is behavior on the base branch, not introduced here — it applies equally to a non-pinned pane whose restart re-resumes. This PR makes it visible where it previously went unreported. Closing it means threading a "do not auto-resume" flag throughconnectPanePtyintopty-connection.ts, which is out of scope for this change and overlaps a file a sibling PR is editing.Dismissal composes with #10802
Dismiss ("Keep old account") marks the renderer notice
dismissedand callscodexAccounts:forgetStalePanes, which deletes the on-disk record. This PR only writes at spawn time, so it never resurrects a dismissed record for a live pane. Note that if the pane later cold-restores again (a genuinely new Codex process re-pinned to the old account), it is re-recorded and can prompt again — correct, in my read, since the earlier dismissal answered for a process that no longer exists.Not verified
markRestoredStaleCodexSessionsForRestartfires once fromApp.tsxover PTYs live at that moment. A pane that cold-restores after the sweep has run gets its record written but no chip until the next app launch. That is the startup-sweep bind race a sibling agent is fixing on a separate branch off fix(codex): keep history, restarts, and account identity across an account switch #10770; I did not duplicate it. Until that lands, acceptance item 1 can present one launch later than ideal.//wsl.localhost/...and\\wsl$\...) throughnormalizeRuntimePathForComparison, but no Windows run.