You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(codex): resolve the Codex CLI once per spawn recheck, off the main thread on Windows - #35967
Every time a terminal opened, Orca looked up where the Codex CLI lives so it could check its hooks. It searched PATH and install folders twice, synchronously, on the main thread. That cost about 61 ms per spawn on Windows. Now it looks once, and on Windows the search no longer blocks the main thread.
What Changed
Look up once: each Codex hook reconcile resolves the path once (resolveAppCodexPath) and passes it to both resolveCodexHookAnswer and readKnownCodexHookAnswer. This applies on every platform.
Off the main thread on Windows: the spawn-time recheck uses a new async resolver on win32 only (resolveCodexCommandForSpawn in src/main/codex-cli/command.ts). macOS and Linux keep the sync resolver, which takes under 1 ms, with half the scans.
One shared lookup: new src/shared/cli-fs-reads.ts expresses each filesystem read as a step, with a sync runner and an async (fs/promises) runner. node-cli-command-resolution.ts and nvm-version-directories.ts drive one cliCommandLookup walk (PATH, then nvm, then install folders) through either runner, so the sync and async results can't diverge. The async path makes no sync filesystem calls.
No lost rechecks:codex-hook-reconcile.ts sets a findingCodexAnswer flag while it resolves the path, waits up to 500 ms on the probe, and reads the saved answer. A spawn that arrives during that time gets one coalesced trailing rerun. This keeps the async scan from dropping a spawn's recheck, for example when Codex is installed or moved mid-scan.
No throttle and no cache: hooks are still rechecked immediately on every spawn, and PATH changes are picked up on the next one.
Why
Main-thread CPU per spawn on macOS (process.threadCpuUsage, 3 rounds):
Case
main
this PR
Codex missing, 69 PATH dirs
0.98 ms
0.45–0.51 ms
Codex missing, 95 dirs
1.35–1.44 ms
0.64–0.73 ms
Codex present
0.024 ms
0.024–0.026 ms
On Windows, the reporter's profile showed about 61 ms blocked per spawn (1,103 ms over 18 spawns). That is now an async scan plus a few small sync calls (fingerprintCodex). I haven't measured on Windows.
Per #27143, this is a free win on macOS and Linux and a substantial one on Windows.
…in thread on Windows
Every native terminal spawn schedules a Codex hook reconcile, which resolved
the Codex path twice with a synchronous stat scan of PATH and install dirs
(~50ms main-process block per spawn on Windows with a long PATH and no Codex).
The reconcile now resolves the path once and passes it to both the live
lookup and the saved-answer read. On Windows, where each stat is slow, that
lookup runs every read (PATH candidates, nvm dirs and aliases, install dirs)
through fs/promises; macOS and Linux keep the sync scan, now run once. Sync
and async share one lookup that yields its reads, so they cannot diverge.
Hook rechecks stay immediate on every spawn and nothing is cached. A spawn
that lands before a run's hook-file pass (while it is still finding Codex or
waiting for its answer) gets one trailing rerun, so an install or upgrade
that moved Codex mid-run cannot leave hooks unchecked.
Fixes#35565
Co-authored-by: Chad Tolkien <[email protected]>
The PR shares one resolved Codex path across each hook recheck and moves Windows filesystem searches off the main thread.
Codex hook rechecks reuse one path and run Windows searches asynchronously.
CLI searches can run asynchronously without changing how they choose a command.
No actionable issues were found.
Known limitation acknowledged by nwparker: a binary move during the trust-config queue wait is not rechecked. That behavior is unchanged.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Native pane spawn] --> B{Recheck running?}
B -->|No| C[Resolve Codex path once]
B -->|Still finding answer| D[Request one trailing pass]
B -->|Writing hook files| E[Use current pass]
C --> F{Windows?}
F -->|Yes| G[Async filesystem reads]
F -->|No| H[Sync filesystem reads]
G --> I[Ask Codex using resolved path]
H --> I
I --> J[Wait up to 500 ms for answer]
J --> K[Use live or saved answer]
K --> L[Recheck hook files]
L --> M{Trailing pass requested?}
M -->|Yes| C
M -->|No| N[Done]
The change adds asynchronous CLI command lookup and updates Codex hook reconciliation to use a spawn-specific path. Reconciliation passes the resolved path to both live and saved-answer lookups. It can request another pass while answer lookup is in progress. Tests cover command lookup behavior and Codex binaries appearing or moving during a scan.
Priority: Normal
Severity of issue fixed: Medium
Merge Risk: Low · up to 6e452
Windows Codex launches can still briefly block while locating the CLI. This is a bounded performance concern, so the change is mergeable with owner awareness.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 29.41% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta…
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 4 passed
Check name
Status
Explanation
Title check
The title clearly and concisely describes the main changes: resolving the Codex CLI once per spawn recheck and moving Windows resolution off the main thread.
Description check
The description is mostly complete. It includes ELI5, What Changed, Why, a linked issue, visual proof, testing details, AI disclosure, and relevant performance and compatibility notes. The Review sect…
Linked Issues check
Issue #35565 requires reducing repeated synchronous Codex path-resolution cost during local terminal spawns. reconcileOnce now calls resolveAppCodexPath() once and passes that path to both hook-an…
Out of Scope Changes check
The changed production files implement the #35565 path-resolution and reconciliation behavior. The shared filesystem-read protocol, nvm directory helper, parity tests, and reconciliation regression te…
Full details: Description check
Explanation
The description is mostly complete. It includes ELI5, What Changed, Why, a linked issue, visual proof, testing details, AI disclosure, and relevant performance and compatibility notes. The Review section is empty, and manual testing and several checklist items remain unchecked, but these omissions do not make the description incomplete.
Full details: Linked Issues check
Explanation
Issue #35565 requires reducing repeated synchronous Codex path-resolution cost during local terminal spawns. reconcileOnce now calls resolveAppCodexPath() once and passes that path to both hook-answer operations. resolveCodexCommandForSpawn() uses resolveCliCommandAsync('codex') on Windows and preserves the synchronous resolver on other platforms. The shared lookup uses one PATH, nvm, and install-directory flow for sync and async reads. The reconciliation tests cover coalesced trailing reruns, installation during lookup, and binary movement during probing. The async resolver tests cover Windows ordering, fallback behavior, parity, and absence of synchronous filesystem reads.
Full details: Out of Scope Changes check
Explanation
The changed production files implement the #35565 path-resolution and reconciliation behavior. The shared filesystem-read protocol, nvm directory helper, parity tests, and reconciliation regression tests support that implementation. The changes do not establish unrelated feature work or a separate sync-scan objective.
Full details: Docstring Coverage
Explanation
Docstring coverage is 29.41% which is insufficient. The required threshold is 80.00%. 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 17 functions across 14 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Use the asynchronous Codex path lookup for launch preparation.
The native launch-preparation path reaches resolveCodexHookAnswerForLaunch() without a path. This invokes synchronous resolveCodexCommand() on Windows for each local launch. reconcileCodexAccountHomeHook() also falls back to readKnownCodexHookAnswer() without a path.
Resolve one path with resolveAppCodexPath() and pass it to both the live lookup and the saved-answer read. Keep the launch wait timeout around the asynchronous lookup.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
Every time a terminal opened, Orca looked up where the Codex CLI lives so it could check its hooks. It searched PATH and install folders twice, synchronously, on the main thread. That cost about 61 ms per spawn on Windows. Now it looks once, and on Windows the search no longer blocks the main thread.
What Changed
resolveAppCodexPath) and passes it to bothresolveCodexHookAnswerandreadKnownCodexHookAnswer. This applies on every platform.resolveCodexCommandForSpawninsrc/main/codex-cli/command.ts). macOS and Linux keep the sync resolver, which takes under 1 ms, with half the scans.src/shared/cli-fs-reads.tsexpresses each filesystem read as a step, with a sync runner and an async (fs/promises) runner.node-cli-command-resolution.tsandnvm-version-directories.tsdrive onecliCommandLookupwalk (PATH, then nvm, then install folders) through either runner, so the sync and async results can't diverge. The async path makes no sync filesystem calls.codex-hook-reconcile.tssets afindingCodexAnswerflag while it resolves the path, waits up to 500 ms on the probe, and reads the saved answer. A spawn that arrives during that time gets one coalesced trailing rerun. This keeps the async scan from dropping a spawn's recheck, for example when Codex is installed or moved mid-scan.Why
Main-thread CPU per spawn on macOS (
process.threadCpuUsage, 3 rounds):On Windows, the reporter's profile showed about 61 ms blocked per spawn (1,103 ms over 18 spawns). That is now an async scan plus a few small sync calls (
fingerprintCodex). I haven't measured on Windows.Per #27143, this is a free win on macOS and Linux and a substantial one on Windows.
Linked Issue
Fixes #35565
Takes over #35622 by @ctolkien, credited as co-author. Changes from that PR:
Visual Proof
N/A: no UI change.
Testing
Windows parity test runs on any OS with
platform: 'win32'. It checks:.cmd→.exe→.batA test where every
*Synccall throws still resolves via the async path.Regression tests:
Touched tests: 308 files / 3,072 tests pass.
pnpm tc:nodepasses.pnpm check:changed --maxWorkers=2: 24/24 checks pass.Adversarial review by Opus and Codex (gpt-6.1-sol, xhigh), three rounds:
One caveat exists on main and isn't changed here: a binary move that lands during the trust-config queue wait is still not rechecked.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Co-authored-by: Chad Tolkien [email protected]
🤖 Generated with Claude Code