Skip to content

fix(codex): keep a dismissed restart notice from killing the pane's keyboard - #10802

Merged
brennanb2025 merged 5 commits into
brennanb2025/fix-codex-account-switchfrom
brennanb2025/codex-notice-dismissed-state
Jul 27, 2026
Merged

brennanb2025 merged 5 commits into
brennanb2025/fix-codex-account-switchfrom
brennanb2025/codex-notice-dismissed-state

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #10770 — base is brennanb2025/fix-codex-account-switch, not main.

Root cause

isCodexPaneStale (pty-connection.ts:819, consumed at the pane's onData handler) treats any Codex restart notice on a pty as "stale" and makes the handler return early — while a notice exists, every keystroke in that pane is silently dropped. That's deliberate: don't let work run under the wrong account. But it means any wrong notice state is a terminal that ignores typing.

Dismissing the prompt ("Keep old account") called clearCodexRestartNotice, which deletes the notice record. previousAccountLabel on that record is the renderer's only memory of the account the pane actually launched under, and it's what markCodexRestartNotices uses for its A → B → A collapse (terminals.ts, "a live Codex pane keeps its original launch account until it actually restarts"). With the record gone, re-selecting the pane's original account A read as a fresh switch:

markCodexRestartNotices({ previous: B, next: A })
  existing = undefined                     // record was deleted by the dismissal
  previousAccountLabel = B                 // falls back to the caller's value
  B !== A  ->  no collapse
  -> notice { previous: B, next: A }       // inverted, and false

The prompt then reads "Codex is still signed in as B. Restart this session to use A" with the labels backwards, and — because a notice exists — the pane's keyboard goes dead.

Verified myself, and confirmed pre-existing on origin/main. I did not take the report on faith: I wrote the repro against the store before touching anything and watched it produce {previousAccountLabel: "[email protected]", nextAccountLabel: "[email protected]"}. origin/main (fd7ebe3) carries a byte-identical markCodexRestartNotices collapse, a byte-identical clearCodexRestartNotice, and a byte-identical isCodexPaneStale, so the bug reproduces there too. #10770 does not introduce it — its startup sweep, which re-raises notices at launch, makes wrong notice state much more reachable.

The fix

A dismissed?: true marker on CodexRestartNotice, so a dismissal is remembered rather than erasing the pane's launch-account memory. New store action dismissCodexRestartNotices(ptyIds) marks instead of deleting.

clearCodexRestartNotice is deliberately left alone: its other caller (TerminalPane.tsx:1596) fires when the pane actually relaunches, and there the record must genuinely die — the pane now runs under the new account, so its launch memory has to reset. Conflating the two would suppress a legitimate later prompt. There's a regression test for exactly that.

Two shared predicates in the new codex-restart-notice-state.ts keep the asymmetry between the two answered states in one place, honoured by every consumer:

restartRequested dismissed
Prompt shown no no
Pane input blocked yes no

Justification for the input gate. restartRequested means the user asked for a restart but the pane hasn't relaunched yet — it is still running under the old account, so letting keystrokes through would run work under the wrong account, which is the entire reason the gate exists. dismissed means the user explicitly chose to keep that account: there is no wrong-account hazard left, and leaving the terminal dead would punish them for answering the prompt. A dismissal that kills the keyboard is the worst possible outcome, so the keyboard comes back immediately.

Consumers updated: isCodexPaneStale (both the live-pty path and the tab-id reconnect fallback), collectStalePtyIdsForTabs (CodexRestartChip.tsx), summarizeCodexRestartStatus (status bar), plus selectCodexRestartInputs — that selector gated on "any notice exists", which would now leave every mounted chip permanently subscribed to pty-lifecycle churn after a single dismissal, so it gates on "any unanswered notice" instead.

A dismissal is not carried across a later switch. It answered "keep A instead of B", which says nothing about a later C. Switching to a genuinely different third account rebuilds the notice as {previous: A, next: C} — correct labels, taken from the surviving launch memory — and prompts. Over-suppressing here would silently strand the pane on A. (restartRequested is carried over, since a queued restart relaunches under whatever is selected when it runs; that behaviour is unchanged.)

Durability across app restart composes with #10770 rather than duplicating it. The two layers are doing different jobs: the renderer marker is in-session memory and the input unblock; codexAccounts:forgetStalePanes drops the on-disk launch record so the startup sweep doesn't re-raise. Dismissal still calls both. No change to the main-process registry.

Mutation proof

Five targeted mutations, each reverting one part of the fix and re-running. Every one produced failures — no test passes with or without the production change:

# Mutation Result
1 blocksCodexPaneInput ignores dismissed 2 failed — both input-gate tests (live-pty path + tab fallback)
2 awaitsCodexRestartAnswer ignores dismissed 5 failed — across all three consumers + the selector
3 markCodexRestartNotices carries dismissed forward (over-suppression) 2 failed — both third-account tests
4 dismissCodexRestartNotices deletes the record (the original bug) 7 failed — including the acceptance-2 repro
5 blocksCodexPaneInput also excludes restartRequested 1 failed — the asymmetry test

Mutation 5 matters: it proves the "restart requested still blocks input" test is discriminating rather than passing incidentally.

Acceptance

  1. Dismiss → keyboard works again immediately — covered by the two pty-connection input-gate tests (mutation 1).
  2. Dismiss → re-select the pane's original account → no prompt, keyboard alive — covered at the store level and end-to-end through the rendered chip (mutation 4).
  3. Dismiss → switch to a genuinely different third account → prompt does appear, with the launch account in the label — covered at both levels (mutation 3).
  4. Quit/relaunch after a dismiss → no re-prompt — unchanged fix(codex): keep history, restarts, and account identity across an account switch #10770 behaviour, already covered by codex-stale-pane-accounts.test.ts ("stops reporting a pane the user chose to keep"), which uses a discriminating second pane; the chip test asserts forgetStalePanes is still called on dismiss.
  5. Every new test mutation-proved, as above.

Gates

All run and clean: tsc × 3 (node, tc.cli, tc.web), oxlint (exit 0, no warnings in touched files), check-max-lines-ratchet (no new bypasses, no max-lines disables added). Targeted suites 523 passed; wider sweep of components/status-bar, components/terminal-pane, store/, main/codex — 5529 passed, 0 failed.

Not verified

  • No live app QA. This is store + component-level verification only; I did not drive a real Codex account switch in the running app.
  • Cross-platform: the change is platform-neutral renderer state (no path handling, no key modifiers), so nothing here is macOS/Linux/Windows-specific, but it was only exercised on macOS.
  • Pre-existing, not touched, flagged for follow-up: because forgetStalePanes deletes the on-disk launch record outright, a pane that was dismissed and then survives an app restart has no launch-account memory on disk. A later switch in the new session will prompt it with whatever account was active at that moment as previousAccountLabel, which may not be the account it truly launched under. The prompt itself is still correct — the pane genuinely is stale — only the label can be wrong. Fixing that means teaching the main-process registry about dismissal instead of forgetting, which is fix(codex): keep history, restarts, and account identity across an account switch #10770's contract and out of scope here.

Review addendum (independent review, 4 rounds)

Four rounds of independent review ran against this branch; rounds 1–3 each found real defects, round 4 came back clean. Five commits were added on top of the original fix. Every fix below was mutation-proved twice — once by the agent that wrote it, once independently re-run by the reviewer (revert the production hunk → confirm the new test fails → restore → confirm it passes).

# Commit Defect Mutation proof
D1 f01251a6da isCodexPaneStale fell through to the tab-level check even when the pane's own record was dismissed. In a split tab, a dismissed pane beside a sibling holding a blocking notice kept a dead keyboard with no prompt — the exact outcome this PR exists to prevent. revert → split-pane test fails (sendInput 0 calls)
D2 f01251a6da queueCodexPaneRestarts did not strip dismissed while dismissCodexRestartNotices stripped restartRequested. {dismissed, restartRequested} resolved as "dismissed wins" → input flowing in a pane with a restart queued, still on the old account. Unreachable via today's UI (both call sites filter through awaitsCodexRestartAnswer); landed as a state-model invariant, not a live bug. revert → lifecycle test fails
D3 2e9f584a93 A bound pane with no record of its own still inherited tab.ptyId's block. Worst case: a plain shell split beside a Codex pane whose restart was already requested — the prompt is off-screen (awaitsCodexRestartAnswer false), so an innocent pane went silently mute with nothing to answer. The tab.ptyId fallback now runs only when panePtyId is null. revert → bound-pane test fails; both null-binding fallback tests pass in both runs, proving the unbound protection is untouched
D4 e576362f58 Introduced by this PR. markCodexRestartNotices dropped dismissed on every re-mark. AccountsPane.tsx re-marks live panes with the selection unchanged for adding (unconditional) and reauth:<activeId>, and the A→B→A collapse does not fire (it compares existing.previousAccountLabel, still A, against next: B). So routine token reauth resurrected an answered prompt and re-muted the pane. dismissed now carries forward iff existing.nextAccountLabel === notice.nextAccountLabel. revert → 1 fails; make it unconditional → 2 third-account over-suppression tests fail. Discriminating in both directions
— 841c7882a8 Two comments added by this PR onto the input gate were factually wrong (tab.ptyId is the first binder, not the last; unbound-pane recovery targets ptyIdsByTabId[tabId][0], not tab.ptyId). Comments only — the reasoning the fixes rest on ("some sibling's id, not this pane's") is unchanged. n/a

Correction to the original description above

"A dismissal is not carried across a later switch."

This is now only true for a genuinely different target account. D4 changed it: a dismissal is carried forward when the incoming target equals the one the dismissal already answered, so adding an account or reauthing the active one cannot resurrect it. A real third account C still reopens the prompt, and the A→B→A collapse still runs first and deletes the record outright.

Verified state-model invariant

{dismissed, restartRequested} is unreachable, re-derived after D4 across all four writers of the map: dismiss strips restartRequested; queue strips dismissed; mark only ever propagates flags from existing, so it cannot manufacture the pair from a single-flag record; the setTabPtyId migration copies verbatim. This matters because that shape would let input flow in a pane still on the old account.

Gates

npm run typecheck exit 0 (all 3 projects) · oxlint exit 0 · 513 passed across the 5 touched suites · 2231 passed across all of store/ + status-bar/ · no max-lines disables added (the two in the touched files are pre-existing on main).

Not verified

  • No live-app QA anywhere in the review — source reading plus vitest only.
  • Nothing exercised on Windows, though [Bug] CHAT HISTORY LOST AFTER ACCOUNT SWITCH !!!! #10757's reporter is on Windows. The diff is platform-neutral renderer state (no path handling, no key modifiers, no git), but Windows foreground-process detection in getLiveCodexSessionPtyIds — the gate on whether a pane gets a notice at all — was not verified.
  • The startup-sweep race was reasoned from call ordering, not reproduced.

Scope note on #10757

This PR owns the "Keep old account" half only. Lost /resume history is PR #10801's territory and is not addressed here; the stuck restart panel and the across-restart stranding are largely base PR #10770 (ed40982db0, 1818553aa6). Reading this PR as closing #10757 on its own would be wrong.

Follow-ups (out of scope, not committed)

  1. Reauth of the active account never prompts anyone. The previousAccountLabel === nextAccountLabel collapse swallows the reauth:<active> mark for panes with no existing record, so a pane on a stale token is never offered a restart even though shouldPromptRestart intends it. Pre-existing on base; shares a root cause with D4.
  2. Dismissal permanently forgets the on-disk launch account. forgetStalePanes deletes the registry entry and only PTY spawn re-records it, so a dismissed pane that later switches to a third account and survives an app restart may be mislabelled — or not surfaced at all. fix(codex): keep history, restarts, and account identity across an account switch #10770's contract.
  3. A restartRequested pane whose restart never runs (tab parked indefinitely) stays input-blocked with no prompt on screen and no way to reopen it — both surfaces filter restartRequested out. Pre-existing on base.
  4. Detection failures now fail open. A bound pane with no record is never blocked, so a genuinely-stale pane whose foreground-process inspection failed at switch time is no longer blocked by accident via a sibling. Correct trade against a guaranteed dead keyboard, but worth writing down.

…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.
@brennanb2025
brennanb2025 merged commit 34e179e 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