Skip to content

perf(orcad): keep the Codex PATH scan off WSL readiness - #35718

Merged
nwparker merged 2 commits into
mainfrom
nwparker/orcad-codex-lookup-after-ready
Oct 29, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/orcad-codex-lookup-after-ready

Conversation

@nwparker

@nwparker nwparker commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​100 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​98
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​73 $\color{#cf222e}{\Huge{\mathbf{−}}}$​8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​65

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.

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

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect Orcad startup timing and command lookup on WSL hosts.

The PR still needs the previously reported Windows-only command escape fixed before merging.

Findings

  1. P1 Windows CLI escapes native-only check ▶

Summary

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]
Loading

Reviews (2) · Last reviewed commit: "refactor(orcad): hand readiness to manag..." · Reviewed by Greptile

Comment on lines +161 to +162
if (known && now - known.checkedAt < WINDOWS_COPY_VERDICT_TTL_MS) {
return known.windowsOnly

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

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: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning 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 Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title is concise, specific, and accurately describes the primary performance change: moving the Codex PATH scan off WSL readiness.
Description check Passed 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 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 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.

❤️ 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: 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.


/** Concurrent calls request another pass; reconciliation failures are logged. */
export function reconcileCodexHooks(request: ReconcileRequest = {}): Promise<void> {
releaseStartup?.()

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.

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)

Comment on lines +161 to +162
if (known && now - known.checkedAt < WINDOWS_COPY_VERDICT_TTL_MS) {
return known.windowsOnly

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.

Minor · Functional Correctness · Quick win

Supported by static analysis

Script executed:

sed -n '1,195p' src/main/ipc/wsl-guest-windows-drive-path.ts
rg -n 'resolveGuestNativeProgram\(' src/main

Repository: stablyai/orca

Length of output: 8623


Script executed:

set -o pipefail
printf '%s\n' '--- PR diff ---'
git diff --unified=80 912ba1c51bc5013be68be2312fe414c02381cca3 8c46e7bcab35f72d67c2a2614872e6bec96f385a -- src/main/ipc/wsl-guest-windows-drive-path.ts src/main/native-chat/structured-agent-command-resolution.ts src/main/codex-cli/command.ts src/main/ipc/wsl-guest-native-program.test.ts src/main/native-chat/structured-agent-command-guest-path.test.ts
printf '%s\n' '--- resolver definition and related exports ---'
rg -n -F --glob '*.ts' -e 'export function resolveCliCommand' -e 'function resolveCliCommand' -e 'resolveCliCommand' src/shared src/main | head -200
printf '%s\n' '--- direct callers and surrounding owners ---'
sed -n '1,180p' src/main/native-chat/structured-agent-command-resolution.ts
sed -n '1,180p' src/main/codex-cli/command.ts
printf '%s\n' '--- spawn and PATH-related references in caller files ---'
rg -n -F --glob '*.ts' -e 'spawn(' -e 'spawnSync(' -e 'execFile(' -e 'guestNativeSpawnEnv' -e 'guestNativePathEnv' -e 'structuredAgentCommand' -e 'resolveStructuredAgentCommand' src/main/native-chat src/main/codex-cli src/main/ipc

Repository: stablyai/orca

Length of output: 41837


Script executed:

set -o pipefail
printf '%s\n' '--- shared resolver ---'
sed -n '1,340p' src/shared/node-cli-command-resolution.ts
printf '%s\n' '--- structured resolution ---'
nl -ba src/main/native-chat/structured-agent-command-resolution.ts | sed -n '1,180p'
printf '%s\n' '--- codex command wrapper ---'
nl -ba src/main/codex-cli/command.ts | sed -n '1,180p'
printf '%s\n' '--- exact callers of structured resolution ---'
rg -n -F --glob '*.ts' -e 'resolveStructuredAgentCommand' -e 'resolveAgentCommand' -e 'structuredAgentCommand' src/main
printf '%s\n' '--- direct command wrapper consumers ---'
rg -n -F --glob '*.ts' -e 'from '../codex-cli/command'' -e 'from './codex-cli/command'' -e 'from '../../main/codex-cli/command'' -e 'resolveCodexCommand' -e 'resolveClaudeCommand' src/main src/shared

Repository: stablyai/orca

Length of output: 41757


Script executed:

set -o pipefail
printf '%s\n' '--- complete codex command wrapper ---'
nl -ba src/main/codex-cli/command.ts | sed -n '1,90p'
printf '%s\n' '--- non-test structured resolver callers ---'
rg -n -F --glob '*.ts' -g '!*.test.ts' -g '!*.spec.ts' 'resolveStructuredAgentCommand' src/main
printf '%s\n' '--- all guest-native environment uses ---'
rg -n -F --glob '*.ts' -g '!*.test.ts' -g '!*.spec.ts' -e 'guestNativeSpawnEnv' -e 'guestNativePathEnv' src/main
printf '%s\n' '--- structured launch resolution and env construction ---'
nl -ba src/main/codex/codex-structured-launch-resolution.ts | sed -n '1,180p'
nl -ba src/main/claude/claude-structured-child-env.ts | sed -n '1,130p'
printf '%s\n' '--- likely launch consumers ---'
rg -n -F --glob '*.ts' -g '!*.test.ts' -g '!*.spec.ts' -e 'resolveCommand(' -e 'command:' -e 'env:' src/main/codex src/main/claude src/main/runtime/agent* src/main/native-chat | head -300

Repository: stablyai/orca

Length of output: 41216


Script executed:

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.
@nwparker
nwparker force-pushed the nwparker/orcad-codex-lookup-after-ready branch from 8c46e7b to e09d58a Compare October 29, 2026 06:06

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Minor · Defer the Codex startup reconcile until readiness is… · orcad-managed-agent-hooks.ts:47-48

src/main/orcad/orcad-managed-agent-hooks.ts:47-48
🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win

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.

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.

1 participant