Repository navigation
perf(wsl): a held WSL spawn reads the running list once, reusing only its own read - #36077
Conversation
[Low impact] The change is limited to held WSL spawn checks in the main process. The PR should preserve the provider's ability to catch an external WSL stop before merging. Findings
SummaryReuses the startup WSL running-list read during the provider hold.
|
The provider-level holds (daemon adapter, daemon-off local provider) accept a running-list read started within a 5 s lease, so they reuse the startup-target hold's probe instead of running wsl --list --running again. A noted stop still forces a fresh read; a read older than the lease probes again.
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes.
|
There was a problem hiding this comment.
🔇 Additional comments: 1
src/main/daemon/daemon-wsl-passive-restore-hold.ts-30-30: 1
30-30:Major · Functional Correctness · Heavy lift
⚠️ Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.Keep a fresh final check when an unobserved stop is possible.
If WSL stops after a confirmed running probe without emitting a stop note, this five-second cutoff lets the provider hold reuse the old running result. The running-list cache accepts that result without another probe. A passive spawn can then start a stopped distro, although a fresh provider read would have blocked it. WSL idle stops are specifically identified as stops that may go unreported. Preserve the fresh final check unless a reliable stop observation can invalidate the lease. (raw.githubusercontent.com)

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:
17e3d04f-b495-4987-9eed-589bff2d9530
Files selected for processing: 6-
src/main/daemon/daemon-pty-adapter-wsl-passive-restore-hold.test.tssrc/main/daemon/daemon-pty-session-spawn.tssrc/main/daemon/daemon-wsl-hold-probe-lease.test.tssrc/main/daemon/daemon-wsl-passive-restore-hold.tssrc/main/providers/local-pty-provider-windows-shell-launch.test.tssrc/main/providers/local-pty-spawn.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
-
…running read Replaces the 5 s lease: the startup-target hold records a read anchor on the spawn's options and reads after it; the provider hold reads after the same anchor, so it reuses that spawn's read and nothing older. No anchor means a fresh read; a noted stop or wake still forces one.
b9248b9 to
1f82c28
Compare
…der hold A daemon respawn or a same-session history lock can sit between the two holds, so the provider hold reads after max(anchor, now - 2 s).
There was a problem hiding this comment.
Actionable comments posted: 1

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:
8288f429-9deb-4717-b5fa-df7252523991
Files selected for processing: 11-
src/main/daemon/daemon-wsl-hold-read-anchor.test.tssrc/main/daemon/daemon-wsl-passive-restore-hold.tssrc/main/ipc/pty/ipc/spawn-options.tssrc/main/ipc/pty/ipc/spawn-preflight.tssrc/main/ipc/pty/ipc/spawn-state.tssrc/main/ipc/pty/pty-spawn-wsl-passive-restore-hold.test.tssrc/main/ipc/pty/runtime/spawn-options.tssrc/main/ipc/pty/runtime/spawn-preflight.tssrc/main/ipc/pty/runtime/spawn-state.tssrc/main/ipc/pty/spawn-startup-target.tssrc/main/providers/pty-provider-contract.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
-
|
|
||
| /** The anchor a spawn's first hold reads after; later holds of the same spawn reuse that read. */ | ||
| export function wslHoldReadAnchor(): number { | ||
| return performance.now() - WSL_HOLD_READ_ANCHOR_SLACK_MS |
There was a problem hiding this comment.
Do not let the anchor accept another spawn’s read.
If a second held spawn starts within 1 ms of the first probe, subtracting the slack places its anchor before that probe. The running-list cache can then return the first spawn’s result instead of reading again. This breaks the per-spawn read guarantee and can miss an unnoted distro stop between the spawns. Capture an anchor that excludes earlier probes, and adjust the frozen-clock tests to verify closely spaced spawns. (raw.githubusercontent.com)
| startedAfter: Math.max( | ||
| opts.wslHoldReadAnchor, | ||
| performance.now() - WSL_HOLD_READ_MAX_AGE_MS | ||
| ) |
There was a problem hiding this comment.
Background spawns undo WSL shutdown
If an external wsl --shutdown stops the distro after the startup read, without an Orca stop note, the provider can reuse the earlier running answer for up to two seconds. It then allows the background spawn to start the distro again instead of holding it. The provider previously requested a fresh read and could catch that stop.
Restricting reuse to the same spawn does not close this gap. Keep a fresh check before the provider starts WSL, or otherwise preserve the stop decision.
ELI5
When Orca holds a WSL terminal it shouldn't start on its own (a passive restore or main's background start), it runs
wsl --list --runningto check whether the distro is running. Since #35971 that check ran twice for the same spawn: once early, at the startup target, and again in the terminal provider. Now the provider's check reuses the early answer, but only that same spawn's answer, so one held spawn runs one probe and nothing older can be trusted.Flag-off: applies to WSL bridge workspaces, which exist with
ORCA_INTERNAL_WSL_HOSTSunset too. Non-WSL, SSH and WSL-host (orcad) spawns never reach this check.User risk: low. Same hold decisions, one fewer
wsl.exeper held spawn.What Changed
spawn-startup-target.ts): when it holds a spawn with a resolved WSL distro, it takes a read anchor (wslHoldReadAnchor(),performance.now()minus 1 ms of slack) and reads the running list after that anchor. It returns the anchor in its target.ipc/spawn-preflight.ts,runtime/spawn-preflight.ts) keep it on their spawn state. Both option builders put it on the spawn's options aswslHoldReadAnchor.holdPassiveRestoreOfStoppedWslDistroreads withstartedAfter: max(opts.wslHoldReadAnchor, now - 2 s)(WSL_HOLD_READ_MAX_AGE_MS). The provider holds are the daemon adapter and the daemon-off local provider, and they pass the spawn's own options unchanged, so they reuse exactly the read made for that spawn, and only while it's under 2 s old. A daemon respawn or a same-session history lock between the two holds therefore can't stretch it.settledWslRunningReadAnchorstill raises the floor past any stop or wake Orca noted, which forces a fresh read.Why
e9-reviewer found the double probe. fix-reviewer then showed that a 5 s lease would let a stop Orca never notices (an external
wsl -tor--shutdown, or WSL's idle stop) slip past a background spawn's last check. Anchoring the reuse to the spawn's own read removes the double probe without widening that window. The provider hold stays, as the only guard for spawns that skip the preflight.Linked Issue
N/A (maintainer change; follow-up to #35971, #35938 and #35865)
Visual Proof
N/A: no UI change.
Testing
daemon-wsl-hold-read-anchor.test.ts, driving the real running-list cache with a counting probe:pty-spawn-wsl-passive-restore-hold.test.ts: the provider receives exactly the anchor the startup-target read used.structured-agent-session-create-adoption.test.ts:171, which this PR doesn't touch and which test: return a structured command from the adoption test's launch resolver #36081 fixes.cloud/andmobile/.relay-region-correctioncan't load locally because thepgpackage isn't installed.Review
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)