Skip to content

fix(wsl): background preflight and agent detection never boot a stopped WSL distro (E9) - #35411

Merged
nwparker merged 7 commits into
mainfrom
nwparker/e9-preflight-gate
Oct 29, 2026
Merged

nwparker merged 7 commits into
mainfrom
nwparker/e9-preflight-gate

Conversation

@nwparker

@nwparker nwparker commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​597 $\color{#cf222e}{\Huge{\mathbf{−}}}$​16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​581
Prod 29 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​381 $\color{#cf222e}{\Huge{\mathbf{−}}}$​62 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​319

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

  • Integration checks (preflight:check: git/gh/glab --version, gh/glab auth status): before probing a WSL distro, main takes a settled running read (the existing blockedWslDistroForPath gate with its 60 s lease, plus the stop-settle window). If the distro is stopped it refuses with WSL_DISTRO_STOPPED, or with WSL_DISTRO_UNVERIFIABLE when 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.
  • Agent detection (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.
  • User acts pass a new optional wakeWslDistro flag. Main then runs the check inside runAsWslUserAct for that one distro, so the gate lets it through:
    • window focus or becoming visible, but only when the focused workspace is a WSL one. Preflight only ever targets that workspace's distro, so a focus with a native workspace active wakes nothing.
    • the Retry / Try again / refresh buttons in Tasks settings, the source-control card and onboarding integrations
    • agent refresh buttons (status bar, Agents settings catalog), choosing an agent runtime in Settings, and first-run onboarding
  • Mounts, the 30 s poll while issues exist, and background detection stay gated. A wake request no longer joins an in-flight background forced poll, which may get refused.
  • New helper src/main/wsl/wsl-background-exec-gate.ts resolves the default distro (when the target names none) and reuses blockedWslDistroForPath / runAsWslUserAct.
  • Not gated: 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.exe spawns on mount and poll paths (audit items P1 and P2). Alternatives I rejected:

  • Reporting "not installed" for a stopped distro would show false "git missing" banners.
  • Gating inside runWslProcess would also block real user acts, such as terminal launch and worktree create.
  • Waiting for the distro to start would hold the UI.

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 real wsl --list --running parse. 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 wakeWslDistro on 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_HOSTS unset. 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

  • 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: unaffected. SSH detection never goes through this gate.
  • Folder workspaces: they use the same preflight context resolution.
  • Remote wire: wakeWslDistro exists only on desktop IPC. RPC params are unchanged.

Status

Ready for review. #35412 is stacked on this PR. This supersedes #35395.

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)

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The change adds WSL distro resolution and running-state checks to preflight and agent-detection paths. It adds an optional wakeWslDistro flag to preflight and agent-refresh APIs. Selected renderer actions pass this flag. Forced preflight requests track whether they include the flag when deciding whether to reuse an existing request. Local agent refreshes can start a separate wake-enabled refresh when a background refresh is already in progress. The renderer also handles distro-running notifications by refreshing preflight status when an error is present and requesting agent detection.

Priority: Normal

Merge Risk: Moderate · up to 6dce8

Background checks can start a stopped distro, and agent results can become stale. Resolve these issues before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 39.29% 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 names the main change: background preflight and agent detection no longer start a stopped WSL distro. It follows the conventional commit format and is specific. It is 87 characters, slightly…
Description check Passed The description follows the template well. It has an ELI5, a What Changed section with the mechanism, a Why section that explains rejected alternatives, Testing with platform notes, a Review section w…
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: Title check

Explanation

The title names the main change: background preflight and agent detection no longer start a stopped WSL distro. It follows the conventional commit format and is specific. It is 87 characters, slightly above a short title, but it stays clear and on-topic.

Full details: Description check

Explanation

The description follows the template well. It has an ELI5, a What Changed section with the mechanism, a Why section that explains rejected alternatives, Testing with platform notes, a Review section with flag and user-risk notes, and a Checklist. The Linked Issue section says the work is an internal E9 audit with no public issue, and the template asks for an issue link. The Visual Proof section is marked N/A with a reason. The AI Disclosure section is blank, and the Fixes # line is not filled in. The Testing section also says the Windows machine was not used, which is a useful limit. The main gaps are the missing linked issue and the blank AI Disclosure section. Both are needed for the description to be complete.

Resolution

Add a linked issue or an explicit reason it is absent (the template asks outside contributors to link a real issue). Complete the AI Disclosure section or note that it does not apply. Confirm the unchecked lint/typecheck/test/build checklist item before merge.

Full details: Docstring Coverage

Explanation

Docstring coverage is 39.29% 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 28 functions across 45 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.

@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

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

Findings

  1. P1 Failed discovery allows a wake ▶
  2. P2 Agent catalog stays empty ▶

Summary

This PR keeps background integration checks and agent detection from starting stopped WSL distros. Explicit user actions can request a wake.

  • Background WSL checks leave stopped distros alone.
  • User actions can wake the focused WSL distro for a check.

Reviews (7) · Last reviewed commit: "fix(wsl): forget agent-inventory refusal..." · Reviewed by Greptile

Comment on lines +33 to +36
const target = await resolveWslExecDistro(distro)
if (target) {
await assertWslUncPathRunning('', target)
}

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

@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: eef48186-bec7-46b4-b76a-d00a15a4fdbf
Commits

Reviewing files that changed from the base of the PR and between f12e12f and 5b25706.

Files selected for processing: 31
  • src/main/ipc/preflight-agent-detection.test.ts
  • src/main/ipc/preflight-agent-refresh.test.ts
  • src/main/ipc/preflight-host-cli-status.test.ts
  • src/main/ipc/preflight-wsl-stopped-distro.test.ts
  • src/main/ipc/preflight.ts
  • src/main/preflight/agent-detection.ts
  • src/main/preflight/preflight-wsl-stopped-distro.test.ts
  • src/main/preflight/workspace-agent-detection.test.ts
  • src/main/preflight/workspace-agent-detection.ts
  • src/main/runtime/rpc/methods/preflight.test.ts
  • src/main/runtime/rpc/methods/preflight.ts
  • src/main/wsl/wsl-background-exec-gate.ts
  • src/preload/api/preflight-api.ts
  • src/preload/api/preflight-bridge.ts
  • src/renderer/src/components/landing-preflight-runtime-boundary.test.ts
  • src/renderer/src/components/landing-preflight-runtime.ts
  • src/renderer/src/components/onboarding/IntegrationsStep.tsx
  • src/renderer/src/components/onboarding/use-onboarding-flow.ts
  • src/renderer/src/components/settings/AgentsPane.test.tsx
  • src/renderer/src/components/settings/AgentsPane.tsx
  • src/renderer/src/components/settings/TasksPane.test.tsx
  • src/renderer/src/components/settings/TasksPane.tsx
  • src/renderer/src/components/settings/source-control-preflight-card-status.ts
  • src/renderer/src/components/status-bar/use-status-bar-controller.ts
  • src/renderer/src/hooks/useDetectedAgents.test.tsx
  • src/renderer/src/hooks/useDetectedAgents.ts
  • src/renderer/src/store/slices/local-agent-inventory-refresh.ts
  • src/renderer/src/store/slices/local-detected-agent-state.ts
  • src/renderer/src/store/slices/local-detected-agent-store-state.ts
  • src/renderer/src/store/slices/preflight.test.ts
  • src/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)

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.

Major · Stability & Availability · Quick win

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)

