Skip to content

fix(codex): index a new WSL account home before bridging history into it (carries #23843) - #33630

Merged
nwparker merged 3 commits into
mainfrom
nwparker/agint-codex-wsl-account-index-order
Oct 25, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/agint-codex-wsl-account-index-order

Conversation

@nwparker

@nwparker nwparker commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​480 $\color{#cf222e}{\Huge{\mathbf{−}}}$​12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​468
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​324 $\color{#cf222e}{\Huge{\mathbf{−}}}$​43 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​281

Carries #23843 by @brennanb2025. It's rebased onto current main, and the three original commits are kept with their authorship. The rebase only resolved comment-only conflicts left by the repo-wide comment cleanup. The code is unchanged from #23843.

ELI5

Codex keeps an index of past conversations. When Orca sets up a new Codex account for a WSL project, it links all your old conversations into that account's folder before Codex has ever opened it. The first Codex to open the folder then has to index everything at once. Every other Codex on that account waits 30s and then gives up. With this change, Orca lets Codex open the empty folder first, then links the history, then has Codex index it in the background, newest first. That's the same order #22971 already uses for non-WSL accounts.

Root cause (upstream refs)

  • Codex blocks startup until the state DB backfill is complete. A process that doesn't own the backfill gives up after 30s with timed out waiting for state db backfill ... (status: running). See codex-rs/rollout/src/state_db.rs:36 (STARTUP_BACKFILL_WAIT_TIMEOUT = 30s) and wait_for_backfill_gate, state_db.rs:132-181 (openai/codex @ 970111f6cb).
  • A backfill that has finished never rescans. Rollouts linked afterwards stay unindexed and are hidden from DB-backed /resume.
  • fix(codex): index a new account home before bridging history into it #22971 fixed this ordering for native account homes only. The WSL bridge (wsl-codex-session-bridge.ts) still linked first. Windows can't read the guest's SQLite over \\wsl.localhost, so the PR records pending work as one marker file per linked rollout. The markers feed fix(codex): index a new account home before bridging history into it #22971's shared healPendingCodexAccountThreads / readCodexThreadsForIndexHeal loop through the distro's own codex app-server.

What changed

See #23843 for the full design. In short:

  • Before linking: the bridge starts codex app-server once per account home per Orca run (buildWslHealInvocation), and initialize acts as the readiness signal. If Codex can't start, nothing is linked on that launch.
  • Markers: the in-distro link script writes <home>/.orca-index-pending/<rollout> for each newly linked rollout. It prints the pending markers newest first.
  • Indexing: Orca indexes those threads in batches through the distro's Codex and clears a batch's markers once it settles. A failed read keeps its marker. Quit stops the WSL bridge the same way it stops the native one.

Verification (real Windows + WSL, win-lowspec: 8 cores / 16 GB, Ubuntu WSL2, Codex 0.164.0 pinned in a temp dir)

This drove the real startWslCodexSessionBridgeInBackground from Windows Node (real wsl.exe, real in-distro script, real guest codex app-server). The source was 20,000 synthetic rollouts in a temp history folder, and each run used a fresh UNC managed home under /tmp. A side probe timed initialize for a "chat" Codex plus a second Codex started 2s later on the same home.

main (9654684):

  • Stall: history fully linked before any Codex opened the home. The chat's Codex took 35.8s to initialize. The second Codex failed with timed out waiting for state db backfill at …/managed after 30s (status: running).
  • Hidden history: when Codex opened the home while linking was still running, the index went complete with 3,563 threads and stayed there after all 20,000 were linked. The other 16,437 conversations were never indexed.

This branch:

  • Codex opens immediately: 20,000 linked plus 20,000 markers, index complete/0. The chat Codex initialized in 2.4s and the second Codex in 0.8s.
  • Newest first: after 120s, 1,640 were indexed, all newest (2026-08-05…2026-08-25). The simulated quit stopped cleanly, and indexed plus markers added up to exactly 20,000.
  • Resume after restart: a fresh process picked up the remaining markers (oldest first left). It ended with 20,000 indexed and 0 markers, and the next launch's bridge settled in about 1s.
  • Unit tests: pnpm test on the codex and codex-accounts suites (70 files / 521 tests) passes. pnpm tc:node and check:code-quality:changed are clean.
  • Real configs untouched: the real Windows ~/.codex config/auth hashes and the WSL ~/.codex/config.toml hash were the same before and after.

Trade-offs vs main

  • One extra short codex app-server start per WSL account per Orca run, before linking.
  • Indexing a huge history costs the same total Codex work as one first-open backfill, but it runs in the background in batches of 50. On the low-spec box, 20k conversations took roughly 24 minutes in total. /resume fills in newest first.
  • Slow boxes: on a low-spec box with a very large history, the existing 30s link-script timeout can expire on the first launch. That's unchanged from main. The guest keeps linking and writing markers, and indexing then starts on the next launch.
  • Accounts created before this change keep their existing links. Already-hidden older history isn't re-indexed.

Risk

Medium-low. The change is WSL-only, runs in the background, and no launch waits on it. It reuses #22971's indexing loop. Compatible with held #33578, which runs WSL bridges for several sources one at a time: indexing state is per target home, and the markers dir is shared.

Refs #20669. Supersedes #23843.

Co-authored-by: Brennan Benson 79079362+brennanb2025@users.noreply.github.com

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.
@coderabbitai

coderabbitai Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent 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: e693ee85-8a7c-4f8d-bf92-6b5b4a41fd4e
Commits

Reviewing files that changed from the base of the PR and between d4cab5c and da7bcb6.

Files selected for processing: 11
  • src/main/codex-accounts/runtime-home-service-per-account-migration.test.ts
  • src/main/codex/codex-account-session-bridge.ts
  • src/main/codex/codex-account-session-index-heal.test.ts
  • src/main/codex/codex-account-session-index-heal.ts
  • src/main/codex/codex-session-index-heal.test.ts
  • src/main/codex/codex-session-index-heal.ts
  • src/main/codex/wsl-codex-session-bridge-index.test.ts
  • src/main/codex/wsl-codex-session-bridge-script.test.ts
  • src/main/codex/wsl-codex-session-bridge-script.ts
  • src/main/codex/wsl-codex-session-bridge.test.ts
  • src/main/codex/wsl-codex-session-bridge.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.

Walkthrough

The changes add pending-thread healing and a WSL invocation builder to session-index healing. The WSL bridge script creates and reports rollout markers. The background WSL bridge opens the managed home index, reads pending markers from sync results, heals identified threads, and removes markers for settled threads. The changes also add tests for these workflows, summary parsing, and shutdown behavior.

Priority: Normal

Merge Risk: Minimal · up to da7bc

No merge-blocking issue is established; normal validation can proceed.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 24 functions across 11 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title is concise, specific, and accurately describes the main WSL Codex indexing change.
Description check Passed The description provides a clear ELI5 summary, root cause, implementation details, rationale, testing results, trade-offs, and risk assessment. Several template headings and checklist fields are not i…
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.
Full details: Description check

Explanation

The description provides a clear ELI5 summary, root cause, implementation details, rationale, testing results, trade-offs, and risk assessment. Several template headings and checklist fields are not included, but the required substantive information is mostly present.

Finishing Touches: 💡 1
📝 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.

@nwparker
nwparker merged commit 220d56f into main Oct 25, 2026
40 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.

2 participants