You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(wsl): start no running-distro read inside the stop settle window - #34372
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.
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.
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: 5
Check name
Status
Explanation
Title check
The title clearly and concisely describes the main WSL settle-window fix.
Description check
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
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
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
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.
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:settledStartedAfterused to sleep once withsetTimeout(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 theirperformance.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 untilperformance.now()has passed the anchor.src/main/wsl-background-distro-gate.test.ts: it wrapssetTimeoutto 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. Withrepeats: 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
repeats: 99fails on main and passes 400 of 400 with the fix.pnpm tc:node, oxlint, oxfmt, the flaky-test ratchet andcheck-changed-code-qualitypass.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 nostartedAfter, so it can join a running-list probe that started inside the settle window.Review
Agent skill upstream boundary
Notes
Windows/WSL only at runtime; the gate is platform-neutral code. No wire or compatibility change.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)