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(orcad): keep the Codex PATH scan off WSL readiness - #35718
When Orca starts its background server inside a WSL distro, it checks early on whether Codex is installed. If Codex isn't installed in the distro, Orca then also checks whether only a Windows copy exists. That second check looks in every Windows folder on the distro's PATH, and it ran twice before the server reported itself ready. On a machine with many Windows PATH folders, those lookups are slow right after the distro starts. This PR moves the startup check to just after the server is ready, and does the Windows-folder search once instead of twice.
User risk: low.
Codex launches still wait for Codex's hook answer exactly as before. If a launch arrives before readiness, it releases the deferred startup check immediately rather than waiting for it.
SSH hosts and the desktop resolve commands exactly as before. With no Windows drives mounted, nothing is cached.
What Changed
Before: a WSL server had to wait for both Codex lookups before it reported ready. Each lookup stats every Windows-drive PATH folder when Codex isn't installed in the distro.
After:
Deferred startup work.startCodexHooks accepts an optional startAfter promise. orcad passes a promise that settles once readiness is published, so the startup hash lookup and the startup hook reconcile run after readiness.
Any launch-triggered reconcile (reconcileCodexHooks and reconcileCodexHooksForLaunch) releases the deferred startup run right away, so a launch never waits on readiness. It still waits for PATH hydration, as before.
The desktop passes nothing, so it behaves as it did.
Remembered Windows-copy check. On a WSL-host orcad, resolveGuestNativeProgram remembers the "is there a Windows copy?" answer for 30 seconds, keyed by command, PATH, home and mounts.
Only the Windows-drive search is remembered. The search inside the distro still runs on every call, so a Codex installed in the distro is picked up immediately.
The memory is capped at 32 entries.
Why
On the shared Windows test box (48 of 58 PATH entries on Windows drives, first run after the distro restarts), these two lookups cost about 110–120 ms of blocking work before readiness, out of about 700 ms in total.
In the real-WSL CI lane (run 40817830493), the same lookup costs only 1–2 ms, because those distros have few Windows PATH folders. So this helps developer machines with large Windows PATHs, not the CI number.
Alternatives considered:
Drop the Windows-copy check from the hook lookup. That would change the user-facing "installed only on Windows" message, so I kept the check and remembered its answer instead.
Delay the startup lookup with a fixed timer. That would make an early Codex launch wait. Releasing on the first launch avoids this.
Linked Issue
N/A (maintainer change)
Visual Proof
N/A: no UI change. This only changes when background startup work runs.
Testing
I manually tested these changes locally. CPU profiles of orcad started cold in a WSL distro on the shared Windows box showed both lookups before readiness, about 110–120 ms of blocking stat calls on Windows-drive PATH folders.
Automated tests added/updated:
codex-hook-reconcile.test.ts:
the startup lookup and reconcile wait for startAfter;
a launch never waits for startAfter, and still converts an older build's entries.
wsl-guest-native-program.test.ts:
one Windows-drive search serves repeated calls;
a later install inside the distro is still found;
the answer is re-checked after 30 seconds;
nothing is cached when there are no Windows drives (SSH hosts, native Linux, macOS, the desktop).
orcad-push-startup.test.ts: orcad's startAfter is still unsettled when readiness publishes, and settles afterwards.
Ran pnpm tc, pnpm run typecheck:ci, the changed-code quality gate, the anti-slop lint, the ast-grep tests and gates, and the touched test files.
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
SSH: remote hosts run the same orcad. There, only the timing of the startup Codex lookup moves to just after readiness. Command resolution is unchanged, with no caching.
Mixed versions: nothing changes on the wire, and all changes are local to the host.
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)
Moves Codex startup work until after orcad publishes readiness and remembers Windows-copy checks for 30 seconds.
Orcad publishes readiness before its startup Codex check runs.
WSL hosts reuse recent results from the Windows-copy search.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Start Codex hooks] --> B[Wait for PATH hydration]
A --> C[Wait for readiness or launch]
B --> D[Run startup lookup and reconcile]
C --> D
E[Codex launch] --> C
D --> F[Fresh native command search]
F --> G{Native copy found?}
G -->|Yes| H[Use native copy]
G -->|No| I[Use cached Windows-copy check or scan]
The reason will be displayed to describe this comment to others. Learn more.
Windows CLI escapes native-only check
If a Windows CLI is installed within 30 seconds of a cached miss, hasWindowsDriveCopy keeps returning false. With no distro install, resolveGuestNativeProgram returns the bare command instead of rejecting the Windows copy. The Pi launch path passes that command and its unchanged PATH to the version probe, which can run the Windows CLI.
Avoid caching negative answers, or ensure bare commands can only search the native PATH.
Codex hook startup now waits for PATH hydration and either Orcad readiness publication or a reconciliation request before warming the hash cache and starting startup reconciliation. WSL guest program resolution now identifies Windows-drive copies and caches verdicts per resolver, with a 30-second lifetime and a 32-entry limit.
Priority: Low
Merge Risk: Low · up to e09d5
This change moves Codex hook startup work off WSL readiness. The startup installer can still release the gate early in some configurations, which would restore part of the original delay. A cached negative lookup for a Windows Codex copy can also go stale for up to 30 seconds. Neither issue should break normal operation, but both are worth addressing or accepting knowingly.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 66.67% 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 is concise, specific, and accurately describes the primary performance change: moving the Codex PATH scan off WSL readiness.
Description check
The description is complete and closely follows the repository template. It explains the user impact, implementation, rationale, testing, platform considerations, and checklist status. The maintainer-…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Description check
Explanation
The description is complete and closely follows the repository template. It explains the user impact, implementation, rationale, testing, platform considerations, and checklist status. The maintainer-specific Linked Issue exception is used appropriately, and Visual Proof is marked N/A with a reason.
Full details: Docstring Coverage
Explanation
Docstring coverage is 66.67% 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 6 functions across 7 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.
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: 8fb21d5d-a8db-4beb-b5bb-41887dca1bd7
Commits
Reviewing files that changed from the base of the PR and between 300b241 and 8c46e7b.
Files selected for processing: 7
src/main/codex/codex-hook-reconcile.test.ts
src/main/codex/codex-hook-reconcile.ts
src/main/ipc/wsl-guest-native-program.test.ts
src/main/ipc/wsl-guest-windows-drive-path.ts
src/main/orcad/orcad-entry.ts
src/main/orcad/orcad-managed-agent-hooks.ts
src/main/orcad/orcad-push-startup.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.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Performance & Scalability · Quick win
Release the startup gate only for launch reconciliation.
The background managed-hook install can call CodexHookService.reconcileHooks(), which calls reconcileCodexHooks({ convertOlderForms: true }). If that call occurs before readiness publication, this unconditional release bypasses startAfter. The Codex PATH scan can then block WSL readiness again. Release the gate for a launch request, not for every reconciliation request. (raw.githubusercontent.com)
set -o pipefail
printf'%s\n''--- structured launch acquisition ---'
nl -ba src/main/codex/codex-structured-session-acquire.ts | sed -n '100,150p'printf'%s\n''--- app-server spawn consumer ---'
nl -ba src/main/codex/codex-app-server-session.ts | sed -n '1,125p'printf'%s\n''--- Claude structured launch consumer ---'
nl -ba src/main/claude/claude-structured-launch-resolution.ts | sed -n '120,215p'
nl -ba src/main/claude/structured/claude-structured-session-acquisition.ts | sed -n '175,215p'printf'%s\n''--- cache-related tests and contract references ---'
nl -ba src/main/ipc/wsl-guest-native-program.test.ts | sed -n '35,105p'
rg -n -F --glob '*.ts' -e 'WINDOWS_ONLY_AGENT_CLI_DIR' -e 'resolveGuestNativeAgentCommand' -e 'guestNativeSpawnEnv' src/main
Repository: stablyai/orca
Length of output: 22186
Script executed:
set -o pipefail
printf'%s\n''--- provider child environment ---'
nl -ba src/main/provider-process/provider-process-launch.ts | sed -n '1,180p'printf'%s\n''--- managed provider environment flow ---'
nl -ba src/main/provider-process/managed-provider-process.ts | sed -n '1,180p'printf'%s\n''--- codex app-server process spawn type ---'
nl -ba src/main/codex/codex-app-server-process-tree-kill.ts | sed -n '1,130p'
Repository: stablyai/orca
Length of output: 13314
Do not reuse a cached negative Windows-copy verdict.
If a Windows copy appears within the 30-second TTL, resolveGuestNativeProgram can return the bare command. The structured Codex launch keeps the original PATH, and the provider environment helper does not filter Windows-drive entries. The child spawn can therefore select the new Windows copy.
Suggested fix
@@
const now = Date.now()
const known = verdicts.get(key)
- if (known && now - known.checkedAt < WINDOWS_COPY_VERDICT_TTL_MS) {- return known.windowsOnly+ if (known?.windowsOnly && now - known.checkedAt < WINDOWS_COPY_VERDICT_TTL_MS) {+ return true
}
const windowsOnly = isAbsolute(resolve(command, options))
+ if (!windowsOnly) {+ return false+ }
if (verdicts.size >= WINDOWS_COPY_VERDICT_LIMIT) {
verdicts.clear()
}
verdicts.set(key, { windowsOnly, checkedAt: now })
return windowsOnly
orcad's startup Codex hook lookup and reconcile now wait for readiness to
publish (a launch still releases them at once), and the WSL Windows-copy
check reuses a recent verdict for the same PATH instead of re-statting
every Windows-drive PATH entry on each call.
Defer the Codex startup reconcile until readiness is published.
A Codex command override can satisfy startup presence detection, but reconciliation resolves the separate guest-native codex command. On WSL-host orcad, that path checks Windows-drive PATH entries. The startup reconcile can release startCodexHooks before readiness publication. Keep the early release for reconcileCodexHooksForLaunch().
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: 1cd7e871-ca1d-4cd4-8ff1-44aaf5b69191
Commits
Reviewing files that changed from the base of the PR and between 8c46e7b and e09d58a.
Files selected for processing: 2
src/main/orcad/orcad-entry.ts
src/main/orcad/orcad-managed-agent-hooks.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.
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
When Orca starts its background server inside a WSL distro, it checks early on whether Codex is installed. If Codex isn't installed in the distro, Orca then also checks whether only a Windows copy exists. That second check looks in every Windows folder on the distro's PATH, and it ran twice before the server reported itself ready. On a machine with many Windows PATH folders, those lookups are slow right after the distro starts. This PR moves the startup check to just after the server is ready, and does the Windows-folder search once instead of twice.
User risk: low.
What Changed
Before: a WSL server had to wait for both Codex lookups before it reported ready. Each lookup stats every Windows-drive PATH folder when Codex isn't installed in the distro.
After:
startCodexHooksaccepts an optionalstartAfterpromise. orcad passes a promise that settles once readiness is published, so the startup hash lookup and the startup hook reconcile run after readiness.reconcileCodexHooksandreconcileCodexHooksForLaunch) releases the deferred startup run right away, so a launch never waits on readiness. It still waits for PATH hydration, as before.resolveGuestNativeProgramremembers the "is there a Windows copy?" answer for 30 seconds, keyed by command, PATH, home and mounts.Why
On the shared Windows test box (48 of 58 PATH entries on Windows drives, first run after the distro restarts), these two lookups cost about 110–120 ms of blocking work before readiness, out of about 700 ms in total.
Alternatives considered:
Linked Issue
N/A (maintainer change)
Visual Proof
N/A: no UI change. This only changes when background startup work runs.
Testing
codex-hook-reconcile.test.ts:startAfter;startAfter, and still converts an older build's entries.wsl-guest-native-program.test.ts:orcad-push-startup.test.ts: orcad'sstartAfteris still unsettled when readiness publishes, and settles afterwards.pnpm tc,pnpm run typecheck:ci, the changed-code quality gate, the anti-slop lint, the ast-grep tests and gates, and the touched test files.Review
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)