Repository navigation
fix(codex): index a new WSL account home before bridging history into it - #23843
brennanb2025 wants to merge 3 commits into
Conversation
Status: ready for review, not mergedWhat it fixes: a new Orca-managed Codex account for a WSL project can't start Codex for many minutes when the distro has a large Codex history. This is the WSL path #22971 didn't cover. Validated on a Windows machine with WSL Ubuntu 24.04 and the distro's real Codex 0.151:
Review:
CI: everything passes at Not verified:
Out of scope, noted for follow-up:
|
|
| const rollout = parseCodexRolloutThreadId(rolloutName) | ||
| if (rollout) { | ||
| pendingThreads.set(rollout.threadId, rollout.rolloutStamp) | ||
| markerByThreadId.set(rollout.threadId, rolloutName) | ||
| } else { | ||
| markersWithoutThread.push(rolloutName) | ||
| } |
There was a problem hiding this comment.
Valid history loses its marker
If a WSL history source contains a dated rollout-<uuid>.jsonl conversation, the link script creates a pending marker for it, but this parser accepts only rollout-<timestamp>-<uuid>.jsonl. The bridge deletes the marker without asking Codex to index the thread. That conversation remains absent from the indexed /resume list, and later launches have no marker to retry.
There was a problem hiding this comment.
ℹ️ No critical issues — one design question and a couple of nits.
Reviewed changes
- The missing WSL twin of #22971.
bridgeAndIndexWslCodexSessionsnow opens the managed home's Codex state DB first (createCodexAccountStateDbwith a 15-minute timeout, once per home per Orca run, through a new WSLbuildWslHealInvocation), skips linking if it cannot, then links history, then drivesthread/readover the newly linked rollouts via the shared heal loop. - Per-rollout marker files record pending index work. The bridge shell script writes
<account home>/.orca-index-pending/<rollout name>for each newly linked rollout, drops it when the link failed, and prints the pending names (newest first) before a summary that counts them. The host parses them, indexes them, and deletes markers as each thread settles. - Shared the heal loop and added a per-batch hook.
healCodexAccountSessionIndexwas split sohealPendingCodexAccountThreadscan be reused by the WSL path;readCodexThreadsForIndexHealgainedafterBatch(runs on success and in the catch path; a failure is logged, not fatal). - Partial link failures no longer strand the marker list.
syncWslCodexSessionsIntoManagedHomeparses the summary even on a non-zero exit and reportsbridgeFailed, so one unlinkable file cannot suppress indexing of everything else.
ℹ️ Pre-existing hidden history in already-created WSL accounts stays hidden
The fix only creates markers for rollouts it links from now on, so an account that already has bridged-but-unindexed history from before this change never gets that history indexed — it stays hidden from /resume. The PR body scopes this out, so this is a check that the call is deliberate rather than an objection.
Technical details
# Existing linked-but-unindexed WSL history is never recovered
## Affected sites
- `src/main/codex/wsl-codex-session-bridge.ts:141` — `pendingThreads` is built only from `summary.pendingRollouts`, i.e. markers written on this launch.
- `src/main/codex/wsl-codex-session-bridge-script.ts:96` — a marker is written only when the loop creates a new `target_file`; an already-linked rollout hits the `continue` at line 61.
- `src/main/codex/wsl-codex-session-bridge.ts:122` — the startup probe only brings the state DB to `complete`; it does not index rollouts linked after Codex's one-shot backfill.
## Required outcome
Decide whether the population the bug actually hit (accounts whose first index never completed) should get a one-time marker sweep of `<managed home>/sessions` on the first run after upgrade, or whether leaving that history hidden is acceptable. The PR body says it is out of scope; confirm that is intended.
## Suggested approach (optional)
On a home that has no markers yet, have the bridge script walk `managed_sessions_root` for `rollout-*.jsonl` without a marker and create one, then let the existing `thread/read` heal settle or drop them. Cost is bounded by the same indexing pass this PR already runs; already-indexed threads resolve as `healed` cheaply.
## Open questions for the human (optional)
- Is the unrecovered old-history population small enough to leave, or is it the common case for the users who reported #20669?ℹ️ Nitpicks
src/main/codex/wsl-codex-session-bridge.test.ts:121— the test name "throws on a non-zero exit so the background wrapper logs and swallows it" no longer matches the contract: a non-zero exit with a parsed summary now returnsbridgeFailed: trueand throws only later inbridgeAndIndexWslCodexSessions, while an unparseable summary throws here. Consider renaming so the next reader does not assume non-zero always throws at this call.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 📝 WalkthroughWalkthroughThe WSL session bridge now waits for a managed Codex home index before syncing sessions. The script records and reports pending rollout markers. The bridge parses those markers, heals matching threads, and clears markers for outcomes other than failed reads. The change also adds configurable healing timeouts, batch callbacks, shutdown checks, and tests for the marker and healing flows. Priority: ➖ Normal Merge Risk: 🔵 Low · up to A ledger write failure may cause a thread to be skipped on future recovery; fix the ordering before merge. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change remains scoped to local WSL account-history processing. The examined paths preserve account and distro targeting and retain unfinished work for recovery. No introduced security weakness was established, but incomplete exposure and comparison coverage prevents a minimal-risk assessment. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
The WSL history bridge hardlinked every conversation into a new managed account home before Codex had opened it, so Codex's first open had to index all of it and every other Codex on that home gave up after 30s. Apply the native ordering from #22971 inside the distro: Codex brings the home's index to complete first, history is linked after, and the shared thread/read loop indexes it newest first. Windows cannot read the guest's Codex sqlite over 9p, so a marker per linked rollout records the pending indexing work and dies once thread/read settles it.
…not a Codex thread The launch bridge counted only Codex-shaped marker names against the script's pendingFiles total, so a single rollout-*.jsonl without a thread id made the count mismatch on every launch and skipped the home's whole index heal. Count every listed marker for the completeness check and index the parseable ones.
…read id thread/read can never settle such a marker, so it was listed on every launch with nothing to remove it.
6274b45 to
57390a5
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: ef65e5db-9bd5-4a23-85ea-e3dfd5dd82d8
📒 Files selected for processing (1)
src/main/codex/codex-session-index-heal.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
| const outcome = await readOneThread(rpc, thread.threadId) | ||
| settled.push({ threadId: thread.threadId, outcome }) | ||
| onOutcome(thread, outcome) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- changed-file diff ---'
git diff --no-ext-diff --unified=50 f09458796db5886abd0be00f726a0b5a302e6a04 57390a5ad6f7ff1563da0333cb5cfe60225d9e50 -- src/main/codex/codex-session-index-heal.ts
printf '%s\n' '--- current module outline ---'
ast-grep outline src/main/codex/codex-session-index-heal.ts
printf '%s\n' '--- current module relevant ranges ---'
rg -n -C 12 'settled|onOutcome|runAfterBatch|afterBatch|recordHealOutcome|pending|marker' src/main/codex/codex-session-index-heal.ts
printf '%s\n' '--- repository bindings ---'
rg -n -C 10 'recordHealOutcome|afterBatch|runAfterBatch|pending.*marker|marker.*pending|clear.*pending|delete.*pending' srcRepository: stablyai/orca
Length of output: 45663
🤖 get_repo_knowledge executed:
get_repo_knowledge stablyai/orca /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions
Length of output: 17103
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- changed files ---'
git diff --name-only f09458796db5886abd0be00f726a0b5a302e6a04 57390a5ad6f7ff1563da0333cb5cfe60225d9e50
printf '%s\n' '--- exact callback bindings ---'
rg -n -C 14 'afterBatch|readCodexThreadsForIndexHeal|runCodexSessionIndexHeal|recordHealOutcome' src/main/codex src/main --glob '*.ts'
printf '%s\n' '--- heal state implementation ---'
wc -l src/main/codex/codex-session-index-heal-state.ts
cat -n src/main/codex/codex-session-index-heal-state.tsRepository: stablyai/orca
Length of output: 42260
🏁 Script executed:
#!/bin/bash
set -e
cat -n src/main/codex/wsl-codex-session-bridge.ts | sed -n '130,225p'
printf '%s\n' '--- marker helper bindings ---'
rg -n -C 12 'clearIndexPendingMarkers|index pending|pending marker|write.*marker|unlink|rmSync' src/main/codex/wsl-codex-session-bridge.ts src/main/codex/wsl-codex-session-bridge-script.ts src/main/codexRepository: stablyai/orca
Length of output: 45665
Record the read only after persisting its outcome.
For a healed or missing read, recordHealOutcome can throw when the ledger write fails. The current order still adds that read to settled, and the WSL afterBatch callback then removes its pending marker. The next pass has neither the marker nor a ledger record.
Suggested fix
- settled.push({ threadId: thread.threadId, outcome })
onOutcome(thread, outcome)
+ settled.push({ threadId: thread.threadId, outcome })📝 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.
| const outcome = await readOneThread(rpc, thread.threadId) | |
| settled.push({ threadId: thread.threadId, outcome }) | |
| onOutcome(thread, outcome) | |
| const outcome = await readOneThread(rpc, thread.threadId) | |
| onOutcome(thread, outcome) | |
| settled.push({ threadId: thread.threadId, outcome }) |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
The two commits since the prior pullfrog review (6274b45) close a marker-counting edge case in the WSL account history bridge:
- A marker whose name is not a Codex thread no longer stalls the whole home's heal.
parseWslSessionBridgeSummarynow validatespendingFilesagainst everyrollout-*marker line, so onerollout-*.jsonlwithout a parseable thread id can no longer fail the count on every launch and skip indexing everything else. - Such markers are cleared instead of reported forever.
pendingRolloutsnow carries the full marker list; the bridge splits parseable names intopendingThreads/markerByThreadIdand clears the rest through a newclearIndexPendingMarkershelper (also reused byclearSettledIndexPendingMarkers), sincethread/readcan never settle them. - Tests pin both halves. A new case asserts the parseable marker is still indexed while the non-thread marker is cleared, and the shared-loop and script suites continue to cover the ordering and marker lifecycle.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
… it (carries #23843) (#33630) New WSL Codex managed accounts no longer link all past rollouts before Codex first opens the home (which stalled startup past Codex's 30s backfill gate or left later-linked sessions unindexed): Codex opens the home first, then history is linked and indexed in background batches newest-first, resumable across restarts — matching #22971's non-WSL order. Supersedes #23843 Co-authored-by: Brennan Benson <[email protected]>
|
Closing as superseded by #33630 (merged), which carries this fix for indexing a new WSL account home before bridging history. Thanks @brennanb2025! |

What this fixes: On Windows, adding a new Codex account for a WSL project, when you already have a large Codex history in WSL, leaves Codex unable to start in that project for many minutes. This is the WSL twin of the bug #22971 fixed for non-WSL accounts. #22971 changed only the non-WSL history bridge; WSL accounts use a separate bridge that still linked history in the old order. Found in the follow-up review of #22971 (issue #20669).
Who is affected: Windows users who add or switch to an Orca-managed Codex account for a WSL project and have a large history in the distro's Codex folder. The more history, the longer the outage.
Not affected: macOS, Linux, non-WSL Windows accounts (already fixed by #22971), SSH, the default WSL Codex setup with no Orca-managed account, and small histories (40 conversations indexed instantly before and after).
ELI5
Codex keeps an index of your past conversations. When Orca creates a new account for WSL, it copies links to all your old conversations into that account's folder so
/resumecan still find them. It did that before Codex had ever opened the folder, so Codex's first start had to index everything at once. Every other Codex that tried to start meanwhile gave up after 30 seconds. Now Orca lets Codex open the empty folder first, then adds the history, then has Codex index it quietly in the background, newest first. That is the same order #22971 uses outside WSL.What Changed
Before (measured on a Windows machine with WSL Ubuntu 24.04, real Codex 0.151, 16,000 synthetic 1 MB conversations, current
main):After (same machine, same history, this branch):
/resumeloads first, already shows 79 conversations for the project, newest first, after about 2,000 of 16,000 were indexed. Indexing continues in the background.Mechanism:
codex app-serveron the account's folder once per Orca run, using the same short, read-only invocation as the other background Codex processes, run throughwsl.exewith the helpersdocs/reference/wsl-command-execution.mdrequires.initializeonly once its startup indexing is complete, so that answer is the "ready" signal.createCodexAccountStateDbdoes in fix(codex): index a new account home before bridging history into it #22971.<account home>/.orca-index-pending/<rollout name>, for each conversation it newly links. It prints the markers that are still pending, newest first, before its summary line.readCodexThreadsForIndexHealloop viahealPendingCodexAccountThreads, with the same batch size, newest-first order and per-home memory of failed reads.Deliberate differences from the non-WSL path:
Why markers instead of the native diff: #22971 decides what to index by reading Codex's SQLite database directly. Windows cannot do that for a WSL folder. I measured three ways:
\\wsl.localhostfails with "database is locked", even with no Codex running. The repo already documents this for other SQLite readers.win32-none) fails too.immutableopen succeeds but returns stale data, because Codex leaves recent writes in its-walfile. It showedrunning/ 35 rows while the truth inside the distro wascomplete/ 40.The distro may not have
python3,nodeorsqlite3, so there is nothing reliable to read the database inside WSL either. A marker per linked conversation is the smallest durable record of "Codex still has to index this". It is created in the same step as the link, and it goes away when indexing settles it or when the account folder is deleted.The legacy WSL auth migration reuses the same script body. It never turns markers on, so its behavior and its 16 KB output limit are unchanged (a test pins that).
Why
/resumehides unindexed conversations once a folder has any indexed one, so linked history would vanish.thread/list): that listing filters by provider, source kind and archive state by default, which varies between Codex versions. For example, the test machine's WSL config uses a custom provider, and the default listing returned 0 of 40 threads.runningfrom before this fix gets repaired by that same background Codex once Codex's 15-minute claim expires, because a Codex that wins the claim finishes the indexing. I did not run that case end to end.Linked Issue
Refs #20669 (fixed for non-WSL accounts by #22971; this is the WSL path it did not cover).
Visual Proof
Before (
main, 45 s after opening a Codex chat on a new WSL account with 16,000 conversations):After (this branch, same setup: the chat is open and running a turn while history indexes in the background):
Testing
Windows + WSL (Windows high spec box, Ubuntu 24.04, Codex 0.151):
mainand of this branch, each with an isolated profile and Windows home, launched in the background.~/.codexwas never a source.~/.codex/~/.claudeconfig files were byte-identical before and after every run.Unit tests:
wsl-codex-session-bridge-index.test.ts, new, covers the pipeline:wsl-codex-session-bridge-script.test.ts, new, runs the real script in bash:tc:node,oxlintandcheck:code-quality:changedare clean.Platforms: Windows + WSL (manual, above). The macOS / Linux unit tests exercise the bash script directly. SSH is not affected: account history bridging is local-only.
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
startWslSessionBridgeForLaunchruns only on Windows). The Codex commands followdocs/reference/wsl-command-execution.md.wsl.exefor the link script. The startup check adds one short Codex start per account per Orca run.\\wsl.localhoston Orca's main thread was added./resumepicker. I used Codex's database-only list, which is what that picker loads first.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred):tc:node,oxlint,check:code-quality:changedand the affected suites pass locally; CI typecheck, tests, static analysis and both packages pass