Skip to content

fix(wsl): preflight, agent detection and WSL CLI checks never boot a stopped distro (E9) - #35395

Closed
nwparker wants to merge 1 commit into
mainfrom
nwparker/wsl-e9-preflight
Closed

nwparker wants to merge 1 commit into
mainfrom
nwparker/wsl-e9-preflight

Conversation

@nwparker

@nwparker nwparker commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​162 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​158
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​60 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​53

Flag-off: Not WSL-host-specific. These checks run on main for any Windows user whose active project, or the default runtime, is a WSL distro, bridge users included. This fixes them flag-off too.
User-risk: Low. While the active WSL distro is stopped:

  • Source-control preflight shows the existing error state, "WSL distro 'X' is not running. Retry, or open a terminal in it, to start it.", instead of starting it.
  • Agent detection for that distro fails and retries, so it never caches "no agents installed".
  • Settings → CLI shows "WSL (X) is not running. Open a terminal in it, then refresh."

The explicit "Refresh agents" action, the WSL CLI install/remove buttons and opening a terminal still start the distro.

ELI5

Orca must never start a WSL distro you stopped unless you ask (rule E9). Some background checks did: a "is git/gh installed and signed in?" check that runs every time the window gets focus, a scan for installed agent CLIs, the Settings CLI status, and two startup/health checks. Now they first check that the distro is running and, if it isn't, say so instead of starting it.

What Changed

  • Preflight (preflight:check). Before: git/gh/glab --version and auth status ran inside the active WSL distro on sidebar/landing mount and forced on every window focus, which booted it. After: executePreflightCheck first calls the new assertPreflightWslDistroRunning, which uses the settled gate assertWslUncPathRunning. A stopped distro rejects with the existing WslDistroStoppedError message, which the renderer already shows as the preflight error. The check sits inside the shared run, so concurrent callers still collapse onto one probe.
  • Agent detection (preflight:detectAgents, mount). Before: a command -v loop ran in the distro on mount. After: it refuses the same way. A rejection already marks detection failed and retries; it never caches []. preflight:refreshAgents (the explicit Refresh button) is unchanged.
  • Settings WSL-CLI status (cli:getWslInstallStatus). Before: a status script ran on the default distro on every mount. After: a stopped distro returns the retryable wsl_unreachable status with "is not running" copy, through the new stoppedWslCliStatus.
  • Startup CLI repair and interop health. Before: both trusted listRunningWslDistrosAsync, which still names a distro inside its stop's settle window, and interop health probed every listed distro on each stop event without asking. After: both use a new listSettledRunningWslDistros (wsl-background-distro-gate.ts), and interop health confirms before probing on stop events too.

Why

Linked Issue

Internal WSL tracker, E9 audit (/tmp/fanout/wsl-exec-audit.md, rows P1–P5).

Visual Proof

N/A: no new UI. The existing preflight-error and CLI-unreachable states show the new copy.

Testing

New tests, each failing with its source fix reverted (checked):

  • preflight-wsl-stopped-distro.test.ts (real gate, mocked wsl.exe, win32): a focus-forced preflight and an on-mount agent detection both refuse a stopped distro without running anything in it.
  • cli.test.ts: a Settings status read of a stopped distro returns "is not running" and never constructs the installer.
  • wsl-interop-health.test.ts: a distro the stop event's list still names, but the settled list doesn't, is not probed. The existing stop-path case now expects the confirming read.
  • wsl-settled-running-list.test.ts: a distro inside its stop settle window is dropped, then listed again once it settles.

The existing preflight tests now mock the gate, because they test what preflight does once a distro runs. One race test now waits for the stale probes before flipping phase, since the running check comes first.

Suites: preflight, ipc/preflight, cli, ipc/cli, wsl, and the background-distro gate pass, except packaged-cli-assets, whose two tests also fail on an exact main baseline here.

Load rule: pnpm tc, typecheck:ci, oxlint, the anti-slop lint, oxfmt, check:code-quality:changed, and the ast-grep gates.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

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)

…stopped distro (E9)

