Repository navigation
fix(wsl): background preflight and agent detection never boot a stopped WSL distro (E9) - #35411
Conversation
Walkthrough
Priority: Merge Risk:
|
[Medium impact] The changes affect WSL preflight and agent checks across desktop and paired-client workflows. The PR should not merge until failed default-distro discovery can no longer allow a background wake. FindingsSummaryThis PR keeps background integration checks and agent detection from starting stopped WSL distros. Explicit user actions can request a wake.
Reviews (7) · Last reviewed commit: "fix(wsl): forget agent-inventory refusal..." · Reviewed by Greptile |
| const target = await resolveWslExecDistro(distro) | ||
| if (target) { | ||
| await assertWslUncPathRunning('', target) | ||
| } |
There was a problem hiding this comment.
Failed discovery allows a wake
assertWslDistroRunningForExec allows execution when it cannot resolve the default distro. listWslDistrosAsync returns [] after a timeout or failed listing, not just when no distros exist. A background check with wslDefault: true then skips the running check and executes in the default distro, which can start it.
Treat an unresolved default as unverifiable instead of allowing the probe.
There was a problem hiding this comment.
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:
eef48186-bec7-46b4-b76a-d00a15a4fdbf
Files selected for processing: 31-
src/main/ipc/preflight-agent-detection.test.tssrc/main/ipc/preflight-agent-refresh.test.tssrc/main/ipc/preflight-host-cli-status.test.tssrc/main/ipc/preflight-wsl-stopped-distro.test.tssrc/main/ipc/preflight.tssrc/main/preflight/agent-detection.tssrc/main/preflight/preflight-wsl-stopped-distro.test.tssrc/main/preflight/workspace-agent-detection.test.tssrc/main/preflight/workspace-agent-detection.tssrc/main/runtime/rpc/methods/preflight.test.tssrc/main/runtime/rpc/methods/preflight.tssrc/main/wsl/wsl-background-exec-gate.tssrc/preload/api/preflight-api.tssrc/preload/api/preflight-bridge.tssrc/renderer/src/components/landing-preflight-runtime-boundary.test.tssrc/renderer/src/components/landing-preflight-runtime.tssrc/renderer/src/components/onboarding/IntegrationsStep.tsxsrc/renderer/src/components/onboarding/use-onboarding-flow.tssrc/renderer/src/components/settings/AgentsPane.test.tsxsrc/renderer/src/components/settings/AgentsPane.tsxsrc/renderer/src/components/settings/TasksPane.test.tsxsrc/renderer/src/components/settings/TasksPane.tsxsrc/renderer/src/components/settings/source-control-preflight-card-status.tssrc/renderer/src/components/status-bar/use-status-bar-controller.tssrc/renderer/src/hooks/useDetectedAgents.test.tsxsrc/renderer/src/hooks/useDetectedAgents.tssrc/renderer/src/store/slices/local-agent-inventory-refresh.tssrc/renderer/src/store/slices/local-detected-agent-state.tssrc/renderer/src/store/slices/local-detected-agent-store-state.tssrc/renderer/src/store/slices/preflight.test.tssrc/renderer/src/store/slices/preflight.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
-
| if (process.platform !== 'win32') { | ||
| return null | ||
| } | ||
| return distro?.trim() || ((await listWslDistrosAsync())[0] ?? null) |
There was a problem hiding this comment.
Resolve the distro that wsl.exe will actually run.
If the distro-list probe fails, listWslDistrosAsync() can return []. The assertion then skips its running-state check, but a later wsl.exe call without -d can still start a stopped default distro. If the cached list predates a change to WSL’s default, the assertion can instead check the old distro while the command starts the new one. Fail closed when the default cannot be resolved, and keep the verified distro consistent with the executed command. (raw.githubusercontent.com)
There was a problem hiding this comment.
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:
4ed621af-7160-4a06-8c33-147f885e98a7
Files selected for processing: 19-
src/main/ipc/preflight-wsl-refusal-retry.tssrc/main/ipc/preflight-wsl-stopped-distro.test.tssrc/main/ipc/preflight.tssrc/preload/api/preflight-api.tssrc/preload/api/preflight-bridge.tssrc/renderer/src/components/NewWorkspaceComposerModal.tsxsrc/renderer/src/components/agent-session-continuation/AgentSessionContinuationDialog.tsxsrc/renderer/src/components/right-sidebar/use-source-control-action-agent-choice.tssrc/renderer/src/components/tab-bar/use-agent-picker-refused-wake.test.tsxsrc/renderer/src/components/tab-bar/use-agent-picker-refused-wake.tssrc/renderer/src/components/tab-bar/use-new-tab-agent-menu-rows.tssrc/renderer/src/components/tab-bar/use-tab-bar-create-menu-controller.tssrc/renderer/src/hooks/ipc-events/app-lifetime-ipc-bridge.tssrc/renderer/src/hooks/ipc-events/preflight-wsl-retry-ipc-bridge.test.tssrc/renderer/src/hooks/ipc-events/preflight-wsl-retry-ipc-bridge.tssrc/renderer/src/store/slices/local-agent-inventory-refresh.tssrc/renderer/src/store/slices/local-detected-agent-state.test.tssrc/renderer/src/store/slices/local-detected-agent-state.tssrc/renderer/src/store/slices/local-detected-agent-store-state.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.
-
| useEffect(() => { | ||
| if (refused && worktreeId !== undefined) { | ||
| void useAppStore.getState().ensureDetectedAgentsForPicker(worktreeId) | ||
| } | ||
| }, [refused, worktreeId]) |
There was a problem hiding this comment.
Limit wake detection to one attempt per picker opening.
If wake-enabled detection fails while the picker remains open, the store changes the inventory from pending back to failed. That change runs this effect again and starts another wake-enabled request. A persistent failure can therefore cause an unbounded sequence of IPC requests and WSL launch attempts. Track whether this opening already attempted the current target; reset that attempt when the picker closes or the target changes. (raw.githubusercontent.com)
| const inflightRefresh = lifecycle.refreshPromises.get(contextKey) | ||
| if (inflightRefresh) { | ||
| // A picker's wake must not ride a background probe that a stopped WSL distro refuses. | ||
| if (inflightRefresh && (!wake || lifecycle.wakeRefreshes.has(inflightRefresh))) { |
There was a problem hiding this comment.
Retire the background refresh when picker detection supersedes it.
If a picker wake bypasses an in-flight background refresh, the refresh remains the current entry in refreshPromises. A later refresh result can replace the agents found by the picker; a later refresh failure can mark that new list as failed. Retire or invalidate the superseded refresh before starting wake detection, and cover both completion orders. (raw.githubusercontent.com)
…ed WSL distro (E9) Integration checks (git/gh/glab --version and auth status) and agent detection ran inside the focused workspace's WSL distro on every mount, poll and status-bar render, and wsl.exe starts a stopped distro. They now take a settled running read first and refuse (WSL_DISTRO_STOPPED or WSL_DISTRO_UNVERIFIABLE) when it is not running. Window focus/visibility, retry buttons, agent refresh buttons, a runtime choice in Settings and first-run onboarding pass wakeWslDistro, which runs the check as a user act on that distro only. Running distros behave exactly as before.
…-end preflight gate test A focus with a native workspace active sends no wake. Ports the real running-list preflight case from #35395 and adds user-act scoping cases.
…r a stopped distro Windows CI runs the real gate, so the WSL detection case must state that the distro runs.
…would be refused with Store the wake flag with each in-flight refresh, as preflight.ts does, so a status-bar or Agents refresh click during a mount refresh reaches main as a user act. Note why the RPC project branch stays ungated.
…nt picker wakes it A preflight or agent detection refused for a stopped WSL distro was final: once the distro came up, nothing re-ran it, so the tab-bar + menu offered no WSL agents (real-WSL golden). Now a refusal is deferred until the distro is next confirmed running (deferUntilWslDistroRunning), and main tells renderers to re-ask. Opening an agent-launch picker (tab-bar +, composer, continuation dialog, source-control action dialog) whose list was refused retries it as a wake, never joining a background probe.
0f1e560 to
b4beb56
Compare
| // A refused inventory is marked failed, so this re-detects it; a known list is reused. | ||
| void state.ensureDetectedAgents() |
There was a problem hiding this comment.
The retry only reloads the enabled agent list. Agents settings reads a separate list through useDetectedAgents(detectionTarget, 'all'). If that read was refused while WSL was stopped, its cached value becomes []. When the distro starts, ensureDetectedAgents() updates only the enabled list, so Settings keeps showing installed agents as missing until the user clicks refresh.
Retry the refused complete inventories too, using their original targets.
…etries real failures The picker wake fired whenever the list read 'failed', so a woken probe that failed again (pending -> failed) re-fired it: an endless wsl.exe loop while the picker stayed open, and repeated probes for native failures too. It now fires at most once per open per target, and only when the last probe was an E9 refusal (distro not running/unverifiable), matched by the gate's message.
…roject contexts are cleared
There was a problem hiding this comment.
Actionable comments posted: 1

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:
6064bbdf-7c24-470c-a8c4-242af642b391
Files selected for processing: 9-
src/main/wsl/wsl-distro-refusal-message.test.tssrc/renderer/src/components/status-bar/use-status-bar-controller.tssrc/renderer/src/components/tab-bar/use-agent-picker-refused-wake.test.tsxsrc/renderer/src/components/tab-bar/use-agent-picker-refused-wake.tssrc/renderer/src/store/slices/local-agent-inventory-refresh.tssrc/renderer/src/store/slices/local-detected-agent-state.test.tssrc/renderer/src/store/slices/local-detected-agent-state.tssrc/renderer/src/store/slices/local-detected-agent-store-state.tssrc/shared/wsl-distro-refusal.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.
-
| await Promise.all([(refreshRemote ?? refreshRateLimits)(), refreshDetectedAgents()]) | ||
| await Promise.all([ | ||
| (refreshRemote ?? refreshRateLimits)(), | ||
| refreshDetectedAgents(undefined, { wakeWslDistro: true }) |
There was a problem hiding this comment.
Do not wake local WSL for remote-owned usage.
When remoteOwned is true, this handler refreshes remote usage but still sends a wake-enabled local agent refresh. If the local default is a stopped WSL distro, clicking Refresh can start that distro even though the displayed agent bars do not use its inventory. Skip the local refresh when remoteOwned is true. (raw.githubusercontent.com)
ELI5
Orca checks whether git, gh and glab are installed and signed in, and which coding agents are installed. For a workspace that lives in WSL it runs those checks inside the WSL distro. Running anything inside a stopped distro starts it. So just opening Orca, rendering the status bar, or a 30-second poll could start a WSL distro the user had shut down. Now these checks only run in a distro that is already running, unless the user just did something themselves (focused the window, clicked retry or refresh).
What Changed
preflight:check:git/gh/glab --version,gh/glab auth status): before probing a WSL distro, main takes a settled running read (the existingblockedWslDistroForPathgate with its 60 s lease, plus the stop-settle window). If the distro is stopped it refuses withWSL_DISTRO_STOPPED, or withWSL_DISTRO_UNVERIFIABLEwhen WSL can't answer. The renderer already keeps the last status and shows the "unavailable / try again" state on an error, so nothing claims git is missing.preflight:detectAgents,preflight:refreshAgents, and the paired-client RPC twins): the same gate runs first. The renderer already treats a failed detection as retryable and keeps the previous inventory through a failed refresh.wakeWslDistroflag. Main then runs the check insiderunAsWslUserActfor that one distro, so the gate lets it through:src/main/wsl/wsl-background-exec-gate.tsresolves the default distro (when the target names none) and reusesblockedWslDistroForPath/runAsWslUserAct.detectProjectLaunchContext(the new-workspace flow for a chosen project, which is a user act) and worktree agent startup.Before: with a stopped Ubuntu workspace focused, launching Orca or rendering the status bar started Ubuntu. After: Ubuntu stays stopped until the user focuses the window, clicks something, or opens a terminal there. A running distro behaves exactly as before.
Why
Background work must never boot a stopped WSL distro (rule E9). An old WSL idle-stop can also wipe the VM-wide interop registration. These preflight calls were the remaining ungated
wsl.exespawns on mount and poll paths (audit items P1 and P2). Alternatives I rejected:runWslProcesswould also block real user acts, such as terminal launch and worktree create.Linked Issue
Internal E9 audit (P1, P2). No public issue.
Visual Proof
N/A. There is no new UI. A stopped distro shows the existing "integrations unavailable / try again" state until the user focuses the window or clicks retry.
Testing
New
src/main/ipc/preflight-wsl-stopped-distro.test.ts(7 cases): a background check, detection or refresh in a stopped or unverifiable distro spawns nothing; the default distro is resolved; a wake runs in that distro; a running distro probes as before. With the gates reverted, 5 of 7 fail.New renderer cases in
store/slices/preflight.test.ts: a focus wake is sent even while a background forced poll is in flight, and a focus with a native workspace active sends no wake.New
src/main/preflight/preflight-wsl-stopped-distro.test.ts(ported from fix(wsl): preflight, agent detection and WSL CLI checks never boot a stopped distro (E9) #35395): runs end to end through the realwsl --list --runningparse. A user act on another distro does not admit this one.Updated the existing preflight suites so they model a running distro. Updated renderer tests to expect
wakeWslDistroon focus and clicks.Load rule:
pnpm tc,pnpm run typecheck:ci, touched tests (1326 files pass),pnpm run check:code-quality:changed(pass), the anti-slop oxlint (pass) and the ast-grep gates (pass).Platforms: unit tests on macOS with a mocked win32 platform. Not run on a Windows machine.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Flag-off: this changes behavior with
ORCA_INTERNAL_WSL_HOSTSunset. Any shipping Windows user whose focused workspace runs in WSL no longer has a stopped distro started by integration checks or agent detection on mount or poll. Running distros are unchanged.User-risk: with the distro stopped, the integrations card and agent list show their existing "unavailable / retry" state until the user focuses the window, clicks retry or refresh, or opens a terminal. A paired web or mobile client can't wake a distro for agent detection or refresh: the RPC has no user-act signal, and adding one would change the wire contract.
Agent skill upstream boundary
Notes
wakeWslDistroexists only on desktop IPC. RPC params are unchanged.Status
Ready for review. #35412 is stacked on this PR. This supersedes #35395.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)