Skip to content

fix(codex): keep a host account switch inside the host lane - #10992

Merged
brennanb2025 merged 8 commits into
mainfrom
brennanb2025/codex-host-switch-lane-guard
Jul 28, 2026
Merged

brennanb2025 merged 8 commits into
mainfrom
brennanb2025/codex-host-switch-lane-guard

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Stacked on #10770.

The bug

markLiveCodexSessionsForRestart walked tabsByWorktree → ptyIdsByTabId and inspected every PTY, carding any pane whose foreground looked like Codex. There was no lane check anywhere in that path — the only filter was ptyIdFilter, an explicit id set used by the sweep. inspectRuntimeTerminalProcess routes remote: ids over RPC by design, so remote panes flowed straight through.

A restart notice mutes the pane (isCodexPaneStale), so a host account switch made the user's live SSH terminal go deaf.

It was provably spurious. A remote spawn carries a connectionId, so isDaemonHostSpawn is false (pty.ts:3214, 4285), so selectedCodexHomePath stays null and no CODEX_HOME is injected. Managed Codex accounts are managedHomeRuntime?: 'host' | 'wsl' — there is no ssh runtime. The remote Codex reads the remote machine's own credentials; the host selection cannot affect it.

The fix

Scope marking by lane, where a pane's lane is (machine, runtime):

lane key pane
host local daemon/host spawn
wsl:<distro> local WSL pane, per-distro
env:<id> relay runtime environment pane
ssh-connection SSH-connection pane — no managed selection can ever name it

The switch's own lane comes from the same vocabulary, so the match is plain equality. Both call sites (AccountsPane, StatusBar) already knew which runtime slot they wrote; they now pass it.

A switch made while a runtime environment is active is RPC'd to that machine's roster, so it keys to env:<id> and still cards that environment's panes. That is the case that made the old "mark everything" behaviour look correct, and it is preserved.

The lane check runs before inspection, not after: an out-of-lane answer cannot change the outcome, and each remote look costs a 15s-timeout RPC.

BUG 2 (WSL): confirmed, not incidental — and fixed here

The prior Windows validation saw a WSL pane correctly get no card on a host switch, but only because its foreground read wsl.exe, which fails the Codex-foreground test. That is an accident of WSL2 process isolation — the Win32 process table cannot see into the VM, so the deepest visible process is wsl.exe.

Probed the eligibility predicate directly:

{"wsl.exe":false,"wsl":false,"node":true,"codex":true,"python3":true,"claude.exe":true}

So any WSL pane whose foreground surfaces codex, node, python3 or another recognized agent would be carded by a host switch. WSL1 pico-processes are visible in Win32_Process, and isCodexRestartEligiblePane's launchAgent === 'codex' fallback accepts wrapper foregrounds outright. The lane is now what decides, and the test pins the lane rather than the accident.

BUG 3: wasted remote RPC

recordCodexPaneAccountForSpawn bails on !isDaemonHostSpawn, so remote PTYs are never written to the pane-account registry and listStaleCodexPanes can never report one stale. Yet the sweep still queued and inspected them on every rung. #10853 widened the ladder from 3 rungs to 5, taking guaranteed-fruitless remote RPC from ~45s to ~75s per pane.

notifyCodexPaneBoundForStaleSweep now rejects them at the door. The test asserts vi.getTimerCount() === 0 immediately after the bind — the scan would skip them anyway, so only an unarmed queue proves they were never queued rather than merely skipped later.

Design note

I kept two paths rather than routing switch-time marking through listStalePanes. Doing that would fix all three bugs at once, but panes with no registry record — anything spawned before this feature shipped, plus every LocalPtyProvider pane, which is also not a daemon host spawn — would stop being carded entirely. The lane check is instead explicit and shared: one resolver, used by both paths, and the lane vocabulary moved to shared/ so the renderer keys panes exactly as a launch does instead of growing a third copy of the rules (StatusBar already had a second).

I also dropped an outOfLane field + shouldRetry clause I had added: with the queue guard in place they were provably unreachable, and the skipped scan result already carries terminal not-retryable semantics.

Tests

24 new tests. Every one mutation-proved — reverted the production change and confirmed the new test fails:

mutation new tests killed
scan lane filter disabled 6
sweep queue guard removed 3
local lane key never matches 5 + all 3 positive controls
foreign-lane branches disabled 5
env switch key + foreign predicate neutered 8
lane key collapsed to host 4