Several checks ran `wsl -d <distro>` in the background:
- Source-control preflight, forced on every window focus.
- Agent detection on mount.
- The Settings WSL-CLI status read.

The startup CLI repair and the interop health monitor trusted a running list
that can still name a stopping distro. The health monitor also probed on every
stop event with no check at all.

Preflight and detection now refuse a stopped distro with the gate's "not running"
error, which callers show and retry, so a stopped distro never caches as "no
agents". The CLI status read reports the distro is not running. CLI repair and
interop health use a settled running list.
@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 2/5

[Medium impact] The changes affect several Windows workflows that inspect or maintain WSL distros.

Fix the explicit-launch regression and the two gaps in stopped-distro checks before merging.

Findings

  1. P1 Explicit WSL launches can fail ▶
  2. P1 Unknown default bypasses the gate ▶
  3. P1 Stop tracking may never start ▶
  4. P2 Unknown state appears as stopped ▶

Summary

This PR adds running-state checks before background WSL preflight, agent detection, CLI status, startup repair, and interop checks.

  • Preflight and automatic agent detection check WSL before probing it.
  • Settings shows when a WSL distro is stopped instead of starting it.
  • Startup CLI repair waits until a WSL distro is settled as running.
  • Interop health checks confirm a WSL distro before probing it.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  Background[Background agent detection] --> Gate[Check whether distro runs]
  Launch[Explicit project launch] --> Context[Read project launch context]
  Context --> Gate
  Gate -->|Stopped| Reject[Reject detection]
  Reject --> Retry[Background check stays retryable]
  Reject --> Cancel[Direct launch cancels]
  Refresh[Explicit agent refresh] --> Scan[Scan guest commands]
Loading

Reviews (1) · Last reviewed commit: "fix(wsl): preflight, agent detection and..." · Reviewed by Greptile

