Repository navigation
fix(windows): make the GPU fallback actually remove the GPU child, and stop WSL latching absent - #11295
Conversation
📝 WalkthroughWalkthroughWindows GPU fallback now applies platform-specific switches through a reusable helper, records applied switches in crash breadcrumbs, and persists fallback state after restart selection. WSL distro and availability detection add shared parsing, retry backoff, concurrent-probe protection, structured cache handling, and expanded tests. Renderer terminal capability reads reconcile contradictory WSL results and periodically refresh eligible local consumers. Documentation updates describe the revised WSL cache semantics. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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: 2
🧹 Nitpick comments (3)
src/main/wsl.ts (2)
327-333: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winNarrow by discriminant instead of casting.
The cast assumes the remaining variant is the failure shape, but
{ available: false, unsupported: true }also reaches here when the platform re-check flips towin32. It happens to work (Date.now() - undefinedisNaN, so freshness is false and a real probe runs), yet the correctness rests on NaN comparison semantics rather than the type.♻️ Suggested narrowing
function isWslAvailabilityCacheFresh(cache: WslAvailabilityCache): boolean { if (isPermanentWslAvailabilityCache(cache)) { return true } - const failed = cache as { cachedAt: number; retryable: boolean; failures: number } - return Date.now() - failed.cachedAt < wslAvailabilityRetryDelayMs(failed) + if (!('cachedAt' in cache)) { + return false + } + return Date.now() - cache.cachedAt < wslAvailabilityRetryDelayMs(cache) }
188-191: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winDistro-list failures bypass the backoff that empty results get. Both catch paths arm a flat
WSL_DISTRO_LIST_RETRY_DELAY_MSwindow and leavewslDistroListEmptyStreakuntouched, so a persistently wedgedwsl.exeis re-spawned every 15s for the whole session — the exact cost the empty-result doubling andwslAvailabilityRetryDelayMswere introduced to bound. Route both through the same streak/backoff arithmetic.
src/main/wsl.ts#L188-L191: replace the flatDate.now() + WSL_DISTRO_LIST_RETRY_DELAY_MSassignment with a shared helper that advances the streak and applies the capped doubling (this path is the blockingexecFileSyncon the main process, so it matters most).src/main/wsl.ts#L211-L214: call the same helper instead of duplicating the flat-window assignment.src/main/wsl.test.ts (1)
383-423: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueExtract the repeated timeout-error fixture.
The
spawnSync ETIMEDOUTobject and its explanatory comment are duplicated four times in this suite (Lines 385-392, 409-416, 440-447, 493-499). A singlewslProbeTimeoutError()factory keeps the shape in one place.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: fec71321-3147-4ec1-b393-916da4761faf
📒 Files selected for processing (6)
docs/agent-status-over-wsl.mdsrc/main/index.tssrc/main/startup/gpu-fallback-switches.test.tssrc/main/startup/gpu-fallback-switches.tssrc/main/wsl.test.tssrc/main/wsl.ts
| } catch { | ||
| wslDistroListFailedUntilMs = Date.now() + WSL_DISTRO_LIST_FAILURE_TTL_MS | ||
| return [] | ||
| wslDistroListRetryAfterMs = Date.now() + WSL_DISTRO_LIST_RETRY_DELAY_MS | ||
| return wslDistroCache ?? [] | ||
| } |
There was a problem hiding this comment.
Catch block can truncate a longer backoff window set by
cacheWslDistroList
When listWslDistrosAsync is called concurrently without in-flight deduplication (acknowledged follow-up), the async catch path always writes Date.now() + WSL_DISTRO_LIST_RETRY_DELAY_MS (15 s) to wslDistroListRetryAfterMs, regardless of what value cacheWslDistroList may have just written. If the empty-streak backoff has grown beyond 15 s (e.g., wslDistroListEmptyStreak = 3 → 60 s window) and one concurrent probe resolves with an empty list while a sibling throws, the sibling's catch will overwrite the longer window with 15 s, causing an earlier re-probe than the backoff table prescribes. The practical effect is one extra blocking wsl.exe --list call on docker-desktop-only machines; the distro data itself remains correct. The same race exists in listWslDistros's catch block at line 189.
Greptile SummaryThis PR fixes two independent Windows-only bugs: the GPU child process was not actually removed by the previous fallback (only its backend changed), and WSL availability/distro state was latched permanently on first failure, hiding WSL from the terminal picker after provisioning or a cold boot.
Confidence Score: 5/5Safe to merge — both the GPU fallback and WSL cache fixes address real, measured production defects with targeted, well-tested changes. The GPU fallback marker-ordering fix is structurally correct: marker write is gated behind explicit user consent and a successful file write, so neither Keep Running nor a dialog error can silently engage Safe Graphics Mode. The WSL cache refactor sequence-number scheme for out-of-order async probe results, the armWslDistroListRetry early-return guard preventing concurrent catches from shortening a longer backoff window, and dropStaleWslAvailabilityFailure clearing the availability latch on successful distro discovery all hold up under the test matrix of 138 cases. No logic errors or correctness gaps were found. Files Needing Attention: No files require special attention. src/main/wsl.ts is the most intricate file (sequence numbers + two independent backoff tables) but is backed by the most thorough tests.
|
| Filename | Overview |
|---|---|
| src/main/wsl.ts | Major refactor: distro-list and availability caches now use bounded exponential backoff instead of process-lifetime latching. Sequence numbers prevent out-of-order async probes from overwriting newer non-empty results. dropStaleWslAvailabilityFailure correctly reconciles a stale availability failure when a distro list succeeds. |
| src/main/index.ts | Correct fix: writeGpuFallbackMarker now called only after user explicitly chooses restart, preventing the marker from being written on Keep Running or dialog errors. GPU fallback switches extracted to applyGpuFallbackCommandLineSwitches and applied switch names recorded in the crash breadcrumb. |
| src/main/startup/gpu-fallback-switches.ts | New file extracting the three GPU fallback switches into a testable unit; Windows-only guard is correct. Return value enables the breadcrumb in index.ts. |
| src/renderer/src/lib/windows-terminal-capabilities.ts | Adds a 30-second periodic refresh interval to the local-only path that fires until both wslAvailable and wslDistros.length > 0 are satisfied; interval is correctly cleared on unmount. SSH and remote targets are excluded. |
| src/renderer/src/lib/windows-terminal-capability-read.ts | Adds reconcileWslAvailability to handle the race where the parallel availability probe read a stale negative while the distro probe succeeded; re-probes only when !available && distros.length > 0. |
| src/main/wsl-distro-retry.ts | Tiny helper for the exponential-backoff formula (15s x 2^(streak-1), capped at 5 min). Extracted for testability. |
| src/main/wsl-distro-list-output.ts | Extracted parseWslDistros (NUL-stripping + line splitting) and filterUserWslDistros (docker-desktop exclusion) from wsl.ts for independent testing. |
| src/main/crash-reporting/gpu-fallback-restart-prompt.ts | Dialog text updated to Restart in Safe Graphics Mode with accurate description of what the mode disables; matched by the test. |
Reviews (3): Last reviewed commit: "fix(wsl): make capability refresh cleanu..." | Re-trigger Greptile
…d stop WSL latching absent Three Windows crash/regression fixes from shipped 1.4.156/1.4.158/1.4.159 crash reports. GPU fallback (cluster D, 14 reports, exit 0x80000003 STATUS_BREAKPOINT): the software-rendering fallback called disableHardwareAcceleration() plus --disable-gpu, neither of which removes the GPU child process — Chromium still spawns it to host Viz and merely drops the backend to software GL. Measured on Windows 11 / Electron 43.1.0: gpuProcessCount stays 1. So a GPU process being killed by a bad driver or an injected DLL kept dying after the fallback engaged, on every launch, for the life of that build (the marker is sticky per version). The crash tails show exactly this: gpu_fallback_applied followed by another GPU crash 1.3s later. --in-process-gpu is the only switch that drops the child count to 0; --disable-software-rasterizer is deliberately excluded because it also kills SwiftShader, which would drop every terminal to the DOM renderer. WSL distro list: a successful-but-empty `wsl --list --quiet` was cached for the process lifetime. `wsl --install` reports zero distros while one is still provisioning, so an early probe latched "no WSL" until restart — WSL appeared during setup and then vanished from the terminal picker. Empty results now re-probe on an exponential window (15s doubling to a 5min cap) while staying readable, so a missing distro is still visible to isKnownMissingDistro. WSL availability: isWslAvailable() latched false on any failure via a bare catch, so one slow wsl.exe activation disabled WSL for the whole session. Failures are now classified — a numeric exit status or ENOENT is answer-shaped and holds for 10min, anything else (timeout, spawn failure) retries after 45s — and both back off per consecutive failure, mirroring isPwshAvailable. Windows-only: every changed path is behind an existing process.platform check, so macOS and Linux behaviour is unchanged.
…t succeeds The distro-list and availability caches expire independently, and getWslRepairReason checks availability first. So a definitive availability failure (numeric exit status or ENOENT) held for 10-30min would keep reporting `wsl-unavailable` even after `wsl --list --quiet` successfully returned a distro — i.e. over a WSL that demonstrably just answered. That is the same latch class this branch fixes, surviving in the gap between the two caches. A non-empty distro list proves wsl.exe ran, so drop the negative availability cache and let the next call re-probe. Scoped to non-empty lists only: those are cached for the process lifetime, so this cannot re-spawn the blocking 5s probe more than once. An empty list keeps its failure cache, since it re-probes on a 15s-to-5min schedule and would otherwise pay the blocking probe far too often.
e2002c4 to
82288ea
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/wsl.ts (1)
161-211: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winConsider in-flight dedupe for concurrent distro probes.
listWslDistros/listWslDistrosAsyncspawn a newwsl.exechild process on every call once outside the retry window, with no shared in-flight promise — each concurrent caller (e.g. multiple owner-keyed renderer capability reads) triggers its own subprocess. The sequence-guard incacheWslDistroListalready handles the resulting out-of-order races correctly, but a shared in-flight promise (similar topendingCapabilitiesByOwnerKeyinwindows-terminal-capabilities.ts) would avoid redundant subprocess spawns and simplify reasoning about overlapping probes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f30f0611-5466-4b0d-94e5-232a0719289d
📒 Files selected for processing (14)
config/tsconfig.tc.web.jsonsrc/main/crash-reporting/gpu-fallback-restart-prompt.test.tssrc/main/crash-reporting/gpu-fallback-restart-prompt.tssrc/main/index.tssrc/main/startup/gpu-fallback-switches.test.tssrc/main/startup/gpu-fallback-switches.tssrc/main/wsl-distro-list-output.test.tssrc/main/wsl-distro-list-output.tssrc/main/wsl-distro-retry.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-read.ts
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/lib/windows-terminal-capabilities.ts (1)
252-269: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winAvoid allocating no-op intervals for remote consumers.
Every enabled hook creates a 30-second timer, even though remote, environment, and SSH consumers return immediately on every tick. Create the interval only for local targets without an SSH connection, and clear it conditionally during cleanup. This matches the PR objective that periodic refresh is limited to local WSL capability consumers.
Suggested adjustment
- const refreshInterval = globalThis.setInterval(() => { - if (resolvedTarget.kind !== 'local' || sshConnectionIdKey) { - return - } + const refreshInterval = + resolvedTarget.kind === 'local' && !sshConnectionIdKey + ? globalThis.setInterval(() => { const cachedCapabilities = getCachedWindowsTerminalCapabilities(resolvedOwnerKey) if (cachedCapabilities.wslAvailable && cachedCapabilities.wslDistros.length > 0) { return } void loadWindowsTerminalCapabilities({ ownerKey: resolvedOwnerKey, target: resolvedTarget, sshConnectionId: sshConnectionIdKey }) - }, CAPABILITY_CACHE_TTL_MS) + }, CAPABILITY_CACHE_TTL_MS) + : undefined - globalThis.clearInterval(refreshInterval) + if (refreshInterval !== undefined) { + globalThis.clearInterval(refreshInterval) + }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 777c6efb-ca5e-4052-acc7-30ba054fb5d8
📒 Files selected for processing (1)
src/renderer/src/lib/windows-terminal-capabilities.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.
…exe probes (#11698) * perf(windows): stop the capability poll respawning blocking wsl.exe probes #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]>
…d stop WSL latching absent (stablyai#11295) * fix(windows): make the GPU fallback actually remove the GPU child, and stop WSL latching absent Three Windows crash/regression fixes from shipped 1.4.156/1.4.158/1.4.159 crash reports. GPU fallback (cluster D, 14 reports, exit 0x80000003 STATUS_BREAKPOINT): the software-rendering fallback called disableHardwareAcceleration() plus --disable-gpu, neither of which removes the GPU child process — Chromium still spawns it to host Viz and merely drops the backend to software GL. Measured on Windows 11 / Electron 43.1.0: gpuProcessCount stays 1. So a GPU process being killed by a bad driver or an injected DLL kept dying after the fallback engaged, on every launch, for the life of that build (the marker is sticky per version). The crash tails show exactly this: gpu_fallback_applied followed by another GPU crash 1.3s later. --in-process-gpu is the only switch that drops the child count to 0; --disable-software-rasterizer is deliberately excluded because it also kills SwiftShader, which would drop every terminal to the DOM renderer. WSL distro list: a successful-but-empty `wsl --list --quiet` was cached for the process lifetime. `wsl --install` reports zero distros while one is still provisioning, so an early probe latched "no WSL" until restart — WSL appeared during setup and then vanished from the terminal picker. Empty results now re-probe on an exponential window (15s doubling to a 5min cap) while staying readable, so a missing distro is still visible to isKnownMissingDistro. WSL availability: isWslAvailable() latched false on any failure via a bare catch, so one slow wsl.exe activation disabled WSL for the whole session. Failures are now classified — a numeric exit status or ENOENT is answer-shaped and holds for 10min, anything else (timeout, spawn failure) retries after 45s — and both back off per consecutive failure, mirroring isPwshAvailable. Windows-only: every changed path is behind an existing process.platform check, so macOS and Linux behaviour is unchanged. * fix(windows): drop a stale WSL availability failure once a distro list succeeds The distro-list and availability caches expire independently, and getWslRepairReason checks availability first. So a definitive availability failure (numeric exit status or ENOENT) held for 10-30min would keep reporting `wsl-unavailable` even after `wsl --list --quiet` successfully returned a distro — i.e. over a WSL that demonstrably just answered. That is the same latch class this branch fixes, surviving in the gap between the two caches. A non-empty distro list proves wsl.exe ran, so drop the negative availability cache and let the next call re-probe. Scoped to non-empty lists only: those are cached for the process lifetime, so this cannot re-spawn the blocking 5s probe more than once. An empty list keeps its failure cache, since it re-probes on a 15s-to-5min schedule and would otherwise pay the blocking probe far too often. * fix(windows): harden GPU safe mode and WSL recovery * fix(wsl): make capability refresh cleanup explicit --------- Co-authored-by: OrcaWin <[email protected]>
…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]>
Summary
--disable-gpu,--disable-software-rasterizer, and--in-process-gpu. This removes the GPU child and disables WebGL/SwiftShader, so terminals use their existing DOM renderer fallback instead of moving untrusted WebGL parsing into Orca's privileged main process.Screenshots
No renderer layout changed. The native warning dialog now says Restart in Safe Graphics Mode and explains that hardware acceleration and WebGL are disabled for this Orca version and that terminals/3D content may render more slowly.
Testing
GPU children=1,WebGL2=truedisableHardwareAcceleration+--disable-gpu):GPU children=1,WebGL2=trueGPU children=0,WebGL2=falsewsl.exe --statusexits 0 whilewsl.exe --list --quietexits 0 with no user distro and NUL-padded output.pnpm run typecheck— pass for node, CLI, and web projects.e4ca7f7f7before merge.AI Review Report
Three independent review lenses covered GPU/Electron behavior and user awareness, WSL cache/concurrency semantics, and Windows validation/CI coverage. Findings fixed in the review commit:
falsewith a newly discovered distro;Cross-platform review: GPU fallback remains Windows desktop-only and is skipped for serve mode. WSL cache state remains owned by the process/host that executes WSL; SSH and folder-workspace routing are unchanged. Local automatic refresh is not installed for SSH-owned capability targets.
Security Audit
Safe Graphics Mode deliberately disables SwiftShader/WebGL because
--in-process-gpucollapses the GPU-process boundary. This removes the largest renderer-controlled shader parsing surface from the privileged main process. Sandboxed browser guests remain sandboxed, and WebGL is unavailable globally in this rare post-crash mode.Residual trade-off: Viz/software compositing still runs in-process, so a persistent compositor fault can terminate the main process. The mode is Windows-only, requires a matching build-scoped marker after explicit user consent, and automatically resets on an Orca or Electron version change.
Notes
The original production defect is verified:
app.disableHardwareAcceleration()plus--disable-gpuchanges the backend but does not remove Chromium's GPU child. The added in-process switch is therefore required to address process-targeted driver/DLL failures; disabling the software rasterizer keeps that emergency fallback conservative.