Skip to content

fix(wsl): show a stopped WSL host within a second of its stop, never exec-ing into it - #35823

Merged
nwparker merged 1 commit into
mainfrom
nwparker/wsl-liveness-stopping-poll
Oct 29, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/wsl-liveness-stopping-poll

Conversation

@nwparker

@nwparker nwparker commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​82 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​77
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​84 $\color{#cf222e}{\Huge{\mathbf{−}}}$​13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​71

Flag-off: WSL hosts only (flag on). The default bridge is unaffected.
User-risk: Low.

  • After a WSL host's distro is stopped from outside Orca, the chat's "is stopped" notice now appears within about 1 s of the stop finishing, instead of up to about 30 s.
  • If orcad itself crashes while its distro keeps running, recovery starts up to about 5 s later than before.
  • While the distro runs normally, no extra wsl.exe probes are made.

ELI5

When you stop a WSL distro yourself (for example with wsl --terminate), Orca should say "Ubuntu is stopped" right away. Sometimes it took up to 30 s, because Orca ran a command inside the distro to double-check while Windows still listed it as running. That check was slow to fail, and it retried on a growing delay. Now Orca waits for Windows' running list to drop the distro and checks it once a second, which is cheap and never starts the distro. A command that runs inside a distro while it is still stopping can start it again, so this also removes that risk.

What Changed

  • Before: a liveness exit (the holder process or the last bridged socket ended) waited the 500 ms settle window and re-read wsl --list --running. If the distro was still listed, as one that is still stopping can be, the supervisor ran the guest identity check (wsl.exe --exec, 10 s timeout).
    • That check failed to unverifiable, which then retried after 1, 2, 4, 8 and 16 s, capped at 30 s.
    • The chat's "is stopped" notice, which only follows the host's distro-stopped status, waited for whichever retry first saw the list drop the distro.
    • The exec into a still-stopping distro could also start it again after the stop finished (E9).
  • After (new wsl-orcad-liveness-stopping-poll.ts, used from WslOrcadLivenessSupervisor.run() for every holder or watch exit):
    • After the settle, while the list still names the distro, it re-reads only the running list every 1 s, for up to 5 s.
    • Each read must be a probe started after the previous one (new optional probedAfter on readRunning, combined with the settle anchor in the wiring), so a cached list can't answer.
    • As soon as the list drops the distro, the verdict is distro-stopped and is published.
    • Only if the distro is still listed when the window ends does today's identity and port evidence run. That's the real case of orcad crashing while its distro keeps running.
  • Busy entry: an exit that arrives while a recovery is waiting out its backoff now ends that recovery (noteSupervisedExit wakes the wait and supersedes the recovery's generation). The pending exit then re-reads the list immediately, instead of waiting behind a backoff of up to 30 s.
  • Unchanged:
    • the 120 s heartbeat;
    • the verify backoff for genuine probe failures (running-list-unavailable);
    • the settle window;
    • every never-boot rule.

Why

  • The running list is the only boot-free signal of a stop. Polling it briefly after an exit is cheap: at most 5 wsl --list --running reads per exit event, and none while the distro is running. An exec into the distro is both slow to fail and an E9 hazard.
  • Every exit trigger, not only holder exits. On a terminate, the bridged-socket exit can arrive first, and the exec hazard applies to it as well. The cost is that recovery starts up to about 5 s later after a real orcad crash.
  • End the recovery wait rather than add a parallel check. That keeps one run in flight per distro, so the existing busy and pending ordering still holds.

Linked Issue

Internal WSL tracker, E9; device notes from wsl-verify-7 (v18 and v2: the chat notice took up to about 30 s). The next device pass logs status publishes and list drops with timestamps.

Visual Proof

N/A in this PR. The device pass will time the notice.

Testing

New supervisor tests. Each fails with its change reverted (the poll, or the busy-entry wake):

  • An exit while the distro is still listed: nothing runs inside it mid-window, and distro-stopped is published within one poll of the list dropping it.
  • An exit while the distro stays listed: the identity check runs only after the window.
  • An exit during a recovery backoff of more than 2 s publishes distro-stopped about 0.6 s after the exit.
  • Three heartbeats make exactly three running-list reads, so there are no added probes while running.

Wiring test: each stopping-window poll asks for a probe started after probedAfter, never older than the exit's settle anchor.

Four existing supervisor tests now advance through the stopping window. Their verdicts are unchanged.

Also run:

  • the wsl and daemon suites: 4,258 pass;
  • the load rule: pnpm tc, typecheck:ci, check:code-quality:changed, the anti-slop lint, oxlint and the ast-grep gates.

Not run on Windows.

  • 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

  • Verdict vocabulary: unchanged (live / unverifiable / exited). A still-listed distro is never called stopped; the change only waits for the list.
  • Scope: SSH is unaffected. There is no wire change.

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)

…exec-ing into it

After a watch or holder exit, a distro the running list still names is
usually stopping. Liveness now re-reads only the running list (never
boots) once a second for up to 5 s before any identity exec, and
publishes distro-stopped as soon as the list drops it. An exit that
arrives during a recovery backoff ends that recovery so the exit
re-checks at once (E9).
@coderabbitai

coderabbitai Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 3 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

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: 25d65c9a-8eab-49e6-81f5-94b6f9101a75
Commits

Reviewing files that changed from the base of the PR and between def7fad and 9b4f62b.

Files selected for processing: 6
  • src/main/wsl/wsl-orcad-liveness-state.ts
  • src/main/wsl/wsl-orcad-liveness-stopping-poll.ts
  • src/main/wsl/wsl-orcad-liveness-supervisor.test.ts
  • src/main/wsl/wsl-orcad-liveness-supervisor.ts
  • src/main/wsl/wsl-orcad-liveness-wiring.test.ts
  • src/main/wsl/wsl-orcad-liveness-wiring.ts
  • 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 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect WSL Orcad supervision and the timing of WSL host status updates.

Fix the overlapping-exit case before merging, because Orca can still run a command inside a stopping distro.

Findings

  1. P1 Later exits keep old timing ▶

Summary

This PR adds a short running-list poll after WSL holder or watch exits.

  • WSL stop checks wait for the running list to drop a stopping distro.
  • A new WSL exit wakes the check waiting behind recovery.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Watch or holder exits] --> B[Read running list]
  B --> C{Still listed?}
  C -->|No| D[Publish distro-stopped]
  C -->|Yes| E[Wait for settle]
  E --> F[Poll fresh running list]
  F --> G{Still listed?}
  G -->|No| D
  G -->|Yes, window remains| F
  G -->|Yes, window ended| H[Read guest identity]
  I[Another holder exit] --> J[Queue pending exit]
  J -. Current poll keeps its old exit time .-> F
Loading

Reviews (1) · Last reviewed commit: "fix(wsl): show a stopped WSL host within..." · Reviewed by Greptile

Comment on lines +30 to +33
running = await args.readRunning({
distro: args.distro,
exitedAt: args.exitedAt,
probedAfter: args.now()

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 Later exits keep old timing

If the watch exits first and the holder exits near the stopping window's end, this poll keeps the first exit's exitedAt and deadline. A clean holder exit does not update the shared gate's stop time either. The final poll can accept a still-listed distro before the newer exit settles, then call readIdentity while it is stopping. That command can restart the distro the user just stopped.

Restart or supersede the current check when another exit arrives, and use the latest exit time before collecting guest evidence.

@nwparker
nwparker merged commit 6568e88 into main Oct 29, 2026
52 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