Skip to content

fix(codex): keep Codex history across WSL account switches - #34968

Merged
nwparker merged 2 commits into
mainfrom
nwparker/codex-wsl-bridge-sibling-accounts
Oct 28, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/codex-wsl-bridge-sibling-accounts

Conversation

@nwparker

@nwparker nwparker commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​160 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​160
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​32 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​25

ELI5

Orca gives each managed Codex account its own Codex folder (CODEX_HOME) so logins never collide. To keep "switch account, keep your conversations" working, Orca links session files between those folders. On WSL, a launch only linked the distro's own ~/.codex into the selected account, so a conversation started on account A disappeared from /resume after switching to account B. This PR also links the other WSL accounts in the same distro, so history follows the user across WSL account switches again.

What Changed

  • startWslSessionBridgeForLaunch (runtime-home-service-managed-home.ts) now bridges the distro's system home plus every other managed WSL account home in the same distro into the selected account's home. Before, it bridged only the system home.
    • The selected home itself and duplicates are skipped by comparing Linux paths.
    • Accounts from other distros are excluded: getWslLaunchCodexHomePath returns null for them.
    • Sources run one at a time through the existing startWslCodexSessionBridgeInBackground. The bridge script, its per-target dedupe, the index-ready gate and the index heal are unchanged.
  • Test: a regression test that a WSL launch on account B bridges both the system home and sibling account A, and skips the Debian account. It fails on main. I dropped one assertion from the retired-session test: it required a retired session not to reach the selected sibling home, which is exactly the cross-account isolation this PR reverts to the fix(codex): keep history, restarts, and account identity across an account switch #10770 behavior.

This is the WSL half of #33578. The host "system default" half is a separate draft PR, because it changes behavior for every non-WSL user and needs a product decision.

Why

