Skip to content

fix(wsl): start no running-distro read inside the stop settle window - #34372

Merged
nwparker merged 4 commits into
mainfrom
nwparker/wsl-hook-relay-settle-flake
Oct 27, 2026
Merged

nwparker merged 4 commits into
mainfrom
nwparker/wsl-hook-relay-settle-flake

Conversation

@nwparker

@nwparker nwparker commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​26 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​25
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​4 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1

ELI5

After a WSL distro stops, Windows keeps listing it as running for a short while. Orca waits out a half-second settle window before it trusts a "running" answer. But the wait used a single timer, and Node timers can wake up to about 2ms early, so the check sometimes ran just inside the window and still saw the stopping distro as running. Orca now keeps sleeping until the window has really passed.

What Changed

  • src/main/wsl-background-distro-gate.ts: settledStartedAfter used to sleep once with setTimeout(anchor - performance.now()). Node truncates timer delays to whole milliseconds and schedules them on libuv's millisecond loop clock. I measured 1540 of 2000 timers firing before their performance.now() target, by up to 1.87ms. The running-list probe then started inside the stop settle window, which breaks the gate's contract that "a running read started inside this window never counts". The function now loops until performance.now() has passed the anchor.
  • New test in src/main/wsl-background-distro-gate.test.ts: it wraps setTimeout to fire early and asserts that the probe starts at or after the settle bound. It fails on main every time and passes with the fix.

Callers whose anchor is already in the past, including relay recovery, the UNC gate and the daemon bridge exit, see no change. Only a future anchor after a stop or wake now waits at most about 2ms longer.

Why

src/main/agent-hooks/wsl-hook-relay-stop-settle.test.ts > "hook relay restart right after its distro stopped > waits out the settle window, sees the stop, and stays down" failed with "expected true to be false" (run 40482082597, shard 5/5, on #34303). Its explorer read probed about 1ms before the window closed. With repeats: 99, main reproduces that exact failure, and the fix passes 4 rounds of 100 at load average ~70. No timeouts were raised and no retries added.

Linked Issue

N/A, CI flake from #34195.

Visual Proof

N/A. No UI change.

Testing

  • The stop-settle test with repeats: 99 fails on main and passes 400 of 400 with the fix.
  • The new gate test fails on main and passes with the fix.
  • All 20 test files that import the gate, plus the stop-settle test, pass: 197 tests.
  • pnpm tc:node, oxlint, oxfmt, the flaky-test ratchet and check-changed-code-quality pass.
  • Codex review is clean. An independent review approved with P3s only; I applied the test-determinism one.

Possible follow-up, pre-existing and not changed here: the orcad liveness supervisor's re-read after EXIT_SETTLE_MS (wsl-orcad-liveness-supervisor.ts:229-230) passes no startedAfter, so it can join a running-list probe that started inside the settle window.

  • 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

Windows/WSL only at runtime; the gate is platform-neutral code. No wire or compatibility 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)

settledStartedAfter slept with one setTimeout until the settle anchor. Node truncates timer
delays to whole ms against a ms loop clock, so the wake can land up to ~2ms before the anchor
by performance.now(), and the probe then started inside the window and could still see the
stopping distro as running. That is the hook relay stop-settle flake ("expected true to be
false"). Sleep until performance.now() has passed the anchor.
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

settledStartedAfter now recalculates the remaining time and sleeps until the settle anchor passes. A test verifies that the running-distro probe starts no earlier than the settle deadline.

Priority: Normal

Merge Risk: Minimal · up to 94ac1

The runtime fix is mergeable, but the timing test should calculate its expected deadline after recording the stop notification.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main WSL settle-window fix.
Description check Passed The description is complete and focused. It explains the user-facing issue, implementation, rationale, testing, platform scope, visual proof, and checklist status. It also identifies the related issue…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within survi…
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 complete and focused. It explains the user-facing issue, implementation, rationale, testing, platform scope, visual proof, and checklist status. It also identifies the related issue context as CI flakiness from #34195.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.

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

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.

Nitpick comments: 1
src/main/wsl-background-distro-gate.test.ts: 1

71-79: Trivial · Functional Correctness · Quick win

Compute settledAt after the stop notification.

noteWslDistroMayHaveStopped records the production timestamp for the settle window, but the test computes settledAt first. The assertion can therefore pass when the probe starts after the test deadline but before the actual settle deadline.

Suggested fix
-    const settledAt = performance.now() + WSL_STOP_SETTLE_MS
     noteWslDistroMayHaveStopped('Ubuntu')
+    const settledAt = performance.now() + WSL_STOP_SETTLE_MS

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: 6588549e-71bf-49ee-97c9-5d87b6021f2f
Commits

Reviewing files that changed from the base of the PR and between 48de731 and 94ac155.

Files selected for processing: 2
  • src/main/wsl-background-distro-gate.test.ts
  • src/main/wsl-background-distro-gate.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.

@nwparker
nwparker merged commit 71f0c74 into main Oct 27, 2026
41 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