The positive controls (a local host pane still cards; a WSL pane cards on its own distro switch; local panes still sweep alongside a remote one) are the regression that would matter most, so they are proved against over-aggressive filtering rather than against removal.

Gates

  • 3× tsc (node, tc.cli, tc.web) — clean
  • oxlint exit 0; switch-exhaustiveness clean; max-lines ratchet OK (no disables added, nothing extracted needed)
  • oxfmt clean
  • 940 tests across src/main/codex + the four Codex renderer suites — pass
  • 1172 tests across src/main/codex-accounts, settings, status-bar, restart-notice lifecycle — pass
  • 2651 tests across src/main/rate-limits + src/main/ipc (every importer of the moved module) — pass

Not run: live SSH/relay QA. The repro was Brennan's; this lands the guard the two independent reproductions pointed at.

Refs #10757

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.
markLiveCodexSessionsForRestart walked every tab's PTYs and carded any pane
whose foreground looked like Codex. There was no lane check anywhere in that
path, so a host account switch raised a restart notice on live SSH/relay panes
— and a notice mutes the pane, so the user's remote terminal went deaf.

The notice was provably spurious: a remote spawn carries a connectionId, so
isDaemonHostSpawn is false and no CODEX_HOME is ever injected. The remote Codex
uses the remote machine's own credentials; a local selection cannot reach it.

Scope marking by lane instead. A pane's lane is (machine, runtime): `host`,
`wsl:<distro>`, `env:<id>` for a relay environment, or an SSH connection that
no managed selection can name. A switch made while a runtime environment is
active still cards that environment's panes, which is the case that made the
old "mark everything" behaviour look right.

WSL was the same defect, not a separate one. A Windows run saw a WSL pane
correctly escape a host switch, but only because its foreground read `wsl.exe`,
which fails the Codex-foreground test — the Win32 process table cannot see into
a WSL2 VM. That is incidental: `codex`, `node` and `python3` foregrounds are all
eligible today, so a WSL pane that surfaces one (WSL1 pico-processes are in
Win32_Process) would be carded by a host switch. The lane is now what decides.

Also stop queueing remote and SSH panes into the bind-driven stale sweep at all.
recordCodexPaneAccountForSpawn bails on anything that is not a daemon host
spawn, so listStalePanes can never report one stale, yet each pane still spent
every rung on a 15s-timeout remote RPC — ~75s per pane since the ladder widened
to five rungs.

The lane vocabulary moves to shared/ so the renderer keys panes exactly as a
launch does rather than growing a third copy of the rules.

Refs #10757
The lane guard derived a pane's WSL distro from the workspace UNC path alone.
A launch does not: pty.ts hands getCodexSelectionTargetForPty a third argument,
the resolved runtime's distro, so a wsl.exe pane on an ordinary Windows-path
worktree launches under `wsl:Ubuntu`. The renderer keyed that same pane
`wsl:__default__`, so the Ubuntu switch never reached it — the pane kept the old
account with no notice, which is #10757 returning by a new route on the exact
platform the issue was reported from.

Resolve the distro the way the spawn does: the project execution runtime first,
then terminalWindowsWslDistro. Both are already in renderer state.

Also match a distro-less WSL switch against the whole `wsl:` family. Two
mutations reach the renderer as `{runtime:'wsl', wslDistro:null}` while writing
concrete distro slots: selecting the system default clears EVERY wsl slot
(setSelectedCodexAccountIdForTarget), and `add` stores the distro it discovered
from the machine. Keying those to `__default__` missed the very panes they
re-pointed. The residual cost is over-marking a sibling distro after an add,
bounded to this machine's WSL panes and far cheaper than a stranded pane.

An owner-less remote pane colliding with the host lane was untested — that
collision is what would mute a working remote terminal, so pin the disjointness
rather than the literal key.

