Repository navigation
[P2] perf(windows): stop the capability poll respawning blocking wsl.exe probes - #11698
Conversation
Greptile SummaryThis PR fixes a session-long
Confidence Score: 5/5Safe to merge; the async probe twins correctly share caches and backoff with their sync counterparts, the renderer watcher parks cleanly, and the full test suite covers the key regression paths. All functional changes — async probe deduplication, failure classifier fixes for both execFileSync and execFile error shapes, the backoff/park watcher — are well-covered by the new test suite. The only gaps are cosmetic: the windowsHide option claimed in the description is missing from two spawns, and the attempt field is redundant with unchangedStreak. Neither affects correctness. Files Needing Attention: src/main/wsl-availability.ts and src/main/pwsh.ts — the two async spawn sites that are missing windowsHide: true.
|
| Filename | Overview |
|---|---|
| src/renderer/src/lib/windows-terminal-capability-reprobe.ts | New shared backoff/park watcher replacing the per-consumer setInterval; logic is sound — both attempt and unchangedStreak are always incremented/reset together (effectively redundant), and the focus-guard correctly drops signals within 30s of the last probe to prevent churn. |
| src/main/wsl-availability.ts | New async twin of isWslAvailable; deduplication via wslAvailabilityProbeInFlight is correct; isRetryableWslProbeFailure correctly handles both execFileSync (numeric status) and execFile callback (numeric code) shapes; windowsHide option absent from probeWslStatus. |
| src/main/pwsh.ts | isTimeoutError correctly handles both execFileSync ETIMEDOUT and execFile SIGTERM kill shapes; isPwshAvailableAsync deduplicates via pwshProbeInFlight; warmPwshAvailabilityCache uses a separate in-flight to avoid mixing 5s/30s timeout semantics; windowsHide option absent from the async spawn. |
| src/renderer/src/lib/windows-terminal-capabilities.ts | reprobe.stop null-safety on fast unmount is correctly handled via the cancelled flag; startWindowsTerminalCapabilityReprobe is only called after the first load resolves and only for local non-SSH targets. |
| src/main/wsl.ts | Availability cache and async twin cleanly extracted to wsl-availability.ts; re-exports preserve all existing callers; listWslDistrosAsync lacks in-flight deduplication (acknowledged as an accepted trade-off). |
| src/main/ipc/app.ts | wsl:isAvailable, wsl:listDistros, and pwsh:isAvailable IPC handlers correctly switched from sync to async variants; gitBash:isAvailable correctly stays synchronous. |
| src/main/runtime/rpc/methods/host-capabilities.ts | RPC methods for web/mobile clients now route through async probes, matching the IPC path; isGitBashAvailable correctly stays synchronous. |
| src/relay/preflight-handler.ts | detectWindowsTerminalCapabilities now uses async probe twins; wslDistros correctly gated on wslAvailable to avoid a redundant spawn when WSL is absent. |
Sequence Diagram
sequenceDiagram
participant R as Renderer (TabBar/StatusBar)
participant W as windows-terminal-capabilities.ts
participant Reprobe as capability-reprobe.ts
participant IPC as Electron IPC
participant Main as Main Process (ipc/app.ts)
participant WSL as wsl-availability.ts
participant Pwsh as pwsh.ts
R->>W: useWindowsTerminalCapabilities()
W->>IPC: loadWindowsTerminalCapabilities()
IPC->>Main: wsl:isAvailable / wsl:listDistros / pwsh:isAvailable
Main->>WSL: isWslAvailableAsync() [deduped in-flight]
Main->>Pwsh: isPwshAvailableAsync() [deduped in-flight]
WSL-->>Main: result (cached or from wsl.exe spawn)
Pwsh-->>Main: result (cached or from pwsh.exe spawn)
Main-->>IPC: "Promise<boolean/string[]>"
IPC-->>W: WindowsTerminalCapabilities
W->>Reprobe: startWindowsTerminalCapabilityReprobe()
Note over Reprobe: arm(attempt=0) -> 30s timer
Reprobe->>Reprobe: "runProbe() at +30s (unchanged, streak=1, next=60s)"
Reprobe->>Reprobe: "runProbe() at +90s (unchanged, streak=2, next=120s)"
Reprobe->>Reprobe: "runProbe() at +210s (unchanged, streak=3 >= SETTLE, park)"
Note over Reprobe: Parked. Re-armed by window focus or new consumer mount.
R->>Reprobe: "window focus event (>30s after last probe)"
Reprobe->>Reprobe: "armRunner() -> reset streak/attempt -> 30s timer"
Reviews (8): Last reviewed commit: "perf(windows): route relay host-capabili..." | Re-trigger Greptile
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe main process now performs WSL and PowerShell availability checks asynchronously. Shared caches, retry backoff, timeout handling, generation tracking, and in-flight deduplication manage probe results. IPC, RPC, preflight, and profile handlers use asynchronous probes. The renderer replaces fixed capability polling with cancellable, shared reprobe runners that support backoff, focus-triggered rearming, cached results, and consumer lifecycle cleanup. Tests cover probe behavior, handler usage, cache behavior, reprobe scheduling, recovery, and shutdown. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 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 |
There was a problem hiding this comment.
Actionable comments posted: 4
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 1bdb4c47-bc75-4c65-b32f-9edf321c04ed
📒 Files selected for processing (12)
config/tsconfig.tc.web.jsonsrc/main/ipc/app.test.tssrc/main/ipc/app.tssrc/main/pwsh.test.tssrc/main/pwsh.tssrc/main/wsl-availability.tssrc/main/wsl.test.tssrc/main/wsl.tssrc/renderer/src/lib/windows-terminal-capabilities.test.tssrc/renderer/src/lib/windows-terminal-capabilities.tssrc/renderer/src/lib/windows-terminal-capability-reprobe.test.tssrc/renderer/src/lib/windows-terminal-capability-reprobe.ts
There was a problem hiding this comment.
Caution
Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.
Actionable comments posted: 4
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 1bdb4c47-bc75-4c65-b32f-9edf321c04ed
📒 Files selected for processing (12)
config/tsconfig.tc.web.jsonsrc/main/ipc/app.test.tssrc/main/ipc/app.tssrc/main/pwsh.test.tssrc/main/pwsh.tssrc/main/wsl-availability.tssrc/main/wsl.test.tssrc/main/wsl.tssrc/renderer/src/lib/windows-terminal-capabilities.test.tssrc/renderer/src/lib/windows-terminal-capabilities.tssrc/renderer/src/lib/windows-terminal-capability-reprobe.test.tssrc/renderer/src/lib/windows-terminal-capability-reprobe.ts
🛑 Comments failed to post (1)
src/renderer/src/lib/windows-terminal-capability-reprobe.ts (1)
125-141: 🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win
Unconditional
armRunnercall resets an active backoff schedule whenever a new consumer joins.
startWindowsTerminalCapabilityReprobecallsarmRunner(runner)every time, including when a second consumer joins a runner that is already mid-backoff (runner.timeris notnull). This restartsattempt/unchangedStreakat zero and reschedules at the 30-second base delay, discarding any backoff progress the shared schedule had made.This is not a rare edge case. The comment on
loadWindowsTerminalCapabilitiesstates that Settings, status bar, and paired web tab bars intentionally share one owner key. If the status bar stays mounted while the user repeatedly opens and closes Settings, each open resets the shared runner to the base delay, keeping the "local" owner key probing every 30 seconds indefinitely instead of backing off. This directly undermines the PR's goal of avoiding frequentwsl.exe/pwsh.exespawns on the main process.Only restart the backoff when there is no active schedule (new runner or previously parked), not on every join.
Consider adding a regression test that starts a first consumer, advances past the base delay so
attemptgrows, then starts a second consumer on the same owner key and asserts the following probe still uses the backed-off delay rather than 30 seconds. Do you want me to draft this test?🔧 Proposed fix to avoid discarding an active backoff schedule
runner.probe = options.probe runner.readCached = options.readCached runner.consumers += 1 runnersByOwnerKey.set(options.ownerKey, runner) - // A newly mounted surface is a demand signal, so restart the backoff window. - armRunner(runner) + // Restart the backoff only when no schedule is currently running (brand-new + // runner or previously parked); joining an active schedule must not discard + // its progress. + if (runner.timer === null) { + armRunner(runner) + } attachFocusListener()📝 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 runner: CapabilityReprobeRunner = runnersByOwnerKey.get(options.ownerKey) ?? { consumers: 0, timer: null, attempt: 0, unchangedStreak: 0, signature: capabilitySignature(options.readCached()), lastProbeAt: 0, probe: options.probe, readCached: options.readCached } runner.probe = options.probe runner.readCached = options.readCached runner.consumers += 1 runnersByOwnerKey.set(options.ownerKey, runner) // Restart the backoff only when no schedule is currently running (brand-new // runner or previously parked); joining an active schedule must not discard // its progress. if (runner.timer === null) { armRunner(runner) } attachFocusListener()
Review follow-up (c4e45b4)Fixed1. Sync/async probe races ( Both caches now carry a generation counter that every write bumps. A probe captures the generation when it spawns and only writes a failure if nothing has been written since; a success always wins (a zero exit is proof, and #11295 says absent must never latch). The WSL failure count is now read at write time instead of from a snapshot taken at call time. The double spawn itself is gone for WSL: Regression tests (both fail on the pre-fix code): 2. Stale probe restoring an invalidated failure ( 3. Refuted"Make the reprobe callback bypass the capability cache" ( Verification
|
|
Both blocking items verified against the branch and fixed in ade28dea4b. 1. Focus churn starved the re-probe — valid, fixed. Reproduced exactly as described. Fix is the suggested early return: 2. The TTL boundary test was inert — valid, fixed. Confirmed by the same mutation: with The test now mounts a consumer (the only state a re-probe actually runs in, so prune never fires) and derives the second timestamp from
Deliberately left
Suites run green: |
|
Thanks — the blocking finding was correct and reproduced exactly as described. Pushed Fixed: parked runner silently discarded a demand signal inside the base delay
The signal is now scheduled at Regression tests added at your suggested offsets, plus the starvation direction:
All four fail on Fixed:
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/pwsh.ts (1)
121-147: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winAdd
windowsHideto the warm-up probe'sexecFilecall.Line 135 spawns
pwsh.exewithoutwindowsHide. The sibling probe inisPwshAvailableAsync(line 107) setswindowsHide: truespecifically to prevent a background probe from flashing a console window.warmPwshAvailabilityCacheruns the same background probe and still can flash a console window on Windows.🩹 Proposed fix
const generation = pwshCacheGeneration pwshWarmupInFlight = new Promise((resolve) => { - execFile('pwsh.exe', ['-Version'], { timeout: PWSH_WARMUP_PROBE_TIMEOUT_MS }, (error) => { - pwshWarmupInFlight = null - if (!error) { - setPwshAvailabilityCache({ available: true }) - resolve(true) - return - } - cachePwshProbeFailure(error, generation) - resolve(false) - }) + execFile( + 'pwsh.exe', + ['-Version'], + { timeout: PWSH_WARMUP_PROBE_TIMEOUT_MS, windowsHide: true }, + (error) => { + pwshWarmupInFlight = null + if (!error) { + setPwshAvailabilityCache({ available: true }) + resolve(true) + return + } + cachePwshProbeFailure(error, generation) + resolve(false) + } + ) })
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 563e1370-3b80-4363-b4cf-1feb3e075fdd
📥 Commits
Reviewing files that changed from the base of the PR and between 6533811 and f178e5d81007062250a8459a441087958f125ef4.
📒 Files selected for processing (13)
src/main/providers/local-pty-provider.test.tssrc/main/providers/local-pty-provider.tssrc/main/pwsh.test.tssrc/main/pwsh.tssrc/main/runtime/rpc/methods/host-capabilities.test.tssrc/main/runtime/rpc/methods/host-capabilities.tssrc/main/wsl-availability.tssrc/main/wsl.test.tssrc/relay/preflight-handler.test.tssrc/relay/preflight-handler.tssrc/renderer/src/lib/windows-terminal-capabilities.test.tssrc/renderer/src/lib/windows-terminal-capability-reprobe.test.tssrc/renderer/src/lib/windows-terminal-capability-reprobe.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/renderer/src/lib/windows-terminal-capability-reprobe.ts
f178e5d to
6533811
Compare
Remediation backed out — branch reset to
|
3dd67a1 to
f7bea17
Compare
Correction: my earlier reset was too aggressiveThe reset I posted earlier reset this branch to its first commit, not its last reviewed-clean one. The original fix round ran 07-30 21:55–23:41; the failed remediation began 07-31 01:18. I used the wrong boundary and dropped 1–2 legitimate commits that were part of the reviewed-clean PR. The branch is now at the correct boundary — the last commit before remediation started. Apologies for the churn; the force-pushes were mine, not a tooling issue. |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/wsl-availability.ts (1)
122-145: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winAdd
windowsHideto the Windows capability probes.
src/main/wsl-availability.tsandsrc/main/pwsh.tsrunexecFileSyncfor Windows probers without hiding the console child. AddwindowsHide: trueto both sync probes sowsl.exeandpwsh.exedo not flash a terminal window on Windows.
🧹 Nitpick comments (1)
src/renderer/src/lib/windows-terminal-capability-reprobe.ts (1)
6-9: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMerge
attemptandunchangedStreak; the 5-minute cap is unreachable.
attemptandunchangedStreakchange together on every path: both increment in the "unchanged" branch (Lines 71-72), both reset in the "changed" branch (Lines 75-77), and both reset inarmRunner(Lines 108-109). No code path ever sets one without the other, so the two fields always hold the same value. Keep one counter to avoid a future edit desynchronizing them.This coupling also makes
REPROBE_MAX_DELAY_MSdead. Scheduling only continues whileunchangedStreak < REPROBE_SETTLE_STREAK(3), soscheduleNextProbenever seesattemptabove 2, giving a maximum delay of30000 * 2^2 = 120000ms. The documented 5-minute cap (Line 7) never engages under any signature-change pattern. Confirm whether the intended maximum backoff is 2 minutes (current behavior) or 5 minutes (as the constant suggests), and adjust eitherREPROBE_SETTLE_STREAKorREPROBE_MAX_DELAY_MSto match the intended cap.♻️ Proposed fix: merge the two counters
type CapabilityReprobeRunner = { consumers: number timer: ReturnType<typeof globalThis.setTimeout> | null attempt: number - unchangedStreak: number signature: string lastProbeAt: number probing: boolean rearmAfterProbe: boolean probe: () => Promise<WindowsTerminalCapabilities> readCached: () => WindowsTerminalCapabilities }if (capabilitySignature(capabilities) === runner.signature) { - runner.unchangedStreak += 1 runner.attempt += 1 } else { // A moving answer means the host is still changing; watch it closely again. runner.signature = capabilitySignature(capabilities) - runner.unchangedStreak = 0 runner.attempt = 0 } if (isSettled(capabilities)) { runner.rearmAfterProbe = false return } if (runner.rearmAfterProbe) { armRunner(runner) return } - if (runner.unchangedStreak >= REPROBE_SETTLE_STREAK) { + if (runner.attempt >= REPROBE_SETTLE_STREAK) { return } scheduleNextProbe(runner)Also applies to: 11-23, 70-92
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 892072a1-43fc-494a-a62e-b77832fe06ad
📥 Commits
Reviewing files that changed from the base of the PR and between f178e5d81007062250a8459a441087958f125ef4 and 3dd67a1.
📒 Files selected for processing (4)
src/main/wsl-availability.tssrc/main/wsl.test.tssrc/renderer/src/lib/windows-terminal-capability-reprobe.test.tssrc/renderer/src/lib/windows-terminal-capability-reprobe.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/wsl.test.ts
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/main/pwsh.ts (2)
70-103: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winHide the
pwsh.exeprobe windows.
windowsHidedefaults tofalseforchild_process.execFile, so Windows PowerShell probes can create visible child-console windows. AddwindowsHide: trueto the async probe and the warm-up probe. Also add it to the sync probe options since it is available on the Node target.
13-20: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy liftGuard the shared PowerShell cache against stale completions.
isPwshAvailable(),isPwshAvailableAsync(), andwarmPwshAvailabilityCache()each writepwshAvailableCacheindependently, whilepwshProbeInFlightandpwshWarmupInFlightprotect only shared spawns, not cache ordering. A later async completion can overwrite a newer cache entry and keep subsequent checks false until the negative-cache TTL; it can also leave stalefalseentries after a later valid probe completed in another writer.Use one shared in-flight operation or a monotonic generation guard for every cache writer, and cover both completion orders.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 4276c0d8-f966-4bed-a4c0-9d5c130fe2de
📒 Files selected for processing (10)
src/main/pwsh.test.tssrc/main/pwsh.tssrc/main/runtime/rpc/methods/host-capabilities.test.tssrc/main/runtime/rpc/methods/host-capabilities.tssrc/main/wsl-availability.tssrc/main/wsl.test.tssrc/relay/preflight-handler.test.tssrc/relay/preflight-handler.tssrc/renderer/src/lib/windows-terminal-capability-reprobe.test.tssrc/renderer/src/lib/windows-terminal-capability-reprobe.ts
🚧 Files skipped from review as they are similar to previous changes (4)
- src/main/pwsh.test.ts
- src/renderer/src/lib/windows-terminal-capability-reprobe.test.ts
- src/main/wsl.test.ts
- src/renderer/src/lib/windows-terminal-capability-reprobe.ts
…robes #11295 added a 30s renderer interval to `useWindowsTerminalCapabilities` whose early-return only fires when WSL is available with at least one distro, so on the common Windows host (no WSL) it re-ran a full capability read forever. Each read IPCs four probes whose main-process handlers were synchronous `execFileSync` calls to wsl.exe/pwsh.exe, blocking the Electron main event loop for up to 5s a time. The un-latching intent is kept: a host that answers "no WSL" is still re-checked, now on an exponential backoff (30s, +60s, +120s) that parks once the answer stops moving, re-arms on window focus, is shared by all consumers of an owner key, and stops entirely when the last consumer unmounts. The wsl/pwsh IPC handlers now use async twins that share the existing caches and back off identically.
…e error shape The async twins feed `execFile` callback errors into classifiers written for `execFileSync`: a non-zero exit lands on `error.code` as a number rather than `error.status`, and a timeout is a SIGTERM kill rather than ETIMEDOUT. So a Windows host without WSL (wsl.exe ships in System32, so it exits non-zero instead of ENOENT) was cached as retryable, shrinking the shared window from 10min to 45s and making the still-sync callers re-pay their blocking spawn ~13x more often; and a pwsh cold start past 5s cached "pwsh missing" for 30s, demoting the user's PowerShell 7 preference — the exact case the ETIMEDOUT branch exists to prevent. Also drops a literal NUL byte from the new re-probe module's signature separator, which made the file binary to git, and seeds `lastProbeAt` at registration so focus churn right after mount cannot defer the first re-probe indefinitely. Co-authored-by: Orca <[email protected]>
…sl/pwsh twins
A paired web/mobile client resolves `useWindowsTerminalCapabilities` to a local
target (TabBar's `isWebClient` gate, and `useSettingsNavigationMetadata` forces
`{kind:'local'}`), so the new re-probe arms there too. But `window.api.wsl/pwsh`
on a web client is not the ipc/app.ts channel — it is `host.wsl.*`/`host.pwsh.*`
over the runtime RPC, which still ran the sync probes and blocked the desktop
main event loop on `execFileSync('wsl.exe' | 'pwsh.exe')` for up to 5s per call.
Switch those handlers and the relay preflight capability probe to the async
twins added here; they share the same caches, dedupe and backoff, so remote
callers see no behavior change.
f7bea17 to
f07f85e
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: b68e8946-e483-4e12-939c-68380be8448f
📒 Files selected for processing (18)
config/tsconfig.tc.web.jsonsrc/main/ipc/app.test.tssrc/main/ipc/app.tssrc/main/providers/local-pty-provider.test.tssrc/main/providers/local-pty-provider.tssrc/main/pwsh.test.tssrc/main/pwsh.tssrc/main/runtime/rpc/methods/host-capabilities.test.tssrc/main/runtime/rpc/methods/host-capabilities.tssrc/main/wsl-availability.tssrc/main/wsl.test.tssrc/main/wsl.tssrc/relay/preflight-handler.test.tssrc/relay/preflight-handler.tssrc/renderer/src/lib/windows-terminal-capabilities.test.tssrc/renderer/src/lib/windows-terminal-capabilities.tssrc/renderer/src/lib/windows-terminal-capability-reprobe.test.tssrc/renderer/src/lib/windows-terminal-capability-reprobe.ts
🚧 Files skipped from review as they are similar to previous changes (10)
- config/tsconfig.tc.web.json
- src/main/ipc/app.test.ts
- src/relay/preflight-handler.test.ts
- src/renderer/src/lib/windows-terminal-capabilities.test.ts
- src/main/runtime/rpc/methods/host-capabilities.test.ts
- src/renderer/src/lib/windows-terminal-capabilities.ts
- src/renderer/src/lib/windows-terminal-capability-reprobe.test.ts
- src/main/runtime/rpc/methods/host-capabilities.ts
- src/main/pwsh.test.ts
- src/renderer/src/lib/windows-terminal-capability-reprobe.ts
…exe probes (stablyai#11698) * perf(windows): stop the capability poll respawning blocking wsl.exe probes stablyai#11295 added a 30s renderer interval to `useWindowsTerminalCapabilities` whose early-return only fires when WSL is available with at least one distro, so on the common Windows host (no WSL) it re-ran a full capability read forever. Each read IPCs four probes whose main-process handlers were synchronous `execFileSync` calls to wsl.exe/pwsh.exe, blocking the Electron main event loop for up to 5s a time. The un-latching intent is kept: a host that answers "no WSL" is still re-checked, now on an exponential backoff (30s, +60s, +120s) that parks once the answer stops moving, re-arms on window focus, is shared by all consumers of an owner key, and stops entirely when the last consumer unmounts. The wsl/pwsh IPC handlers now use async twins that share the existing caches and back off identically. * fix(windows): classify async wsl/pwsh probe failures with the execFile error shape The async twins feed `execFile` callback errors into classifiers written for `execFileSync`: a non-zero exit lands on `error.code` as a number rather than `error.status`, and a timeout is a SIGTERM kill rather than ETIMEDOUT. So a Windows host without WSL (wsl.exe ships in System32, so it exits non-zero instead of ENOENT) was cached as retryable, shrinking the shared window from 10min to 45s and making the still-sync callers re-pay their blocking spawn ~13x more often; and a pwsh cold start past 5s cached "pwsh missing" for 30s, demoting the user's PowerShell 7 preference — the exact case the ETIMEDOUT branch exists to prevent. Also drops a literal NUL byte from the new re-probe module's signature separator, which made the file binary to git, and seeds `lastProbeAt` at registration so focus churn right after mount cannot defer the first re-probe indefinitely. Co-authored-by: Orca <[email protected]> * perf(windows): route relay host-capability probes through the async wsl/pwsh twins A paired web/mobile client resolves `useWindowsTerminalCapabilities` to a local target (TabBar's `isWebClient` gate, and `useSettingsNavigationMetadata` forces `{kind:'local'}`), so the new re-probe arms there too. But `window.api.wsl/pwsh` on a web client is not the ipc/app.ts channel — it is `host.wsl.*`/`host.pwsh.*` over the runtime RPC, which still ran the sync probes and blocked the desktop main event loop on `execFileSync('wsl.exe' | 'pwsh.exe')` for up to 5s per call. Switch those handlers and the relay preflight capability probe to the async twins added here; they share the same caches, dedupe and backoff, so remote callers see no behavior change. * fix(windows): harden async capability reprobes * fix(windows): dedupe PowerShell shell probes --------- Co-authored-by: Orca <[email protected]> Co-authored-by: OrcaWin <[email protected]>
ELI5 Orca was repeatedly asking Windows “is WSL/PowerShell installed yet?” from the same Electron process that handles terminal input and IPC. On machines without WSL, mounted UI surfaces could trigger this every 30 seconds for the entire session. The checks used synchronous child processes, so a slow or hooked
wsl.exe/pwsh.exepaused Orca while each command ran; the production timeout permits a pause of up to 5 seconds. This PR keeps later-install discovery without keeping the old spawn rate: - capability reads use async child processes across desktop IPC, paired-client RPC, and relay preflight; - consumers of one local host share a single 30s → 60s → 120s backoff, then one ceiling check every 5 minutes; - window focus can bring only a ceiling check forward, never postpone a pending check, and never probe less than 30 seconds after the last one; - a usable WSL stops the watcher, and the last consumer unmounting removes it; - stable “no WSL” sessions fall from 60 checks/30 minutes per consumer to at most 9 shared reads, while WSL installed in a continuously focused Orca session is still discovered. ## What changed - Added async WSL and PowerShell availability probes that share the existing caches and in-flight work. - Routed renderer IPC, host RPC, relay preflight, distro listing,LocalPtyProvider.getProfiles(), and automatic local shell selection through async paths. - Added generation-ordered cache writes so an older async failure cannot overwrite a newer success, and distro discovery invalidates an in-flight stale availability failure. - AddedwindowsHide: trueto the new Windows child processes. - Replaced per-consumer fixed intervals with the shared bounded watcher above. - Preserved local, SSH, paired-client, and folder-workspace behavior; there is no remote wire change. ## Deterministic reproduction Before the hardening commit, six new fake-clock/deferred-callback tests failed deterministically while 58 neighboring tests passed: 1. older WSL async failure overwrote a newer synchronous success; 2. successful distro discovery was overwritten by an already-running availability failure; 3. older PowerShell async failure overwrote a newer synchronous success; 4. a second consumer reset the shared watcher’s earned backoff; 5. 25-second focus churn could defer the next probe forever; 6. a demand signal just after parking could be dropped forever. The same tests pass after the fix. The scheduler tests also pin the exact 30/60/120-second ladder, five-minute ceiling, 30-second focus floor, shared-consumer behavior, teardown, and stop-on-usable-WSL behavior. ## Native Windows benchmark Environment: native Windows,wsl.exepresent but no installed distro. Six-block ABBA run, 12 sync and 12 async samples per exact command. “Gap” is event-loop delay; the async baseline is approximately one 16 ms timer tick. | Command | Sync median / p95 gap | Async median / p95 gap | | --- | ---: | ---: | |wsl.exe --status| 34.1 / 63.5 ms | 16.1 / 16.4 ms | |wsl.exe --list --quiet| 35.1 / 37.3 ms | 16.0 / 25.5 ms | |pwsh.exe -Version| 103.0 / 312.9 ms | 18.9 / 25.8 ms | This shows the synchronous path delays the event loop for the command’s duration, while the async path stays near the timer baseline. Machines with slow security hooks or wedged WSL can amplify the old pause up to the 5-second timeout. ## Verification Green locally: - 188/188 focused WSL, PowerShell, watcher, capability-hook, and local-PTY tests - 99/99 IPC, host-RPC, relay-preflight, local/SSH ownership, settings, and Windows tab-launch tests - 624/627 broader direct-consumer tests; the three failures reproduce in files identical toorigin/mainand are existing native-Windows PTY fixture assumptions (POSIX path expectations and unrelated Codex resume provenance) -pnpm typecheck-pnpm exec oxlint --format github- native and type-aware code-quality audits - reliability-gate and max-lines ratchets - changed-file formatting andgit diff --checkA repository-widepnpm testrun was inconclusive: it produced no test output before the explicit 10-minute local timeout. PR CI remains the authoritative full-shard run. ## Tradeoffs - A stable unavailable host still performs a shared async ceiling read every five minutes. This is deliberate: permanent parking would misswsl --installcompleted while Orca remains focused. - Focus can accelerate ceiling reads, but the 30-second floor bounds churn. - Async WSL availability and distro reads may overlap instead of serially blocking the main loop. -getProfiles()may await a slow WSL result for up to the existing timeout, but it no longer freezes Electron while waiting. Regression source: #11295 changed absent-WSL detection from a process-lifetime latch to a 30-second renderer poll without first moving the underlying Windows probes off the main event loop.