Skip to content

fix(wsl): restoring or switching to a WSL host workspace never boots its stopped distro - #36688

Merged
nwparker merged 2 commits into
mainfrom
nwparker/wsl-host-launch-restore-no-boot
Oct 31, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/wsl-host-launch-restore-no-boot

Conversation

@nwparker

@nwparker nwparker commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​64 $\color{#cf222e}{\Huge{\mathbf{−}}}$​134 $\color{#cf222e}{\Huge{\mathbf{−}}}$​70
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​40 $\color{#cf222e}{\Huge{\mathbf{−}}}$​141 $\color{#cf222e}{\Huge{\mathbf{−}}}$​101

ELI5

If you stop a WSL distro that Orca uses as a host, then quit and reopen Orca with that host's workspace last active, Orca started the distro again by itself. Clicking the workspace did the same, with no "stopped" card. Now reopening Orca or switching to the workspace leaves a stopped distro stopped. The workspace shows the existing stopped card with a Start button. Clicking Start, or opening a new terminal there, still starts it.

What Changed

Two separate paths booted the distro.

  1. The early wake at launch.
    • Before: src/main/index.ts ran wakeRememberedWslHosts right at startup. It ran wsl.exe -d <distro> --exec true for the last focused host, from orca-wsl-host-wake.json, with no running check. Every focus switch wrote that list.
    • After: removed. Nothing writes or reads the list any more, and a launch deletes a list an older build left behind (deleteLegacyWslHostWakeList).
  2. The window's focus report.
    • Before: the renderer reports the active workspace's host on every change, including the launch restore. WslHostService.focusHost then connected the host with boot allowed.
    • After: focusHost lifts any park and runs the same no-boot check runtime calls use (ensureWslHostForRuntimeCall, treating the focused host as visible):
      • a running distro reconnects with noBoot;
      • a stopped one is published as distro-stopped, which shows the existing stopped card with Start;
      • an unconfirmed one is refused, and liveness publishes the verdict.

Unchanged:

  • Start (startWslHostAndReloadProjects → wslHosts:connect) and New Terminal (startStoppedWslHostForUserAct) still boot the distro.
  • A due automation still wakes it, as before.

Why

E9 says background or passive work must never start a stopped distro. A launch restore is passive, and a sidebar click is navigation, not an explicit start.

The QA run (2 of 2) reproduced the boot 1–3 s after relaunch. The stopped card isn't gone from the code (WslHostStoppedCard via TerminalPaneRecoveryPortals); it just never showed, because focus booted the distro before any status could say "stopped". With focus no longer booting, the card appears again.

I gated focus in main rather than the renderer, so every window and every restore path gets the same rule. I reused the runtime-call check so focus and polls agree on what "running" means.

Flag-off: WSL hosts only exist with the flag on, so flag-off is unchanged. The launch only deletes an old list file if one exists.
User-risk: medium-low. After a stop, opening Orca or switching to a WSL-host workspace shows the stopped card instead of starting the distro, so one extra click (Start, or New Terminal) is needed. A distro that's still running reconnects as before. Warm relaunch with a running distro is unaffected; a cold relaunch no longer boots ahead of time.

Linked Issue

N/A (flag-on adhoc QA finding F3)

Visual Proof

N/A. It reuses the existing stopped card, which now appears again for this case.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • wsl-host-service.test.ts:

    • New: a launch restore or switch to a stopped host never connects it and publishes distro-stopped.
    • Rewritten: a confirmed-stopped host stays down for polls and for a switch back; once the distro runs, a switch reconnects with noBoot.
    • Rewritten: focus reads the running list before connecting, even with no bridge yet.
    • Removed: the early-wake tests.
  • wsl-host-pending-removal.test.ts: the early-wake cases are removed with the feature.

  • wsl-host-early-wake.test.ts: a launch deletes the old wake list.

  • All of src/main/wsl and the renderer IPC bridge tests pass (142 files, 1252 tests).

  • pnpm tc, typecheck:ci, oxlint, anti-slop, check:code-quality:changed, the flaky-test ratchet and the localization catalog all pass.

  • The e2e lanes (wsl-host-terminal-start, wsl-host-no-background-boot) already expect "boots only for Start or New Terminal". CI runs them.

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

  • SSH: unaffected. Only WSL hosts use focus wake and the early wake.
  • Remote compatibility: no wire change; wslHosts:focusHost keeps its signature.

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)

…its stopped distro

A launch booted the last focused WSL host's distro from an early-wake list,
and the window's focus report (sent for a launch restore as well as a click)
connected the host with boot allowed. Both started a distro the user had
stopped, and the stopped card never appeared. Focus now re-checks and
connects only a running distro; a stopped one is published stopped, so the
panes show Start. Start and New Terminal still boot it. The early wake is
gone, and a launch deletes the list an older build left.
@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

On Windows startup, the application deletes the legacy WSL host wake list after configuring the WSL hosts gate. Host focus checks reachability without booting a stopped distro. When the distro is running, focus can connect with noBoot: true. ensureForRuntimeCall accepts an optional visibility callback and uses a ready-generation counter to retry when reachability results may be stale. Tests cover these startup and focus behaviors.

Merge Risk: Moderate · up to b754f

Reopening Orca no longer boots a stopped WSL distro, which is the intended change. If the distro status check cannot be confirmed at launch, though, the restored workspace may stay disconnected with no status shown and no automatic retry. The test for the stopped-host focus path also has a weak assertion. Resolve the unconfirmed-status retry before merging.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description is detailed and covers the user impact, implementation, rationale, testing, and compatibility. However, the required Linked Issue section contains “N/A” instead of an actual issue link… Add the actual issue link in the Linked Issue section. If the author is a maintainer, attach a relevant pre-existing issue instead of using “N/A”.
Docstring Coverage Warning Docstring coverage is 66.67% 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: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: preventing stopped WSL distros from booting during workspace restoration or switching.
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: Description check

Explanation

The description is detailed and covers the user impact, implementation, rationale, testing, and compatibility. However, the required Linked Issue section contains “N/A” instead of an actual issue link.

Resolution

Add the actual issue link in the Linked Issue section. If the author is a maintainer, attach a relevant pre-existing issue instead of using “N/A”.

Full details: Docstring Coverage

Explanation

Docstring coverage is 66.67% 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 3 functions across 8 files.

Resolution

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

Finishing Touches
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

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

Nitpick comments: 1
src/main/wsl/wsl-host-service.test.ts: 1

420-424: Trivial · Maintainability & Code Quality · Quick win

Tie the stopped-state assertions to focusHost.

Clear both the reachability mock and the prior publication before calling focusHost. Then flush the asynchronous focus work before checking that it did not connect. Clearing only the reachability mock leaves the published-state assertion satisfied by the earlier setup.

Suggested fix
     // Switching back to one of its workspaces is navigation: it re-checks, never starts it.
+    connector.reachability.mockClear()
+    published.length = 0
     service.focusHost('wsl:ubuntu')
-    await vi.waitFor(() =>
+    await vi.waitFor(() => {
       expect(connector.reachability).toHaveBeenCalledWith('Ubuntu', 'wsl:ubuntu')
-    )
+      expect(published.at(-1)).toMatchObject({ environmentId: 'wsl:ubuntu', state: 'distro-stopped' })
+    })
+    await new Promise((resolve) => setImmediate(resolve))
     expect(connector.connect).not.toHaveBeenCalled()
-    expect(published.at(-1)).toMatchObject({ environmentId: 'wsl:ubuntu', state: 'distro-stopped' })

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: 3246926c-95b6-405c-b316-4544f70f3f12
Commits

Reviewing files that changed from the base of the PR and between bbd324a and 0e3df17.

Files selected for processing: 7
  • src/main/index.ts
  • src/main/wsl/wsl-host-early-wake.test.ts
  • src/main/wsl/wsl-host-early-wake.ts
  • src/main/wsl/wsl-host-pending-removal.test.ts
  • src/main/wsl/wsl-host-service.test.ts
  • src/main/wsl/wsl-host-service.ts
  • src/renderer/src/hooks/ipc-events/wsl-host-ipc-bridge.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

A focus re-check that read the running list while the distro was stopped
could finish after a user Start or New Terminal had connected, then publish
distro-stopped with terminals exited over the live host. Every ready publish
now bumps a per-host generation; a runtime call whose read a newer ready
overtook re-checks instead of parking.

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

Follow-up Comments

Outside diff Retry an unconfirmed host after launch.

237-237: Major · Stability & Availability · Heavy lift

Retry an unconfirmed host after launch.

When the initial running-list read returns unavailable, ensureWslHostForRuntimeCall rejects before publishing a status or connecting. focusHost discards that rejection. A reachability probe does not create a liveness entry, so a restored host can remain disconnected after the read recovers.

Publish an unverifiable status and register a no-boot retry for this focus path. Preserve the existing boot behavior for explicit Start and New Terminal actions.

Open the source location


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: 629ae2f9-c73b-4514-8bc9-341154dacff7
Commits

Reviewing files that changed from the base of the PR and between 0e3df17 and b754fa5.

Files selected for processing: 3
  • src/main/wsl/wsl-host-runtime-call.ts
  • src/main/wsl/wsl-host-service.test.ts
  • src/main/wsl/wsl-host-service.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

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