Comment on lines +143 to +146
// Detection runs on mount: a stopped distro is unverifiable, never "no agents" and never booted.
const wsl = getPreflightWslTarget(host.context)
if (wsl) {
await assertPreflightWslDistroRunning(wsl)

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 Explicit WSL launches can fail

detectProjectLaunchContext also calls this helper, so the new background gate can reject an intentional issue/PR launch when its distro is stopped. launchWorkItemDirect starts detection before its setup checks, converts a rejection to null, and cancels the launch with an unavailable-agent message. Keep the gate for background detection, but let the explicit launch path start its selected distro.

Comment on lines +11 to +13
const distro = target.distro?.trim() || (await listWslDistrosAsync())[0]
if (distro) {
await assertWslUncPathRunning('', distro)

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 Unknown default bypasses the gate

listWslDistrosAsync returns an empty list after a failed lookup, including during its retry delay. This helper then returns without checking anything. With { wslDefault: true }, the following commands still omit a distro name and run in WSL's default distro, so a temporary lookup failure can let a background check start a stopped distro. Reject as unverifiable when the default cannot be resolved.

Comment on lines +151 to +153
export async function listSettledRunningWslDistros(): Promise<string[]> {
const distros = await listRunningWslDistrosAsync({ requireConfirmed: true })
return distros.filter((distro) => wasWslDistroLastSeenRunningSettled(distro))

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 Stop tracking may never start

This filter depends on mayHaveStoppedAt, but its stop listener is registered only by settledWslRunningReadAnchor. Neither new caller invokes that helper. If startup repair or interop health runs before another caller registers the listener, a stop seen by the running-list cache goes unrecorded. A later list that names the distro during its stop window then passes this filter, allowing a probe or repair to restart it. Initialize stop tracking before reading the running list.

Comment thread src/main/ipc/cli.ts
Comment on lines +147 to +148
if (distro && (await blockedWslDistroForPath('', distro))) {
return stoppedWslCliStatus(distro)

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 Unknown state appears as stopped

blockedWslDistroForPath also returns a value when WSL's running-list checks fail. This condition therefore gives a running but temporarily unreachable distro the false message “is not running.” Check the returned state and use an unknown/unreachable message for unverifiable, rather than sending users to open a terminal unnecessarily.

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The change adds a settled running-distro lookup and uses it in CLI registration reconciliation and WSL interop health checks. It adds a WSL running-distro gate before preflight and host agent detection. The WSL CLI status handler now returns an unsupported status when its access gate reports a stopped distro. Tests cover these behaviors and isolate existing preflight tests from the new gate.

Priority: Normal

Merge Risk: Moderate · up to 0404a

The change mostly keeps background checks from waking a stopped WSL distro. However, in edge cases such as a failed distro lookup or a distro that is just stopping, a background check can still start it, and Settings can show the wrong status message. Close these gaps before merging.

Pre-merge checks: Passed 3 · Failed 1 · Inconclusive 1

Failed Failed checks: 1 warning · 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% 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.
Description check Inconclusive The description follows the template's main sections: ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, AI Disclosure, Review, Notes, and Checklist. The ELI5, What Changed, and Why section… Link a real GitHub issue in the Linked Issue section using "Fixes #". Replace the internal tracker reference and the /tmp path, which reviewers cannot open. State which platforms were manually tested (for example Windows 11 with WSL…
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title "fix(wsl): preflight, agent detection and WSL CLI checks never boot a stopped distro (E9)" names the main change: background checks no longer start a stopped WSL distro. It matches the raw s…
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 "fix(wsl): preflight, agent detection and WSL CLI checks never boot a stopped distro (E9)" names the main change: background checks no longer start a stopped WSL distro. It matches the raw summary, which adds running-distro gates to preflight, agent detection, and the Settings WSL CLI status. The title is long (88 characters) and uses an internal tracker tag "(E9)", which a teammate scanning history may not recognize. These are style issues and do not make the title off-topic.

Full details: Docstring Coverage

Explanation

Docstring coverage is 25.00% 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 4 functions across 15 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Full details: Description check

Explanation

The description follows the template's main sections: ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, AI Disclosure, Review, Notes, and Checklist. The ELI5, What Changed, and Why sections are detailed and explain the before and after behavior and the mechanism. Visual Proof is marked N/A with a reason. Testing lists the new tests and the suites that pass. The Linked Issue section does not contain a real issue link. It cites an "Internal WSL tracker, E9 audit" and a local file path (/tmp/fanout/wsl-exec-audit.md), and it has no "Fixes #" reference. The template requires an actual linked issue. The manual testing box is unchecked, and the lint, typecheck, test, and build checklist item is unchecked. The Testing section does not say which platforms were tested by hand.

Resolution

Link a real GitHub issue in the Linked Issue section using "Fixes #<number>". Replace the internal tracker reference and the /tmp path, which reviewers cannot open. State which platforms were manually tested (for example Windows 11 with WSL2), or state that manual testing was not done. Confirm the pnpm lint, typecheck, test, and build status, or state that CI will cover them. The template also asks for the AI Disclosure section to be filled in if the author is not a StablyAI team member. The description is otherwise complete.

Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 5


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: c9be7b1e-e538-43ce-acd5-9f7b94c5d597
Commits

Reviewing files that changed from the base of the PR and between 58d97f5 and 0404a01.

Files selected for processing: 15
  • src/main/cli/wsl-cli-registration-reconciliation.ts
  • src/main/cli/wsl-cli-status.ts
  • src/main/ipc/cli.test.ts
  • src/main/ipc/cli.ts
  • src/main/ipc/preflight-agent-detection.test.ts
  • src/main/ipc/preflight-host-cli-status.test.ts
  • src/main/preflight/agent-detection.ts
  • src/main/preflight/preflight-wsl-running-gate.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/wsl-background-distro-gate.ts
  • src/main/wsl-settled-running-list.test.ts
  • src/main/wsl/wsl-interop-health.test.ts
  • src/main/wsl/wsl-interop-health.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.

// Never boot stopped distros for background repair; defer until they run.
const running = new Set(
(await (options.listRunningDistros ?? listConfirmedRunningWslDistros)()).map((distro) =>
(await (options.listRunningDistros ?? listSettledRunningWslDistrosOrNone)()).map((distro) =>

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

Schedule a settled retry when this lookup defers a running distro.

If a candidate is running but its observation falls inside the stop-settle window, this lookup excludes it. The observation occurs before deferUntilWslDistroRunning registers the task, so its settle-probe scheduler has no task to schedule. Reconciliation then waits for an unrelated observation or wake, leaving the managed launcher unrepaired. Schedule a post-settle probe when registering this deferral. (raw.githubusercontent.com)

Comment thread src/main/ipc/cli.ts
Comment on lines +147 to +148
if (distro && (await blockedWslDistroForPath('', distro))) {
return stoppedWslCliStatus(distro)

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

Distinguish an unverifiable distro from a stopped distro.

blockedWslDistroForPath also returns a block when running-state discovery fails. This branch then tells users that the distro is not running and asks them to start it, even when its state is unknown. Return unreachableWslCliStatus for unverifiable and reserve stoppedWslCliStatus for stopped. (raw.githubusercontent.com)

*/
export async function assertPreflightWslDistroRunning(target: WslPreflightTarget): Promise<void> {
// No distro named means wsl.exe's default, which a probe would boot just the same.
const distro = target.distro?.trim() || (await listWslDistrosAsync())[0]

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 · Functional Correctness · Heavy lift

Resolve and pin the actual default distro.

listWslDistrosAsync retains a nonempty list, but the WSL default can change while Orca runs. After a default change, this gate can check the old distro while the subsequent command, which has no distro argument, starts the new stopped default. Resolve the current default and pass that same name to the command. (raw.githubusercontent.com)

Comment on lines +12 to +14
if (distro) {
await assertWslUncPathRunning('', distro)
}

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 · Functional Correctness · Quick win

Fail closed when the default distro cannot be resolved.

If distro discovery fails without a cached list, it returns []. This branch then skips the assertion, and preflight or agent detection can launch the default distro when a later WSL command succeeds. Return an unverifiable error instead. (raw.githubusercontent.com)

// The confirmed list that reported the stop also proves this distro is up.
void this.check(health.name, { confirmRunning: false })
// That list may still name a distro that is itself stopping: confirm, settled (E9).
void this.check(health.name, { confirmRunning: 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.

Major · Stability & Availability · Quick win

Require a new probe after the stop event.

The stop listener runs while the probe that produced running is still in flight. This check joins that same probe, so it does not independently confirm the distro. If another distro is also stopping but has not been marked stopped, the interop probe can start it again. Request a running-list read anchored after the stop event and its settle window. (raw.githubusercontent.com)

nwparker added a commit that referenced this pull request Oct 28, 2026
…-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.
@nwparker

Copy link
Copy Markdown
Contributor Author

Superseded by #35411 (preflight and agent detection, P1/P2) and #35412 (Settings CLI status, startup CLI repair, interop health, chat-link existence: P3/P4/P5/G3), which is stacked on #35411. I cross-checked them against this PR. The end-to-end preflight running-list test was ported into #35411. The stop-settle concern behind listSettledRunningWslDistros is covered by a per-distro settled read taken right before each CLI repair and interop probe or repair. P6 stays ungated and is now documented in code. Closing.

@nwparker nwparker closed this Oct 28, 2026
nwparker added a commit that referenced this pull request Oct 29, 2026
…-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.
nwparker added a commit that referenced this pull request Oct 29, 2026
…ed WSL distro (E9) (#35411)

* fix(wsl): background preflight and agent detection never boot a stopped 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.

* fix(wsl): a focus wakes only a focused WSL workspace's distro; end-to-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.

* test(wsl): model the running gate in the preflight RPC suite and cover a stopped distro

Windows CI runs the real gate, so the WSL detection case must state that the distro runs.

* fix(wsl): an agent refresh click never joins a background refresh it 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.

* fix(wsl): a refused background check waits for the distro, and an agent 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.

* fix(wsl): an open agent picker wakes a refused list once, and never retries 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.

* fix(wsl): forget agent-inventory refusals when the inventory or its project contexts are cleared
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