@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: 4ed621af-7160-4a06-8c33-147f885e98a7
Commits

Reviewing files that changed from the base of the PR and between bfa3e1a and 0f1e560.

Files selected for processing: 19
  • src/main/ipc/preflight-wsl-refusal-retry.ts
  • src/main/ipc/preflight-wsl-stopped-distro.test.ts
  • src/main/ipc/preflight.ts
  • src/preload/api/preflight-api.ts
  • src/preload/api/preflight-bridge.ts
  • src/renderer/src/components/NewWorkspaceComposerModal.tsx
  • src/renderer/src/components/agent-session-continuation/AgentSessionContinuationDialog.tsx
  • src/renderer/src/components/right-sidebar/use-source-control-action-agent-choice.ts
  • src/renderer/src/components/tab-bar/use-agent-picker-refused-wake.test.tsx
  • src/renderer/src/components/tab-bar/use-agent-picker-refused-wake.ts
  • src/renderer/src/components/tab-bar/use-new-tab-agent-menu-rows.ts
  • src/renderer/src/components/tab-bar/use-tab-bar-create-menu-controller.ts
  • src/renderer/src/hooks/ipc-events/app-lifetime-ipc-bridge.ts
  • src/renderer/src/hooks/ipc-events/preflight-wsl-retry-ipc-bridge.test.ts
  • src/renderer/src/hooks/ipc-events/preflight-wsl-retry-ipc-bridge.ts
  • src/renderer/src/store/slices/local-agent-inventory-refresh.ts
  • src/renderer/src/store/slices/local-detected-agent-state.test.ts
  • src/renderer/src/store/slices/local-detected-agent-state.ts
  • src/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.

Comment on lines +21 to +25
useEffect(() => {
if (refused && worktreeId !== undefined) {
void useAppStore.getState().ensureDetectedAgentsForPicker(worktreeId)
}
}, [refused, worktreeId])

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.

Major · Stability & Availability · Quick win

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

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

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.
@nwparker
nwparker force-pushed the nwparker/e9-preflight-gate branch from 0f1e560 to b4beb56 Compare October 29, 2026 00:29
Comment on lines +15 to +16
// A refused inventory is marked failed, so this re-detects it; a known list is reused.
void state.ensureDetectedAgents()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Agent catalog stays empty

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.

@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: 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
Commits

Reviewing files that changed from the base of the PR and between 0f1e560 and 6dce864.

Files selected for processing: 9
  • src/main/wsl/wsl-distro-refusal-message.test.ts
  • src/renderer/src/components/status-bar/use-status-bar-controller.ts
  • src/renderer/src/components/tab-bar/use-agent-picker-refused-wake.test.tsx
  • src/renderer/src/components/tab-bar/use-agent-picker-refused-wake.ts
  • src/renderer/src/store/slices/local-agent-inventory-refresh.ts
  • src/renderer/src/store/slices/local-detected-agent-state.test.ts
  • src/renderer/src/store/slices/local-detected-agent-state.ts
  • src/renderer/src/store/slices/local-detected-agent-store-state.ts
  • src/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 })

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

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)

@nwparker
nwparker merged commit 9babef2 into main Oct 29, 2026
55 checks passed
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