The host per-account launch already uses ~/.codex plus every sibling account home as sources (getSelfContainedSessionBridgeSourceHomes). The WSL launch lost that after the WSL direct-home cutover (#16854), which caused #18486. Reusing the existing per-source WSL bridge keeps the change small. I considered teaching the bridge script to take several sources in one wsl.exe run, but that script is shared with migration and backfill, and its single-source summary drives marker and index-heal bookkeeping. Changing it would be a much larger and riskier diff than this fix needs.

Cost: each WSL Codex launch now runs one bridge per source instead of one: the system home plus each sibling WSL account in that distro. With the typical 1–3 WSL accounts, that is 0–2 extra short wsl.exe runs, each one a find over the source's sessions folder. A Codex thread/read index heal follows only when something new was linked. It all runs in the background after launch preparation and never blocks the pane.

Stopped distros (E9): this never starts a stopped distro. The bridge runs only from finishWslLaunchPreparation, which is reached only from prepareForCodexLaunch for a WSL target. That is a Codex launch (terminal pane, chat or commit-message generation) that starts Codex in that distro anyway. No startup, background, polling or discovery path calls it.

Linked Issue

Fixes #18486. Split from #33578.

Visual Proof

N/A. This is internal launch preparation and changes no UI. #33578 has a real Windows/WSL check with pinned Codex 0.164.0: on main, codex exec resume <id> from account B fails with "no rollout found"; with this change it resumes from a hardlink of account A's rollout.

Testing

  • pnpm tc and pnpm run typecheck:ci pass.
  • pnpm exec oxlint src/main/codex-accounts passes, and so do the anti-slop lint, the ast-grep gates, check:process-host-imports and check:code-quality:changed.
  • src/main/codex-accounts/ plus src/main/codex/wsl-codex-session-bridge.test.ts pass: 470 tests. One unrelated real-home catalog test timed out once under full-suite load and passed on reruns.
  • Not covered, as in fix(codex): keep Codex history across account switches on WSL and system default #33578: the WSL lane links files without healing Codex's thread index for older bridged threads, so codex resume <id> works but the picker's indexed-only view may not list them.

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Windows/WSL only (process.platform === 'win32' guard). macOS, Linux, native Windows and SSH are unchanged. No wire, settings or dependency change.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The WSL launch bridge now uses the system home and eligible managed-account homes as session-history sources for the selected home. It excludes sources with the same normalized Linux path as the target, removes duplicates, and awaits each bridge sequentially. A test covers bridging from the WSL system home and a same-distro sibling account, while excluding an account from another distro.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Low · up to 7875c

Switching WSL Codex accounts now restores session history from the system home and sibling accounts in the same distro. Linking of sibling sessions can be delayed when an earlier source has a slow index gate or heal. Launch is not blocked. A new test also uses paths that would fail if run on a Windows host. Neither issue blocks the fix itself, but both are worth addressing.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly identifies the main change: preserving Codex history when users switch between WSL accounts.
Description check Passed The description is complete and covers the user impact, implementation, rationale, linked issue, testing, scope, risks, and checklist. Visual proof is correctly marked N/A because the change has no UI…
Linked Issues check Passed The change meets #18486. For a selected WSL account, startWslSessionBridgeForLaunch uses the distro system home and sibling managed account homes as sources. It excludes the selected home and non-ma…
Out of Scope Changes check Passed The production change is limited to WSL Codex launch bridging. The tests cover sibling sources, the no-selected-account case, and concurrent launches. The change does not add host system-default behav…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Description check

Explanation

The description is complete and covers the user impact, implementation, rationale, linked issue, testing, scope, risks, and checklist. Visual proof is correctly marked N/A because the change has no UI impact. The Review and AI Disclosure sections are empty, but these omissions are non-critical.

Full details: Linked Issues check

Explanation

The change meets #18486. For a selected WSL account, startWslSessionBridgeForLaunch uses the distro system home and sibling managed account homes as sources. It excludes the selected home and non-matching distro homes. It runs one bridge per source. The regression test verifies account B receives the system home and account A sources, and the concurrency test prevents duplicate bridge loops. The existing bridge performs the session linking required for codex resume.

Full details: Out of Scope Changes check

Explanation

The production change is limited to WSL Codex launch bridging. The tests cover sibling sources, the no-selected-account case, and concurrent launches. The change does not add host system-default behavior, UI changes, dependencies, or unrelated platform behavior.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 3 files.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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: 2


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d0548e25-5771-4d07-8496-325f8d88981f
Commits

Reviewing files that changed from the base of the PR and between 9e9b545 and 6230fbc.

Files selected for processing: 2
  • src/main/codex-accounts/runtime-home-service-managed-home.ts
  • src/main/codex-accounts/runtime-home-wsl-session-bridge.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Comment on lines +266 to +268
...this.store
.getSettings()
.codexManagedAccounts.map((account) => this.getWslLaunchCodexHomePath(account, distro))

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.

Major · Data Integrity & Integration · Quick win

Supported by static analysis

Script executed:

sed -n '225,300p' src/main/codex-accounts/runtime-home-service-managed-home.ts
rg -n 'startWslSessionBridgeForLaunch' src

Repository: stablyai/orca

Length of output: 2880


Script executed:

set -o pipefail
printf '%s\n' '--- caller and routing context ---'
sed -n '1,270p' src/main/codex-accounts/runtime-home-service-home-routing.ts
printf '%s\n' '--- bridge definition and callers ---'
rg -n -F --glob '*.ts' -e 'startWslCodexSessionBridgeInBackground' -e 'type CodexAccountSelectionTarget' -e 'interface CodexAccountSelectionTarget' -e 'CodexAccountSelectionTarget' src/main/codex-accounts src/main | head -200
printf '%s\n' '--- bridge source ---'
bridge=$(rg -l -F --glob '*.ts' 'export async function startWslCodexSessionBridgeInBackground' src/main || true)
if [ -n "$bridge" ]; then
  printf '%s\n' "$bridge"
  sed -n '1,280p' "$bridge"
else
  rg -n -F --glob '*.ts' 'startWslCodexSessionBridgeInBackground' src/main
fi

Repository: stablyai/orca

Length of output: 39685


Script executed:

set -o pipefail
printf '%s\n' '--- caller ---'
sed -n '1,270p' src/main/codex-accounts/runtime-home-service-home-routing.ts
printf '%s\n' '--- bridge references ---'
rg -n -F --glob '*.ts' -e 'startWslCodexSessionBridgeInBackground' -e 'CodexAccountSelectionTarget' src/main/codex-accounts src/main | head -240
printf '%s\n' '--- bridge implementation ---'
rg -l -F --glob '*.ts' 'export async function startWslCodexSessionBridgeInBackground' src/main | while IFS= read -r f; do
  printf '%s\n' "$f"
  sed -n '1,300p' "$f"
done

Repository: stablyai/orca

Length of output: 38487


Script executed:

set -o pipefail
printf '%s\n' '--- WSL home selection ---'
nl -ba src/main/codex-accounts/runtime-home-service-wsl.ts | sed -n '1,230p'
printf '%s\n' '--- launch orchestration ---'
nl -ba src/main/codex-accounts/runtime-home-service-launch.ts | sed -n '1,150p'
printf '%s\n' '--- bridge implementation ---'
nl -ba src/main/codex/wsl-codex-session-bridge.ts | sed -n '1,190p'
printf '%s\n' '--- focused tests and relevant line ranges ---'
nl -ba src/main/codex-accounts/runtime-home-wsl-session-bridge.test.ts | sed -n '1,430p'

Repository: stablyai/orca

Length of output: 42634


Script executed:

set -o pipefail
printf '%s\n' '--- WSL home selection ---'
nl -ba src/main/codex-accounts/runtime-home-service-wsl.ts | sed -n '1,230p'
printf '%s\n' '--- launch orchestration ---'
nl -ba src/main/codex-accounts/runtime-home-service-launch.ts | sed -n '1,150p'
printf '%s\n' '--- bridge implementation ---'
nl -ba src/main/codex/wsl-codex-session-bridge.ts | sed -n '1,190p'
printf '%s\n' '--- focused tests ---'
nl -ba src/main/codex-accounts/runtime-home-wsl-session-bridge.test.ts | sed -n '1,430p'

Repository: stablyai/orca

Length of output: 42609


Script executed:

set -o pipefail
printf '%s\n' '--- remaining bridge implementation ---'
nl -ba src/main/codex/wsl-codex-session-bridge.ts | sed -n '187,430p'
printf '%s\n' '--- bridge shell script ---'
nl -ba src/main/codex/wsl-codex-session-bridge-script.ts | sed -n '1,320p'
printf '%s\n' '--- source-path helper references ---'
rg -n -F --glob '*.ts' -e 'resolveWslCodexSessionBridgeLinuxPaths' -e 'syncWslCodexSessionsIntoManagedHome' src/main/codex

Repository: stablyai/orca

Length of output: 15010


Script executed:

set -o pipefail
printf '%s\n' '--- managed-home header and bridge method ---'
nl -ba src/main/codex-accounts/runtime-home-service-managed-home.ts | sed -n '1,310p'
printf '%s\n' '--- selection helpers ---'
nl -ba src/main/codex-accounts/runtime-selection.ts | sed -n '1,155p'

Repository: stablyai/orca

Length of output: 19058


Restrict managed-account sources to managed-account targets.

When no WSL account is selected, getWslCodexHomePathForSelection returns the distro system home. Launch preparation passes that path to the bridge as its target, while startWslSessionBridgeForLaunch still adds managed-account homes from the distro as sources. The bridge then links those session files into the system home.

Suggested fix
--- "a/src/main/codex-accounts/runtime-home-service-managed-home.ts"
+++ "b/src/main/codex-accounts/runtime-home-service-managed-home.ts"
@@ -259,14 +259,18 @@
     const systemCodexHomePath =
       resolveWslCodexSessionSourceHome(this.store.getSettings(), distro) ??
       this.getWslSystemCodexHomePath({ runtime: 'wsl', wslDistro: distro })
     const targetLinuxPath = parseWslUncPath(runtimeHomePath)?.linuxPath ?? runtimeHomePath
+    const managedAccountHomes = this.store
+      .getSettings()
+      .codexManagedAccounts.map((account) => this.getWslLaunchCodexHomePath(account, distro))
+    const targetIsManagedAccountHome = managedAccountHomes.some(
+      (home) => !!home && (parseWslUncPath(home)?.linuxPath ?? home) === targetLinuxPath
+    )
     // Sibling account homes are sources too, or a switch hides the previous account's sessions (#18486).
     const sourceHomes = [
       systemCodexHomePath,
-      ...this.store
-        .getSettings()
-        .codexManagedAccounts.map((account) => this.getWslLaunchCodexHomePath(account, distro))
+      ...(targetIsManagedAccountHome ? managedAccountHomes : [])
     ].filter(
       (home): home is string =>
         !!home && (parseWslUncPath(home)?.linuxPath ?? home) !== targetLinuxPath
     )

Comment on lines +275 to +276
for (const sourceHome of new Set(sourceHomes)) {
await startWslCodexSessionBridgeInBackground({

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.

Major · Functional Correctness · Heavy lift

Supported by static analysis

Script executed:

sed -n '1,200p' src/main/codex/wsl-codex-session-bridge.ts
sed -n '255,290p' src/main/codex-accounts/runtime-home-service-managed-home.ts

Repository: stablyai/orca

Length of output: 8689


Let each source finish linking before index work delays the next source.

startWslSessionBridgeForLaunch awaits each startWslCodexSessionBridgeInBackground call before it starts the next source. The returned promise settles only after the index-ready gate, the file linking, and the index heal all finish. When the target home's index is not yet complete, the gate can wait up to 15 minutes. A long heal for an earlier source can also delay linking for every later source, including the sibling-account sessions this change adds for account-switch /resume.

Launch itself is not blocked, because the loop runs inside an unawaited async function. The delay affects only the sibling-account links.

Serialize the file-link steps where order matters. Start the index-gate and heal work without making the next source's file linking wait for it. This likely requires splitting the link step from the index step in src/main/codex/wsl-codex-session-bridge.ts.

Bridge the distro's system home and every sibling managed WSL account home in
the same distro into the selected account's home at launch, so a session
started on account A is resumable after switching to account B (#18486).

Split from #33578 (WSL half only).
…e loop per home

System default's own ~/.codex in the distro gets no sibling sources, so the
#24511 product decision stays out of this change. Concurrent launches join the
loop already bridging a target home. Restores #16854's drain-target assertion
with the launch bridge mocked.
@nwparker
nwparker force-pushed the nwparker/codex-wsl-bridge-sibling-accounts branch from 6230fbc to 7875c27 Compare October 28, 2026 10:46

@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
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c77a456f-39e8-4fee-a5a6-ab873a53ecb8
Commits

Reviewing files that changed from the base of the PR and between 6230fbc and 7875c27.

Files selected for processing: 3
  • src/main/codex-accounts/runtime-home-service-managed-home.ts
  • src/main/codex-accounts/runtime-home-wsl-session-bridge.test.ts
  • src/main/codex-accounts/runtime-home-wsl-sibling-bridge.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

setupRuntimeHomeTest()
originalPlatform = Object.getOwnPropertyDescriptor(process, 'platform')
Object.defineProperty(process, 'platform', { configurable: true, value: 'win32' })
wslHome = join(testState.userDataDir, 'ubuntu-home')

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.

Major · Functional Correctness · Quick win

Supported by static analysis

Script executed:

sed -n 1,160p src/main/codex-accounts/runtime-home-wsl-sibling-bridge.test.ts
rg -n "getWslManagedHomeIdentity|wslLinuxHomePath" src/main/codex-accounts/*.ts | head -40
rg -n "windows-latest|runs-on" .github/workflows | head -30
sed -n 1,80p src/main/codex-accounts/runtime-home-wsl-session-bridge.test.ts

Repository: stablyai/orca

Length of output: 15445


Script executed:

set -eu
printf '%s\n' '--- runtime-home-service-wsl-core.ts ---'
nl -ba src/main/codex-accounts/runtime-home-service-wsl-core.ts | sed -n '1,180p'
printf '%s\n' '--- parseWslUncPath and related path helpers ---'
rg -n -F --glob '*.ts' -e 'parseWslUncPath' -e 'getWslManagedHomeIdentity' -e 'wslLinuxHomePath' src/main src/shared | head -120
printf '%s\n' '--- sibling bridge test with line numbers ---'
nl -ba src/main/codex-accounts/runtime-home-wsl-sibling-bridge.test.ts | sed -n '1,180p'
printf '%s\n' '--- session bridge fixture blocks ---'
nl -ba src/main/codex-accounts/runtime-home-wsl-session-bridge.test.ts | sed -n '200,330p'
nl -ba src/main/codex-accounts/runtime-home-wsl-session-bridge.test.ts | sed -n '420,490p'
printf '%s\n' '--- test scripts and Windows CI references ---'
rg -n -F --glob 'package.json' -e '"test' -e 'vitest' .
rg -n -F --glob '.github/workflows/*' -e 'runtime-home-wsl-sibling-bridge' -e 'codex-accounts' -e 'windows-2022' -e 'windows-latest' -e 'pnpm test' -e 'vitest' .

Repository: stablyai/orca

Length of output: 41900


Script executed:

set -u
printf '%s\n' '--- shared WSL path parser ---'
nl -ba src/shared/wsl-paths.ts | sed -n '1,75p'
printf '%s\n' '--- runtime-home service launch and sibling bridge flow ---'
rg -n -F --glob 'src/main/codex-accounts/*.ts' -e 'prepareForCodexLaunch' -e 'startWslCodexSessionBridgeInBackground' -e 'getWslManagedHomeIdentity' -e 'getWslManagedHomePath'
printf '%s\n' '--- runtime-home service implementation ---'
nl -ba src/main/codex-accounts/runtime-home-service.ts | sed -n '1,260p'
printf '%s\n' '--- test harness path setup ---'
rg -n -F -- 'userDataDir' src/main/codex-accounts/runtime-home-service-test-harness.ts
nl -ba src/main/codex-accounts/runtime-home-service-test-harness.ts | sed -n '1,150p'
printf '%s\n' '--- Windows workflow and test selection ---'
for f in .github/workflows/*.yml .github/workflows/*.yaml; do
  [ -f "$f" ] || continue
  if grep -n -E 'windows|runs-on|pnpm (test|tc)|vitest|codex-accounts' "$f" >/tmp/workflow-matches 2>/dev/null; then
    echo "### $f"
    cat /tmp/workflow-matches
  fi
done

Repository: stablyai/orca

Length of output: 41214


Script executed:

set -eu
printf '%s\n' '--- launch methods ---'
nl -ba src/main/codex-accounts/runtime-home-service-launch.ts | sed -n '1,145p'
printf '%s\n' '--- managed-home bridge methods ---'
nl -ba src/main/codex-accounts/runtime-home-service-managed-home.ts | sed -n '1,120p'
nl -ba src/main/codex-accounts/runtime-home-service-managed-home.ts | sed -n '255,305p'
printf '%s\n' '--- WSL runtime-home methods ---'
nl -ba src/main/codex-accounts/runtime-home-service-wsl.ts | sed -n '1,125p'
printf '%s\n' '--- WSL home helper ---'
nl -ba src/main/wsl.ts | sed -n '1,75p'
printf '%s\n' '--- exact Windows CI test commands ---'
nl -ba .github/workflows/preflight-cli-platforms.yml | sed -n '24,60p'
nl -ba .github/workflows/zcode-credential-contract.yml | sed -n '25,105p'
nl -ba .github/workflows/zcode-transcript-contract.yml | sed -n '20,50p'

Repository: stablyai/orca

Length of output: 32691


Script executed:

set -eu
printf '%s\n' '--- WSL system-home helper ---'
rg -n -F --glob 'src/main/codex-accounts/*.ts' -e 'getWslSystemCodexHomePath' -e 'finishWslLaunchPreparation'
nl -ba src/main/codex-accounts/runtime-home-service-wsl.ts | sed -n '125,230p'
printf '%s\n' '--- finish launch preparation and bridge entry ---'
nl -ba src/main/codex-accounts/runtime-home-service-managed-home.ts | sed -n '205,270p'

Repository: stablyai/orca

Length of output: 6247


Use WSL-shaped paths in the fixtures.

On Windows, join(...) creates drive paths, but getWslManagedHomeIdentity requires POSIX wslLinuxHomePath values or WSL UNC paths. The selected account is rejected, so prepareForCodexLaunch returns the system WSL home instead of selectedHome, and the expected sibling bridge calls are not made.

Use explicit POSIX Linux paths and WSL UNC paths for the fixtures, then update the assertions.

@nwparker
nwparker merged commit f1bd810 into main Oct 28, 2026
36 checks passed
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.

[Bug]: Regression in 1.4.196: Codex session history no longer bridged between managed accounts

1 participant