Refs #10757
Three more places where the renderer's lane and the launch's lane disagreed.
Each disagreement is silent: too narrow and a stranded pane never gets its
notice (#10757 returns), too wide and a healthy pane is muted, because a notice
makes onData drop every keystroke.

Shell: main runs the request through resolveLocalWindowsTerminalRuntimeOptions,
so an unset shellOverride still lands on WSL when that is the Windows default.
Reading tab.shellOverride alone called such a pane `host` — a host switch would
have muted a working WSL terminal. Gate on the renderer platform, as pty.ts
gates on process.platform.

Cwd: a terminal's startup cwd is deliberately not constrained to the worktree
(resolveTerminalStartupCwd, #7685), and main keys the lane off that cwd. Follow
it through the same shared call instead of reading the workspace root, so a pane
split after `cd \\wsl.localhost\...` is keyed where it actually runs. The comment
claiming a pane can never start outside its workspace was simply wrong.

Family match: narrow the previous commit. setSelectedCodexAccountIdForTarget
only nulls every WSL slot when the account is null AND no distro is named; any
other write lands in one slot. So claim the family only when the change actually
cleared them all, and let `add` pass the created account's concrete target
rather than the row's "WSL default". Both call sites already knew which case
they were in.

Refs #10757
The previous commit reached for getLocalProjectExecutionRuntimeContext as a
stand-in for main's resolveLocalProjectRuntimeForWorktreeId. They are not the
same function, and the differences both produce wrong lanes:

- It falls back to `state.activeRepoId` when the worktree is not a git worktree,
  so a folder-workspace pane inherited whichever repo happened to be selected.
  That is not a property of the pane at all — the lane moved when the sidebar
  selection moved. On a WSL project it both muted a healthy host pane and hid
  the notice a host switch owed it.
- It synthesizes a runtime from `inherit-global` where main returns undefined,
  and its host branch rewrites an explicit `wsl.exe` to powershell.exe, keying a
  live WSL pane `host`.

Walk repo -> project directly instead, which is what resolveLocalProjectRuntimeForRepo
does, and use it only to supply a distro — never to downgrade a shell. That also
drops the throwing call out of this path entirely; the lane runs outside
scanCodexPanes' inspection guard, so a throw there would have lost the notice
for every pane in the batch, not just one.

Also find the added account by diffing the roster. Reading it back through the
row's active id returns null once two distro slots are filled, which sent the
notice to `wsl:__default__` while `add` had written a concrete distro.

Refs #10757
Reverses the project-runtime half of the previous commit. That commit assumed
main resolved the project runtime itself, so it re-derived one by hand. It does
not: for a local pane the RENDERER computes it with
getLocalProjectExecutionRuntimeContext and ships it with the spawn
(pty-connection.ts), and pty.ts feeds that straight to getCodexSelectionTargetForPty.
So the helper is not an approximation to be improved on — it is the launch.

The hand walk dropped the global Windows runtime default, which is what turns an
`inherit-global` project preference into WSL. A user who set their runtime
default to WSL but left terminalWindowsShell alone would have had every live WSL
pane keyed `host`: muted by a host switch, and missed by their own. It also
disagreed on folder workspaces, where the launch really does resolve through the
active repo.

Keep the repair-required early return: that call throws, and it sits outside the
scan's per-pane failure guard, so a throw would lose the notice for every pane in
the batch rather than one.

Separately, floating terminals have no workspace root, so their startup cwd is
used verbatim (resolveTerminalStartupCwdForWorkspace). Resolving one against a
root that does not exist yielded no cwd at all, keying a floating Codex pane on
a WSL filesystem as `host`. Read its cwd directly.

Require exactly one new account before trusting the roster diff — an unloaded
prior roster makes every account look new, and Add Account is not gated on it.

Refs #10757
The floating-terminal branch read tab.startupCwd, which no floating creation
path ever sets (FloatingTerminalPanel, FloatingTerminalWindowControls,
floating-workspace-tab-creation all pass none). Its cwd is resolved over IPC
from settings.floatingTerminalCwd and handed to the transport as a prop, so it
never reaches the store at all. The branch was inert and its comment described
main's handling of args.cwd rather than what the code read.

Say what is actually true: a floating pane is keyed by its shell, and the
configured-WSL-cwd-under-a-host-shell case is a known gap. Guessing from the
unresolved setting would risk the mute direction, which is the expensive one.

Also pin the repair-required early return. resolveLocalWindowsTerminalRuntimeOptions
throws there, and the lane runs outside scanCodexPanes' per-pane failure guard,
so without it Promise.all rejects and every pane in the batch loses its notice.
That guard had no coverage; removing it now fails with the spawn error.

Refs #10757
The switch path re-derived each pane's Codex lane from current state while
main had already written the resolved shell, cwd and distro at spawn. Four
review rounds each found another divergence between the two, and the
derivation still answers for a launch that never happened once the user
edits a runtime preference.

Prefer the recorded lane where one exists; keep the derivation for the panes
main never records — pre-feature panes, LocalPtyProvider spawns and remote
ids — and log when the two disagree.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/codex-host-switch-lane-guard branch from 0eb25e9 to 88b64fa Compare July 28, 2026 01:53
@brennanb2025
brennanb2025 changed the base branch from brennanb2025/fix-codex-account-switch to main July 28, 2026 01:53
@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Codex selection targets and lane-key helpers now live in a shared module. Renderer lane resolution handles local, WSL, remote, SSH, environment, recorded, and derived pane lanes. Recorded pane lanes are exposed through registry, IPC, preload, and web APIs. Restart notifications now filter panes by affected lanes, while stale-pane sweeps exclude foreign-machine PTYs. Account action callers provide runtime and WSL scope information, with expanded tests covering lane resolution and restart behavior.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 64.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description is off-template and missing required sections like Summary, Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes. Rewrite the PR description using the repository template and fill in the required Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes sections.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately reflects the main change: keeping host switches scoped to the host lane.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a2c78482-89ef-4e18-bcff-f289c7eb35d4

📥 Commits

Reviewing files that changed from the base of the PR and between 9a8e21a and 88b64fa.

📒 Files selected for processing (15)
  • src/main/codex-accounts/runtime-selection.ts
  • src/main/codex/codex-pane-account-registry.ts
  • src/main/ipc/codex-accounts.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/renderer/src/components/settings/AccountsPane.tsx
  • src/renderer/src/components/status-bar/StatusBar.tsx
  • src/renderer/src/lib/codex-pane-selection-lane.test.ts
  • src/renderer/src/lib/codex-pane-selection-lane.ts
  • src/renderer/src/lib/codex-session-restart.test.ts
  • src/renderer/src/lib/codex-session-restart.ts
  • src/renderer/src/lib/codex-stale-pane-sweep.test.ts
  • src/renderer/src/lib/codex-stale-pane-sweep.ts
  • src/renderer/src/web/web-preload-api.ts
  • src/shared/codex-selection-lane.ts

Comment on lines +124 to +168
export function resolveCodexPaneSelectionLane(args: {
state: CodexPaneLaneState
tab: Pick<TerminalTab, 'shellOverride' | 'startupCwd' | 'worktreeId'>
ptyId: string
/** The pane's `selectionKey` from the on-disk registry, when it has one. */
recordedLaneKey?: string | null
}): CodexPaneSelectionLane {
const recorded = args.recordedLaneKey?.trim()
// Why the local-key check: the registry accepts any string it finds on disk,
// and a lane key that matches no switch silently drops that pane's notice.
// Why foreign ids still derive: their lane is settled by the id itself and no
// record can exist for one, so a hit here would mean a recycled id.
const trustsRecord =
Boolean(recorded) &&
isLocalCodexSelectionLaneKey(recorded as string) &&
!isForeignMachineCodexPtyId(args.ptyId)
if (!trustsRecord) {
const laneKey = resolveCodexPaneSelectionLaneKey(args)
return { laneKey, source: 'derived', derivedLaneKey: laneKey }
}
const derivedLaneKey = deriveLaneKeyForDiagnostics(args)
if (derivedLaneKey !== null && derivedLaneKey !== recorded) {
// Why loud: every divergence found in review was this exact disagreement,
// and the recorded key now hides it instead of producing a visible bug.
console.warn('[codex-lane] recorded launch lane disagrees with the derived one:', {
ptyId: args.ptyId,
recorded,
derived: derivedLaneKey
})
}
return { laneKey: recorded as string, source: 'recorded', derivedLaneKey }
}

/** Never let the diagnostic derivation break a pane whose lane is already known. */
function deriveLaneKeyForDiagnostics(args: {
state: CodexPaneLaneState
tab: Pick<TerminalTab, 'shellOverride' | 'startupCwd' | 'worktreeId'>
ptyId: string
}): string | null {
try {
return resolveCodexPaneSelectionLaneKey(args)
} catch {
return null
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Untrusted-branch throw risk is unguarded and untested. resolveCodexPaneSelectionLane's no-record/derived path calls resolveCodexPaneSelectionLaneKey without the try/catch protection given to the trusted-record path, and no test exercises that specific failure mode even though the file's own comments prove the underlying derivation chain can throw.

  • src/renderer/src/lib/codex-pane-selection-lane.ts#L124-L168: guard the derived-only branch (Line 140-143) by reusing deriveLaneKeyForDiagnostics and falling back to a non-matching lane key (e.g. UNATTRIBUTED_REMOTE_LANE_KEY) instead of letting the exception propagate.
  • src/renderer/src/lib/codex-pane-selection-lane.test.ts#L364-L383: add a sibling to "still answers with the record when the derivation throws" that passes no recordedLaneKey with an exploding state, asserting the function returns a safe fallback instead of throwing.
📍 Affects 2 files
  • src/renderer/src/lib/codex-pane-selection-lane.ts#L124-L168 (this comment)
  • src/renderer/src/lib/codex-pane-selection-lane.test.ts#L364-L383

@brennanb2025
brennanb2025 merged commit ee7ec43 into main Jul 28, 2026
41 of 65 checks passed
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.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…#10992)

* fix(codex): keep a host account switch inside the host lane

markLiveCodexSessionsForRestart walked every tab's PTYs and carded any pane
whose foreground looked like Codex. There was no lane check anywhere in that
path, so a host account switch raised a restart notice on live SSH/relay panes
— and a notice mutes the pane, so the user's remote terminal went deaf.

The notice was provably spurious: a remote spawn carries a connectionId, so
isDaemonHostSpawn is false and no CODEX_HOME is ever injected. The remote Codex
uses the remote machine's own credentials; a local selection cannot reach it.

Scope marking by lane instead. A pane's lane is (machine, runtime): `host`,
`wsl:<distro>`, `env:<id>` for a relay environment, or an SSH connection that
no managed selection can name. A switch made while a runtime environment is
active still cards that environment's panes, which is the case that made the
old "mark everything" behaviour look right.

WSL was the same defect, not a separate one. A Windows run saw a WSL pane
correctly escape a host switch, but only because its foreground read `wsl.exe`,
which fails the Codex-foreground test — the Win32 process table cannot see into
a WSL2 VM. That is incidental: `codex`, `node` and `python3` foregrounds are all
eligible today, so a WSL pane that surfaces one (WSL1 pico-processes are in
Win32_Process) would be carded by a host switch. The lane is now what decides.

Also stop queueing remote and SSH panes into the bind-driven stale sweep at all.
recordCodexPaneAccountForSpawn bails on anything that is not a daemon host
spawn, so listStalePanes can never report one stale, yet each pane still spent
every rung on a 15s-timeout remote RPC — ~75s per pane since the ladder widened
to five rungs.

The lane vocabulary moves to shared/ so the renderer keys panes exactly as a
launch does rather than growing a third copy of the rules.

Refs stablyai#10757

* fix(codex): key a WSL pane by the distro its launch actually used

The lane guard derived a pane's WSL distro from the workspace UNC path alone.
A launch does not: pty.ts hands getCodexSelectionTargetForPty a third argument,
the resolved runtime's distro, so a wsl.exe pane on an ordinary Windows-path
worktree launches under `wsl:Ubuntu`. The renderer keyed that same pane
`wsl:__default__`, so the Ubuntu switch never reached it — the pane kept the old
account with no notice, which is stablyai#10757 returning by a new route on the exact
platform the issue was reported from.

Resolve the distro the way the spawn does: the project execution runtime first,
then terminalWindowsWslDistro. Both are already in renderer state.

Also match a distro-less WSL switch against the whole `wsl:` family. Two
mutations reach the renderer as `{runtime:'wsl', wslDistro:null}` while writing
concrete distro slots: selecting the system default clears EVERY wsl slot
(setSelectedCodexAccountIdForTarget), and `add` stores the distro it discovered
from the machine. Keying those to `__default__` missed the very panes they
re-pointed. The residual cost is over-marking a sibling distro after an add,
bounded to this machine's WSL panes and far cheaper than a stranded pane.

An owner-less remote pane colliding with the host lane was untested — that
collision is what would mute a working remote terminal, so pin the disjointness
rather than the literal key.

Refs stablyai#10757

* fix(codex): resolve a pane's lane the way its launch resolved it

Three more places where the renderer's lane and the launch's lane disagreed.
Each disagreement is silent: too narrow and a stranded pane never gets its
notice (stablyai#10757 returns), too wide and a healthy pane is muted, because a notice
makes onData drop every keystroke.

Shell: main runs the request through resolveLocalWindowsTerminalRuntimeOptions,
so an unset shellOverride still lands on WSL when that is the Windows default.
Reading tab.shellOverride alone called such a pane `host` — a host switch would
have muted a working WSL terminal. Gate on the renderer platform, as pty.ts
gates on process.platform.

Cwd: a terminal's startup cwd is deliberately not constrained to the worktree
(resolveTerminalStartupCwd, stablyai#7685), and main keys the lane off that cwd. Follow
it through the same shared call instead of reading the workspace root, so a pane
split after `cd \\wsl.localhost\...` is keyed where it actually runs. The comment
claiming a pane can never start outside its workspace was simply wrong.

Family match: narrow the previous commit. setSelectedCodexAccountIdForTarget
only nulls every WSL slot when the account is null AND no distro is named; any
other write lands in one slot. So claim the family only when the change actually
cleared them all, and let `add` pass the created account's concrete target
rather than the row's "WSL default". Both call sites already knew which case
they were in.

Refs stablyai#10757

* fix(codex): derive the pane's project runtime the way main does

The previous commit reached for getLocalProjectExecutionRuntimeContext as a
stand-in for main's resolveLocalProjectRuntimeForWorktreeId. They are not the
same function, and the differences both produce wrong lanes:

- It falls back to `state.activeRepoId` when the worktree is not a git worktree,
  so a folder-workspace pane inherited whichever repo happened to be selected.
  That is not a property of the pane at all — the lane moved when the sidebar
  selection moved. On a WSL project it both muted a healthy host pane and hid
  the notice a host switch owed it.
- It synthesizes a runtime from `inherit-global` where main returns undefined,
  and its host branch rewrites an explicit `wsl.exe` to powershell.exe, keying a
  live WSL pane `host`.

Walk repo -> project directly instead, which is what resolveLocalProjectRuntimeForRepo
does, and use it only to supply a distro — never to downgrade a shell. That also
drops the throwing call out of this path entirely; the lane runs outside
scanCodexPanes' inspection guard, so a throw there would have lost the notice
for every pane in the batch, not just one.

Also find the added account by diffing the roster. Reading it back through the
row's active id returns null once two distro slots are filled, which sent the
notice to `wsl:__default__` while `add` had written a concrete distro.

Refs stablyai#10757

* fix(codex): key the lane off the runtime the renderer actually shipped

Reverses the project-runtime half of the previous commit. That commit assumed
main resolved the project runtime itself, so it re-derived one by hand. It does
not: for a local pane the RENDERER computes it with
getLocalProjectExecutionRuntimeContext and ships it with the spawn
(pty-connection.ts), and pty.ts feeds that straight to getCodexSelectionTargetForPty.
So the helper is not an approximation to be improved on — it is the launch.

The hand walk dropped the global Windows runtime default, which is what turns an
`inherit-global` project preference into WSL. A user who set their runtime
default to WSL but left terminalWindowsShell alone would have had every live WSL
pane keyed `host`: muted by a host switch, and missed by their own. It also
disagreed on folder workspaces, where the launch really does resolve through the
active repo.

Keep the repair-required early return: that call throws, and it sits outside the
scan's per-pane failure guard, so a throw would lose the notice for every pane in
the batch rather than one.

Separately, floating terminals have no workspace root, so their startup cwd is
used verbatim (resolveTerminalStartupCwdForWorkspace). Resolving one against a
root that does not exist yielded no cwd at all, keying a floating Codex pane on
a WSL filesystem as `host`. Read its cwd directly.

Require exactly one new account before trusting the roster diff — an unloaded
prior roster makes every account look new, and Add Account is not gated on it.

Refs stablyai#10757

* fix(codex): stop claiming a floating-terminal cwd the tab never has

The floating-terminal branch read tab.startupCwd, which no floating creation
path ever sets (FloatingTerminalPanel, FloatingTerminalWindowControls,
floating-workspace-tab-creation all pass none). Its cwd is resolved over IPC
from settings.floatingTerminalCwd and handed to the transport as a prop, so it
never reaches the store at all. The branch was inert and its comment described
main's handling of args.cwd rather than what the code read.

Say what is actually true: a floating pane is keyed by its shell, and the
configured-WSL-cwd-under-a-host-shell case is a known gap. Guessing from the
unresolved setting would risk the mute direction, which is the expensive one.

Also pin the repair-required early return. resolveLocalWindowsTerminalRuntimeOptions
throws there, and the lane runs outside scanCodexPanes' per-pane failure guard,
so without it Promise.all rejects and every pane in the batch loses its notice.
That guard had no coverage; removing it now fails with the spawn error.

Refs stablyai#10757

* fix(codex): trust the lane main recorded at spawn over a re-derived one

The switch path re-derived each pane's Codex lane from current state while
main had already written the resolved shell, cwd and distro at spawn. Four
review rounds each found another divergence between the two, and the
derivation still answers for a launch that never happened once the user
edits a runtime preference.

Prefer the recorded lane where one exists; keep the derivation for the panes
main never records — pre-feature panes, LocalPtyProvider spawns and remote
ids — and log when the two disagree.

* refactor(codex): drop a redundant guard around the recorded-lane lookup
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