Skip to content

fix(codex): sweep stale panes on real PTY binds and stop filtering out launcher panes - #10803

Merged
brennanb2025 merged 6 commits into
brennanb2025/fix-codex-account-switchfrom
brennanb2025/codex-sweep-bind-and-foreground
Jul 27, 2026
Merged

brennanb2025 merged 6 commits into
brennanb2025/fix-codex-account-switchfrom
brennanb2025/codex-sweep-bind-and-foreground

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

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 of pty: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 and listStalePanes did 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 (bindActivePanePty and 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.ts owns 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:

  • Coalesced — a burst of startup binds becomes one sweep. The short first delay also lets updateTabPtyId land, since the scan walks tabs to reach launchAgent.
  • Bounded retry, scoped — only an unusable process read, or a Codex tab still showing its shell mid-reattach, is retried, on a 3-step ladder (300 / 1500 / 4000 ms) and then dropped. An authoritative "not stale" from the registry stops immediately. Never a polling loop.
  • Never re-fires — a pane that has been notified is never queued again, on top of fix(codex): keep history, restarts, and account identity across an account switch #10770's existing rule that dismissing drops the on-disk record so listStalePanes stops 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 only codex and codex-*. Windows reports the deepest process in the tree. Measured in the same app at the same instant:

pane tree foreground before
plain shell, user typed codex pwsh -> codex.exe codex card appears
Orca "Codex" launcher pane pwsh -> node -> codex.exe -> claude.exe claude no card ever

Any 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 affects markLiveCodexSessionsForRestart) 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:

  1. the tab's launchAgent === 'codex' — recorded metadata, not a repaintable label (the existing comment in codex-session-restart.ts explains why tab titles are unreliable; this is a different, stronger signal, and launchAgent is only set when Orca itself launched the agent);
  2. the foreground is not a shell (isShellProcess);
  3. hasChildProcesses.

Why the predicate stops where it does

A restart notice makes the pane's onData handler 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:

  • A pane that launched Codex, was exited, and is now running some other long-lived child (git log in 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.
  • A manually-typed codex (no launchAgent) 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.

mutation result
Revert the predicate to codex-only (pre-fix) 3 fail — the two launcher-pane cases in codex-pane-restart-eligibility.test.ts + marks a launcher-started Codex pane whose deepest process is a subagent
Over-widen the predicate (drop the shell/child guard) 4 fail — the exited-to-prompt negatives in all three suites
Remove the retry ladder (single attempt) 4 fail
Remove the already-notified guard 1 fail — does not re-prompt a pane that already got its notice
Remove the shouldRetry scoping (retry everything) 1 fail — stops retrying a pane the registry reports as not stale
Remove notifyCodexPaneBoundForStaleSweep from the bind chokepoint 1 fail — binds a fresh spawn that resolves as a daemon reattach

One honest miss: removing the flushTimer !== null re-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:

npx tsc --noEmit -p config/tsconfig.node.json      exit 0
npx tsc --noEmit -p config/tsconfig.tc.cli.json    exit 0
npx tsc --noEmit -p config/tsconfig.tc.web.json    exit 0
npx oxlint                                          exit 0
node config/scripts/check-max-lines-ratchet.mjs     exit 0 (no new bypasses)
npx oxfmt --check <changed>                         clean

vitest run --config config/vitest.config.ts over the Codex suites + pty-connection.test.ts: 42 files, 1108 passed, 5 skipped. New files are 51 / 105 / 136 lines — no max-lines suppression added anywhere.

What I could NOT verify

  • The Windows process-tree shape. I cannot reproduce pwsh -> node -> codex.exe -> claude.exe on 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.
  • Real quit/relaunch timing. Whether 300 / 1500 / 4000 ms is enough for a slow Windows daemon reattach is unproven on hardware. If a pane loses the race the ladder simply exhausts and no card appears — a miss, never a dead keyboard.
  • Acceptance criteria 1–5 are covered by unit tests against injected state, not by a live app run on the reporter's platform.

Closes nothing on its own — this unblocks #10770's fix 3.

…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
brennanb2025 merged commit 74e6478 into brennanb2025/fix-codex-account-switch Jul 27, 2026
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.
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