Skip to content

fix(codex): keep Codex history across account switches on WSL and system default - #33578

Closed
nwparker wants to merge 1 commit into
mainfrom
nwparker/agint-codex-bridge-missing-lanes
Closed

nwparker wants to merge 1 commit into
mainfrom
nwparker/agint-codex-bridge-missing-lanes

Conversation

@nwparker

@nwparker nwparker commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​105 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​104
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​35 $\color{#cf222e}{\Huge{\mathbf{−}}}$​8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​27

Summary (ELI5)

Orca gives each managed Codex account its own CODEX_HOME so their logins never collide. To keep "switch account, keep your conversations" working (#10770), Orca hardlinks session files between those homes, because Codex's /resume and codex resume <id> only look in their own CODEX_HOME. Two launch paths had stopped doing that:

  1. WSL accounts ([Bug]: Regression in 1.4.196: Codex session history no longer bridged between managed accounts #18486): after the WSL direct-home cutover (fix(codex): re-land WSL direct-home cutover with counsel findings fixed #16854), a WSL launch only linked the distro's ~/.codex into the selected account. A session started on account A was missing after switching to account B.
  2. Host system default on the real ~/.codex ([Bug]: Codex session disappears after account switch when pane routes from managed home to ~/.codex (macOS 1.4.218) #25000): switching back to "system default" launched Codex on ~/.codex, and nothing linked the managed accounts' sessions there, so the folder's session list looked empty.

Root cause

  • runtime-home-service-managed-home.ts startWslSessionBridgeForLaunch passed only the distro system home as a source (systemCodexHomePath → runtimeHomePath). The host lane already includes every managed home (getSelfContainedSessionBridgeSourceHomes).
  • runtime-home-service-launch.ts prepareForCodexLaunch returned null for the real-home lane without starting any bridge. Managed-home history flowed from ~/.codex but never back into it.
  • Upstream Codex: codex resume <id> resolves the rollout by scanning $CODEX_HOME/sessions (codex-rs/rollout/src/list.rs:1512-1529, find_thread_path_by_id_str → filename fallback). The picker lists indexed threads, which the existing account-session bridge heals through thread/read.

What changed

  • WSL: bridge the distro system home and every sibling managed WSL account home in the same distro into the launch home. The target and duplicates are skipped by comparing Linux paths, and sources run one wsl.exe at a time. The existing bridge script and its in-flight dedupe are unchanged.
  • Host real-home lane: start the existing startCodexAccountSessionBridgeInBackground with target = the host session-source home (~/.codex or the configured source home) and sources = trusted managed host account homes. This reuses its backfill-ready gate and index heal. It is skipped when there are no managed host accounts.
  • Tests: one regression test per lane (both fail on main). I dropped one assertion from fix(codex): re-land WSL direct-home cutover with counsel findings fixed #16854's retired-session test that required the retired session to not reach the selected sibling home. That is exactly the cross-account isolation this PR reverts to fix(codex): keep history, restarts, and account identity across an account switch #10770 behavior.

Verification (real Windows: win-lowspec, WSL Ubuntu, pinned Codex 0.164.0, isolated USERPROFILE/APPDATA/LOCALAPPDATA/CODEX_HOME, mock Responses server, no API keys)

I drove Orca's real CodexRuntimeHomeService.prepareForCodexLaunch* on Windows (esbuild bundle of the source, real wsl.exe and bridge script, real Codex app-server for index heal). getWslHome points at a temp guest dir, and accounts live under /tmp/agint-codexbridge in the distro.

#18486, WSL: a real session was created with codex exec in account A's home, account B was selected, Orca's WSL launch prep ran, and then codex exec resume <id> ran under B's CODEX_HOME:

main this PR
rollout in B 0 1 (same inode as A: hardlink)
codex exec resume <id> from B thread/resume failed: no rollout found for thread id … resumes, and the mock model replies

#25000, host real-home lane: a real session was created in a managed host account home, system default was selected (no CODEX_HOME override), Orca's launch prep returned null (real home), and then:

main this PR
rollouts in ~/.codex/sessions none the managed session
thread indexed in ~/.codex state DB (picker) n/a yes, before any resume
codex exec resume <id> on ~/.codex no rollout found for thread id … resumes and appends to the same rollout
  • pnpm test src/main/codex-accounts/ (457 tests), pnpm tc:node, and pnpm run check:code-quality:changed pass.

Risk / trade-offs vs main

  • Behavior change: sessions from managed accounts now also show up in the user's own ~/.codex session list. Hardlinks only, so no extra disk use, and no auth or config is copied. This matches the existing host per-account lane, which already links ~/.codex and every sibling account home in. Users who want strict per-account isolation ([Bug]: Codex session bridge shares history across all managed accounts with no opt-out or per-account scope #24511) still have no switch. That is a separate product decision.
  • The real-home lane now does a background scan of managed homes on each system-default launch, deduped per target like the per-account lane. If ~/.codex has no state DB yet, the existing gate starts Codex once to create it before linking.
  • WSL bridging now spawns up to N sequential wsl.exe runs per launch (N = number of WSL accounts in that distro).
  • Not covered: the WSL lane still links files without healing Codex's thread index, so codex resume <id> works but the picker's indexed-only view may not list bridged WSL threads. The pane-restart path choosing bare codex (a comment on [Bug]: Regression in 1.4.196: Codex session history no longer bridged between managed accounts #18486) is also not covered.

Fixes #18486
Fixes #25000

…tem default

WSL launches bridged only the distro's ~/.codex into the selected account
home, so a session started on another managed WSL account was missing after
switching (regressed by the direct-home cutover in #16854). Bridge every
sibling WSL account home in the distro too, one wsl.exe at a time.

Host system-default launches on the real ~/.codex bridged nothing, so
sessions from managed accounts disappeared when switching back. Bridge
managed host account homes into the real home with the existing
account-session bridge, which also heals Codex's thread index.

Fixes #18486
Fixes #25000
@nwparker
nwparker marked this pull request as draft October 25, 2026 16:24
@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The host system-default real-home launch path now starts a session bridge from managed account homes to the configured host session source or the system Codex home. Windows WSL launches now bridge sessions from the system home and managed homes in the selected distro into the selected account home. Tests cover both launch paths. The WSL test also removes an assertion that a retired session is absent.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Moderate · up to a3cac

With a separate history-source setting, switching to the default Codex home can still leave managed-account sessions unavailable. Correct the bridge target before merging unless that limitation is explicitly accepted.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Out of Scope Changes check Warning The real-home change bridges every trusted managed host account home into the real or configured host home. getManagedHostAccountHomesForSessionDiscovery() collects all managed host accounts, and `s… Limit the real-home bridge to the managed account involved in the route transition, or add an explicit supported opt-in or transfer action before exposing histories from multiple managed accounts. Keep the cross-account WSL bridge required …
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title names the main change: restoring Codex history across account switches on WSL and the system-default home. It uses the conventional fix(codex) prefix, is one sentence, and matches the change…
Description check Passed The description follows the template's main sections: ELI5 summary, root cause, what changed, verification, risks, and linked issues (Fixes #18486 and Fixes #25000). It uses the template's linked-issu…
Linked Issues check Passed The PR meets the coding requirements in #18486 and #25000. For #18486, startWslSessionBridgeForLaunch adds same-distro managed homes as sources, excludes the target path, deduplicates sources, and r…
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 4…
Full details: Title check

Explanation

The title names the main change: restoring Codex history across account switches on WSL and the system-default home. It uses the conventional fix(codex) prefix, is one sentence, and matches the changeset, which bridges sessions into the WSL launch home and the host real-home lane.

Full details: Description check

Explanation

The description follows the template's main sections: ELI5 summary, root cause, what changed, verification, risks, and linked issues (Fixes #18486 and Fixes #25000). It uses the template's linked-issue format. The Visual Proof section is missing, and the AI Disclosure, Review, and Agent skill upstream boundary sections are blank or unchecked. The Testing section gives detailed real-Windows steps but leaves the manual-testing checkbox unmarked. The Checklist is not ticked. The Visual Proof section should state whether a before/after is needed; the lane changes affect launch behavior, not UI, so the author should write N/A with a reason if no visual change applies. The author should also tick the manual-test checkbox, since the description reports manual validation on win-lowspec.

Resolution

Mark the manual-testing checkbox, since the description reports real-Windows validation. Add a Visual Proof entry or write N/A with a reason. Complete or tick the Checklist items, and confirm the Agent skill upstream boundary item. Fill in the AI Disclosure section if an AI tool helped write the change.

Full details: Linked Issues check

Explanation

The PR meets the coding requirements in #18486 and #25000. For #18486, startWslSessionBridgeForLaunch adds same-distro managed homes as sources, excludes the target path, deduplicates sources, and runs bridges sequentially. The regression test verifies the system home and sibling account home inputs. For #25000, the real-home launch calls startSystemDefaultSessionBridgeForLaunch. The method targets the configured host session source or the real Codex home and uses trusted managed host homes as sources. The regression test verifies the call and the null real-home launch result. The existing bridge supplies rollout linking and host index healing.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 4 files.

Full details: Out of Scope Changes check

Explanation

The real-home change bridges every trusted managed host account home into the real or configured host home. getManagedHostAccountHomesForSessionDiscovery() collects all managed host accounts, and startSystemDefaultSessionBridgeForLaunch() passes the full list as sources. Issue #25000 requests continuity for the managed-home to real-home transition and explicitly does not request unrestricted history sharing across unrelated accounts. This change exposes histories from all managed accounts in the real home, including accounts unrelated to the affected conversation.

Resolution

Limit the real-home bridge to the managed account involved in the route transition, or add an explicit supported opt-in or transfer action before exposing histories from multiple managed accounts. Keep the cross-account WSL bridge required by #18486.

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: 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: edf637f8-d3bd-41a6-8891-566250c43d65
Commits

Reviewing files that changed from the base of the PR and between c074ec5 and a3cacfb.

Files selected for processing: 4
  • src/main/codex-accounts/runtime-home-real-home-lane-routing.test.ts
  • src/main/codex-accounts/runtime-home-service-launch.ts
  • 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; 2 remain after this review.

Comment on lines +158 to +159
targetCodexHomePath:
resolveHostCodexSessionSourceHome(this.store.getSettings()) ?? getSystemCodexHomePath(),

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:

set -o pipefail
printf '%s\n' '--- diff ---'
git diff --find-renames c074ec50da641241e79867cf520cea93e45a919d0 a3cacfb26556809d29235e16982373b82a74b6d0 -- src/main/codex-accounts/runtime-home-service-managed-home.ts src/main/codex-accounts
printf '%s\n' '--- target implementation and related symbols ---'
rg -n -F --glob '*.ts' -e 'resolveHostCodexSessionSourceHome' -e 'isHostSystemDefaultRealHomeSelected' -e 'prepareForCodexLaunch' -e 'targetCodexHomePath' -e 'codexSessionSourceHome' src/main/codex-accounts src | head -240
printf '%s\n' '--- relevant file excerpts ---'
nl -ba src/main/codex-accounts/runtime-home-service-managed-home.ts | sed -n '1,240p'
printf '%s\n' '--- selection/launch definitions ---'
rg -l -F --glob '*.ts' -e 'isHostSystemDefaultRealHomeSelected' -e 'resolveHostCodexSessionSourceHome' -e 'codexSessionSourceHome' src/main | while read -r f; do echo "### $f"; nl -ba "$f" | sed -n '1,280p'; done
printf '%s\n' '--- focused tests ---'
rg -n -F --glob '*.{ts,tsx}' -e 'resolveHostCodexSessionSourceHome' -e 'isHostSystemDefaultRealHomeSelected' -e 'startSystemDefaultSessionBridgeForLaunch' -e 'configured source' -e 'session source' src/main/codex-accounts src | head -240

Repository: stablyai/orca

Length of output: 45667


Script executed:

printf '%s\n' '--- launch ---'
nl -ba src/main/codex-accounts/runtime-home-service-launch.ts | sed -n '1,190p'
printf '%s\n' '--- home routing ---'
nl -ba src/main/codex-accounts/runtime-home-service-home-routing.ts | sed -n '1,150p'
printf '%s\n' '--- session source resolver ---'
nl -ba src/main/codex/codex-session-source-home.ts
printf '%s\n' '--- direct consumers of source home ---'
nl -ba src/main/startup/main-process-runtime-service.ts | sed -n '95,140p'
nl -ba src/main/startup/main-process-account-services.ts | sed -n '35,65p'
nl -ba src/main/startup/main-window-core-services.ts | sed -n '75,105p'
printf '%s\n' '--- configured source tests ---'
nl -ba src/main/codex-accounts/runtime-home-session-migration-pass.test.ts | sed -n '1,180p'
nl -ba src/main/codex-accounts/runtime-home-real-home-lane-routing.test.ts | sed -n '1,230p'
printf '%s\n' '--- relevant settings declarations ---'
rg -n -F --glob '*.{ts,tsx}' -e 'codexSessionSourceHome' -e 'realHomeRoutable' src/shared src/main | head -160

Repository: stablyai/orca

Length of output: 42129


Target the real Codex home for real-home launches.

When the real-home lane is selected, prepareForCodexLaunch() returns null, so CODEX_HOME remains unset and Codex reads the system home. The bridge currently targets the configured history source instead, so managed sessions can remain unavailable from the real 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"
@@ -155,8 +155,7 @@
       return
     }
     void startCodexAccountSessionBridgeInBackground({
-      targetCodexHomePath:
-        resolveHostCodexSessionSourceHome(this.store.getSettings()) ?? getSystemCodexHomePath(),
+      targetCodexHomePath: getSystemCodexHomePath(),
       sourceCodexHomePaths
     })
   }

If the configured history home must also contribute existing sessions, include it as a source instead of using it as the target.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
targetCodexHomePath:
resolveHostCodexSessionSourceHome(this.store.getSettings()) ?? getSystemCodexHomePath(),
targetCodexHomePath: getSystemCodexHomePath(),

@nwparker

Copy link
Copy Markdown
Contributor Author

Split into two PRs: #34968 is the WSL half (#18486), ready for review. #34981 is the host system-default half (#25000), a draft because it writes into the user's own ~/.codex and needs an owner product decision (#10770 vs #24511 opt-out).

@nwparker nwparker closed this Oct 28, 2026
nwparker added a commit that referenced this pull request Oct 28, 2026
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).
nwparker added a commit that referenced this pull request Oct 28, 2026
* fix(codex): keep Codex history across WSL account switches

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).

* fix(codex): bridge WSL siblings only into a selected account home, one 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 added a commit that referenced this pull request Oct 29, 2026
… on system default

When system default launches Codex on the real ~/.codex, bridge every trusted
managed host account home into it so sessions started on a managed account
stay resumable after switching back (#25000).

Split from #33578 (host half). Needs an owner product decision (#10770 vs #24511).
nwparker added a commit that referenced this pull request Oct 29, 2026
…h a per-host opt-out (#24511) (#34981)

* fix(codex): link managed-account history into the user's own ~/.codex on system default

When system default launches Codex on the real ~/.codex, bridge every trusted
managed host account home into it so sessions started on a managed account
stay resumable after switching back (#25000).

Split from #33578 (host half). Needs an owner product decision (#10770 vs #24511).

* feat(codex): a per-host opt-out for sharing Codex history across accounts (#24511)

Adds codexShareHistoryAcrossAccounts (absent = on, today's #10770 behaviour).
Off, the host that launches Codex starts none of its history bridges: system
default into the shared runtime home, accounts and ~/.codex into a per-account
home, managed accounts into the real ~/.codex, and the WSL distro and sibling
accounts into a WSL account home. Turning it off removes nothing already linked.

The setting lives in each host's own store, since that host writes the links.
Settings → Agents shows it for the selected host: local writes update this app,
a paired SSH or WSL host is read and written over settings.get/settings.update.
New hosts always publish the key; a host that doesn't is shown as needing an
update and is never sent it, because older hosts' strict update schema would
reject the call. Strings are localized for all 11 locales.

The system-default lane moves into the launch class, keeping managed-home under
the line cap.

* fix(codex): ~/.codex gets hardlinks or nothing, and a WSL history source is left to the WSL lane

The system-default lane wrote into codexSessionSourceHome when set, which can be
a \\wsl.localhost path: the background scan would boot a stopped distro over 9P
and its cross-volume symlinks are ignored by codex resume. That lane now returns
early for a WSL UNC target; the WSL lane owns those homes.

Into the user's own ~/.codex the bridge now links with hardlinks only: a failed
hardlink (EXDEV across volumes) skips the rollout, counted as skippedFiles,
removes any folder it just created, and never falls back to a symlink that
codex resume ignores and that would dangle once an account is removed. Bridges
between Orca-managed homes keep the symlink fallback.

Also: the setting's JSDoc sits above its own field, and Settings search finds
the switch (codex, history, share, shared, account; existing localized keys).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant