Repository navigation
fix(codex): sweep stale panes on real PTY binds and stop filtering out launcher panes - #10803
Merged
brennanb2025 merged 6 commits intoJul 27, 2026
Conversation
…t launcher panes Live Windows 11 validation of #10770 found fix 3 never produced a card, for two independent reasons. Both are fixed here. **The startup sweep raced PTY bind.** markRestoredStaleCodexSessionsForRestart was called once, fire-and-forget, during hydration — when nothing is attached yet. Every inspectProcess answered terminal_gone, the pty-id list came back empty, the function early-returned and nothing ever retried. Invoking the same function by hand once the app had settled produced the correct notice immediately, so the logic was right and only the scheduling was wrong. Drive it from the bind chokepoint instead. Every real bind — fresh spawn, provider rebind, daemon reattach — funnels through the pane->PTY layout write in connectPanePty, which is the first moment a restored shell can be inspected at all. Each bound PTY is queued, coalesced over a short window so updateTabPtyId lands before the tab walk, and swept once. A pane whose process read is unusable, or a Codex tab still showing its shell mid-reattach, is retried on a three-step ladder and then dropped; an authoritative "not stale" stops immediately, and a pane that has already been notified is never queued again. **Launcher-started Codex panes were filtered out before the registry was even consulted.** The foreground test accepted only `codex`/`codex-*`, but Windows reports the DEEPEST process in the tree, so an Orca "Codex" pane running a subagent reads as pwsh -> node -> codex.exe -> claude.exe => "claude". Any live child — git, node, a subagent — did this, on the switch-time path as well as the sweep. Fall back to the tab's recorded launchAgent, which is metadata rather than a repaintable label, and pair it with a non-shell foreground plus a live child: a restart notice makes the pane drop every keystroke, so a pane the user exited back to its prompt must never be marked.
The launcher-pane fallback accepted any non-shell foreground, so an Orca Codex tab the user had exited and was now typing into (`less`, `vim`, `ssh`, `git`) was marked stale on an account switch — and a restart notice drops every keystroke in that pane, leaving no way to quit the program from the keyboard. Both the Windows descendant scan and the POSIX `ps` walk only ever surface a recognized agent or the shell/tty foreground, so require the fallback foreground to be a recognized agent (or its unresolved node/python wrapper). Also cover the restored-session reattach bind: removing the sweep notification there left every test green, yet that is the only path a pane which outlived the app takes to its PTY.
One shared timer drained the whole queue, but each PTY tracks its own rung, so a pane already waiting on its 1500ms rung had the next rung consumed by a newer pane's shorter delay: two panes bound ~300ms apart burned pane A's three attempts by t=3300 instead of t=5800, dropping a Windows daemon reattach that had not settled yet. `arm()` also refused to move a pending timer earlier, so a fresh bind waited out whatever retry delay happened to be armed. Queue a due time per PTY and keep one timer aimed at the earliest of them. A PTY that has never been inspected still folds into an earlier sweep, so a staggered startup burst is still one registry round-trip.
listStalePanes is the one call in the sweep with no catch of its own, and it reads the on-disk pane-account registry. A single transient rejection dropped the PTYs that sweep had taken AND returned without re-aiming the timer, so any pane parked on a later rung — no longer holding the timer, and untouched by the failed sweep — was left with nothing that would ever fire it: no card, ever. Spend a rung for the taken PTYs through the existing ladder, so a thrown sweep retries like any other unusable read, and re-aim the timer before returning.
The strand regression test rejected listStalePanes by call ordinal, so the rejection would silently attach to the wrong sweep if the flush sequence ever changed. Key it on the requested ptyIds instead.
The strand test set up its scenario purely through timer arithmetic, so a later change to when sweeps fire could leave it green while no longer reproducing the stranding at all. Pin that the throw landed on a sweep of pty-2 alone and that pty-1 later got its own sweep.
brennanb2025
merged commit Jul 27, 2026
74e6478
into
brennanb2025/fix-codex-account-switch
4 checks passed
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 #10770 (base:
brennanb2025/fix-codex-account-switch, pinned at 1818553 for live Windows validation — nothing here touches that branch).Live Windows 11 validation of #10770 found that its "fix 3" — the startup sweep that re-raises a Codex account-restart prompt for a pane that outlived the app — never produced a card, for two independent reasons. Registry, staleness detection, labels and rendering all worked; the prompt just never appeared. Both causes are fixed here.
Defect 1 (blocker): the startup sweep raced PTY bind
markRestoredStaleCodexSessionsForRestart()was called once, fire-and-forget, during hydration. At that moment no PTYs are bound — the startup log is full ofpty:inspectProcess: terminal_gone. The pty-id list came back empty, the function early-returned, and nothing ever retried. On the Windows box the registry was intact andlistStalePanesdid report the pane as stale, yet no card appeared after 70+ seconds. Calling the same function by hand once the app had settled produced the correct notice immediately, so this was purely a scheduling bug.Fix: key off an actual bind signal, not a point in time. Every real bind — fresh spawn, provider rebind, and daemon reattach — funnels through the pane→PTY layout write in
connectPanePty(bindActivePanePtyand the attach path). That is the first moment a restored daemon shell can be inspected at all.notifyCodexPaneBoundForStaleSweep(ptyId)queues the PTY there;codex-stale-pane-sweep.tsowns the scheduling.This is deliberately the same shape as the earlier fix in this PR stack, which had to move off
store.ptyIdsByTabId(already populated for a restored id before the pane mounts) and onto the layout binding that a real bind rewrites.Bounds, per the acceptance criteria:
updateTabPtyIdland, since the scan walks tabs to reachlaunchAgent.listStalePanesstops reporting it.App.tsx's hydration-time call is removed: it inspected zero PTYs by construction, and keeping it would only bypass the sweep's dedupe.Defect 2: launcher-started Codex panes were filtered out
isCodexForegroundProcess()accepted onlycodexandcodex-*. Windows reports the deepest process in the tree. Measured in the same app at the same instant:codexpwsh -> codex.execodexpwsh -> node -> codex.exe -> claude.execlaudeAny live child — git, node, a subagent — does this. The pane was filtered out before the registry was consulted, so it got no card from the sweep and none on account switch. This is pre-existing on
main(it also affectsmarkLiveCodexSessionsForRestart) and is very likely why the original reporter on #10757 never saw a prompt at all.Fix (
codex-pane-restart-eligibility.ts): a pane is eligible when the foreground is Codex itself, or all three of:launchAgent === 'codex'— recorded metadata, not a repaintable label (the existing comment incodex-session-restart.tsexplains why tab titles are unreliable; this is a different, stronger signal, andlaunchAgentis only set when Orca itself launched the agent);isShellProcess);hasChildProcesses.Why the predicate stops where it does
A restart notice makes the pane's
onDatahandler return early (isCodexPaneStale,pty-connection.ts:819), so every keystroke is dropped while a notice exists. A false positive is a dead keyboard, which is worse than the bug being fixed. Conditions 2 and 3 are what keep that from happening: a user who exits Codex is back at a shell prompt, the foreground is the shell, and the pane is not marked. That negative case is tested explicitly and mutation-proved in both directions.Known residual gaps, stated plainly:
git login a pager) would be marked. It needs a full process-chain from the inspection API to distinguish, which would mean changing main, the daemon, and the remote-runtime RPC. Out of scope here.codex(nolaunchAgent) running a subagent on Windows still reads as the child and is not eligible. Same root cause, same fix needed.Mutation proof
Every new test was mutation-proved by reverting the production change and confirming the test fails.
codex-pane-restart-eligibility.test.ts+marks a launcher-started Codex pane whose deepest process is a subagentdoes not re-prompt a pane that already got its noticeshouldRetryscoping (retry everything)stops retrying a pane the registry reports as not stalenotifyCodexPaneBoundForStaleSweepfrom the bind chokepointbinds a fresh spawn that resolves as a daemon reattachOne honest miss: removing the
flushTimer !== nullre-entrancy guard fails nothing. The shared queue makes it behaviorally equivalent for every covered scenario — the guard only prevents orphaned timers, not duplicate sweeps. It is kept for that reason, not asserted.Gates
All green:
vitest run --config config/vitest.config.tsover the Codex suites +pty-connection.test.ts: 42 files, 1108 passed, 5 skipped. New files are 51 / 105 / 136 lines — nomax-linessuppression added anywhere.What I could NOT verify
pwsh -> node -> codex.exe -> claude.exeon macOS and did not fake it. The predicate is written to be unit-testable from an injected inspection result plus tab metadata, and is tested against the measured Windows shape as data. The real-Windows end-to-end run is still needed.Closes nothing on its own — this unblocks #10770's fix 3.