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): WSL host bridge dials, ready clients and holder re-ensures never boot a stopped distro (E9) - #35707
On a WSL host (WSL hosts flag on), a chat keeps a live connection to the Orca server inside the distro. When the user stopped the distro, that connection's automatic redial reached Orca's local bridge. The bridge launched wsl.exe to forward the redial, and that launch started the distro again about a second after the "Ubuntu is stopped" notice appeared. Now a background redial can't start a stopped distro. A real user act, such as Start, reconnect, opening a chat or a New Terminal, still can.
What Changed
The bridge listener checks the distro first (wsl-orcad-stdio-bridge.ts).
Before each per-socket orca_node_bridge --exec, it requires a settled "running" read: the cached one under the usual 60 s lease, so there is no wsl --list per socket. A stopped or unverifiable distro gets the dial refused, and the client's socket closes.
User acts still work. Every wsl.exe launch from the WSL host transport now calls noteWslDistroLaunched, so the user's connect, which launches into the distro first, makes any older "stopped" read stale. Its own bridges then pass on a fresh read.
A bridge the guest ends first now calls noteWslDistroMayHaveStopped. The next dial re-reads the running list instead of trusting a cached "running".
A ready runtime client (wsl-host-connector.ts) skips the cold reachability check only while the last settled running list still names the distro, via wasWslDistroLastSeenRunningSettled, a cache read with no probe. Before, a ready client counted as available even after its distro stopped.
Holder re-ensures from liveness (heartbeat, arm, live) now pass requireRunning to ensureHeld. It is checked right before the holder spawns, and a stopped distro is refused with WslDistroNotRunningError. A user ensure that arrives while a background one is in flight doesn't inherit its refusal. The holder's types move to wsl-distro-holder-types.ts to keep the module under max-lines.
The SSH path is unchanged:
the shared bridge listener (orcad-stdio-bridge-listener.ts) and provider are untouched;
the gate lives only in the WSL wrapper;
the shared-control reconnect is untouched.
Why
This is rule E9: background work never starts a stopped distro. The device trace showed the distro running within about 1 s of the stopped notice, followed by the holder and 7 bridge --exec launches.
Gating the one place every dial goes through covers chat reconnects, runtime calls and the watch probe at once. It also leaves the reconnect code that SSH shares alone. The fan-out after the boot (holder plus bridges) was correct once the distro was running; what was wrong was the first boot.
Linked Issue
Internal E9 (device finding (c)). No public issue.
Visual Proof
N/A. No UI change. With the distro stopped, the stopped notice now stays up until the user presses Start.
Testing
New wsl-orcad-stdio-bridge-e9.test.ts (real listener, real gate and running-list cache, fake wsl.exe children, only the --list --running probe faked). It checks that:
a dial into a stopped distro spawns nothing;
running-distro dials share one running read;
after the guest ends a bridge, the next dial re-reads and is refused once the distro has stopped;
a user act's launch isn't refused by the "stopped" read taken before it;
the shared SSH bridge path never reads WSL state.
Connector test: a ready client whose distro may have stopped gets the cold check (stopped).
Holder tests: a gated ensure re-reads right before spawning and never boots; a user ensure isn't refused by a gated one in flight.
Each fix fails its test when reverted: gate (all 4 bridge cases), guest note, launch note, fix 3, fix 4.
Load rule:pnpm tc, pnpm run typecheck:ci, check:code-quality:changed, anti-slop and the ast-grep gates pass. src/main/wsl, managed-server and ssh suites pass (390 files); one unrelated heartbeat test flaked under load and passes alone.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Flag-off: no behavior change with ORCA_INTERNAL_WSL_HOSTS unset; every change sits in the WSL-host (flag-on) bridge, connector, liveness and holder paths. The SSH listener and reconnect are untouched, and a test pins the SSH path as ungated.
User-risk: a background redial into a stopped WSL host now fails instead of booting it. The chat shows the existing stopped notice with Start. After a guest-side bridge close, the next dial waits about 500 ms (the stop-settle window) for one running read.
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.
Status
Ready for review: e9-reviewer and fix-reviewer-2.
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)
…never boot a stopped distro (E9)
With a chat open on a WSL host, terminating the distro let the control connection's quick
redial reach the still-open loopback listener, whose per-socket `orca_node_bridge --exec`
spawned wsl.exe and booted it again.
1. The WSL bridge listener admits a dial only on a settled running read (the cached one, under
the usual lease), refusing a stopped or unverifiable distro. Every wsl.exe launch from the
WSL host transport notes the distro as launched, so a user act's connect is never refused its
own bridges by a "stopped" read taken before it started the distro.
2. A bridge the guest ends first notes the distro may have stopped, so the next dial re-reads.
3. A ready runtime client skips the cold reachability check only while the last settled running
list names the distro.
4. Background holder re-ensures (liveness) re-read the running list right before spawning; a user
ensure never inherits a background one's refusal. The holder's types move to their own module.
The shared SSH bridge listener and the shared-control reconnect are unchanged.
The reason will be displayed to describe this comment to others. Learn more.
Normal closes stop session indexing
byGuest is also true when the server finishes closing a one-shot WebSocket request while the control socket stays open. Calling noteWslDistroMayHaveStopped then sends a distro-wide stopped notice. The Codex session bridge trusts that notice and stops its remaining indexing batches, even though the distro still runs.
Separate cache invalidation from the stopped notice, or confirm the distro stopped before notifying those listeners.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 10298410-703c-4542-96fe-4063f51401f2
Commits
Reviewing files that changed from the base of the PR and between 840deb3 and 6d8867c.
Files selected for processing: 5
src/main/wsl/wsl-host-connector.test.ts
src/main/wsl/wsl-host-connector.ts
src/main/wsl/wsl-orcad-bridge-activity.ts
src/main/wsl/wsl-orcad-stdio-bridge-e9.test.ts
src/main/wsl/wsl-orcad-stdio-bridge.ts
Walkthrough
The change adds exported WSL distro-holder types and a running-state gate for holder spawning. Host reachability now checks settled running-state evidence. The stdio bridge receives the distro name, checks its running state before opening channels, and records guest-side channel endings. The WSL transport records distro launches. Tests cover holder concurrency, reachability, and bridge behavior.
Priority: Normal
Merge Risk: Low · previous review 840de
Normal bridge closes may briefly make a running distro appear stopped. The impact appears bounded, so this is mergeable with owner awareness and a follow-up fix.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 25.00% 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 checks: 4 passed
Check name
Status
Explanation
Title check
The title names the main change: WSL host bridge dials, ready clients, and holder re-ensures are gated so they never boot a stopped distro. It matches the changeset (bridge gate in wsl-orcad-stdio-bri…
Description check
The description follows the template well. It has an ELI5, a What Changed section with the mechanism, a Why section, a linked-issue note, a Visual Proof N/A with reason, Testing details, a Review sect…
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: Title check
Explanation
The title names the main change: WSL host bridge dials, ready clients, and holder re-ensures are gated so they never boot a stopped distro. It matches the changeset (bridge gate in wsl-orcad-stdio-bridge.ts, connector readiness in wsl-host-connector.ts, requireRunning in the holder and liveness wiring). It is long at 101 characters and uses an internal ticket tag (E9), but it is specific and accurate.
Full details: Description check
Explanation
The description follows the template well. It has an ELI5, a What Changed section with the mechanism, a Why section, a linked-issue note, a Visual Proof N/A with reason, Testing details, a Review section, and an agent-skill boundary checkbox. Gaps: the Linked Issue section gives an internal reference (E9) and no public issue number, and the template's 'Fixes #' line is not filled in. The AI Disclosure section is missing, and the template's Notes section is not carried over. The unchecked 'pnpm lint, typecheck, test, build' box is left open, and the 'manually tested' box is unchecked while the author reports only automated testing. These gaps are noted in the resolution.
Resolution
Optional improvements: state the internal issue reference in the Linked Issue section, or confirm that no public issue applies for outside contributors. Confirm whether the AI Disclosure section applies. Check off or explain the unchecked lint, typecheck, test, and build item, and state whether the change was tested manually.
Full details: Docstring Coverage
Explanation
Docstring coverage is 25.00% 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 4 functions across 13 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Finishing Touches: 💡 1
📝 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.
The reason will be displayed to describe this comment to others. Learn more.
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: 957ed9e8-ac98-48f0-bd88-a910363a558c
Commits
Reviewing files that changed from the base of the PR and between 3b9c1d3 and 840deb3.
Files selected for processing: 13
src/main/wsl/wsl-distro-holder-types.ts
src/main/wsl/wsl-distro-holder.test.ts
src/main/wsl/wsl-distro-holder.ts
src/main/wsl/wsl-host-connector.test.ts
src/main/wsl/wsl-host-connector.ts
src/main/wsl/wsl-orcad-bridge-activity.test.ts
src/main/wsl/wsl-orcad-connection.ts
src/main/wsl/wsl-orcad-host-transport.ts
src/main/wsl/wsl-orcad-incumbent.ts
src/main/wsl/wsl-orcad-liveness-wiring.ts
src/main/wsl/wsl-orcad-stdio-bridge-e9.test.ts
src/main/wsl/wsl-orcad-stdio-bridge.test.ts
src/main/wsl/wsl-orcad-stdio-bridge.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Supported by static analysis
Script executed:
#!/bin/bash# Check what a "stopped" note does and who consumes it.
rg -nP -C4 'noteListeners|settledRunningFloor|mayHaveStoppedAt' src/main/wsl-background-distro-gate.ts
rg -nP -C3 '\bonWslDistroNote|subscribeWslDistroNotes|noteWslDistroMayHaveStopped' src --type=ts -g '!**/*.test.ts'
sed -n 1,60p src/main/wsl/wsl-orcad-bridge-activity.ts
Repository: stablyai/orca
Length of output: 15673
Script executed:
set -o pipefail
printf'%s\n''--- stdio bridge ---'
nl -ba src/main/wsl/wsl-orcad-stdio-bridge.ts | sed -n '1,110p'printf'%s\n''--- bridge activity observer and tests ---'
nl -ba src/main/wsl/wsl-orcad-bridge-activity.ts | sed -n '1,180p'
rg -n -F --glob '*.test.ts' -e 'server ends the stream first' -e 'observeWslOrcadBridgeChannel' -e 'byGuest' src/main/wsl src/main/managed-server src/main/ssh ||test"$?" -eq 1
printf'%s\n''--- cited test context ---'
nl -ba src/main/wsl/wsl-orcad-bridge-activity.test.ts | sed -n '80,145p'printf'%s\n''--- channel declaration and close/end wiring ---'
rg -n -F --glob '*.ts' -e 'export type RemoteCommandChannel' -e 'interface RemoteCommandChannel' -e 'class .*RemoteCommandChannel' -e 'writableEnded' -e "emit('end')" src/main/managed-server src/main/ssh src/main/wsl | head -160
Do not treat every guest-ended bridge as a stopped distro.
A normal WebSocket close can set byGuest to true: the desktop sends the close frame, then the server ends the stream first. The current callback then calls noteWslDistroMayHaveStopped(distro) even when another bridge remains open. This advances the stopped-state floor and emits a false stopped note.
Limit the stopped-state note to the last open bridge, or exclude close-handshake completions from this note.
…every guest-first close
A guest-first end is also how one-shot RPC sockets and WebSockets close normally; noting a stop
on each made the next dial wait out the settle and probe, flapped reachability, and fed false
stop notes to the session scanner. The note now rides WslOrcadBridgeActivity's exit signal: the
guest ending the last open bridge, outside the burst cooldown.
The reason will be displayed to describe this comment to others. Learn more.
Stopped distro starts again
onExit now invalidates the cached running list, but the two-second cooldown can skip it. After a normal last-socket close, another dial can refresh that list after the 500 ms settle wait. If the user then stops the distro before the cooldown ends, the real exit leaves that refreshed list untouched. A background redial trusts it and starts the stopped distro again.
Keep cache invalidation independent of the cooldown used for exit notifications.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
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
On a WSL host (WSL hosts flag on), a chat keeps a live connection to the Orca server inside the distro. When the user stopped the distro, that connection's automatic redial reached Orca's local bridge. The bridge launched
wsl.exeto forward the redial, and that launch started the distro again about a second after the "Ubuntu is stopped" notice appeared. Now a background redial can't start a stopped distro. A real user act, such as Start, reconnect, opening a chat or a New Terminal, still can.What Changed
wsl-orcad-stdio-bridge.ts).orca_node_bridge --exec, it requires a settled "running" read: the cached one under the usual 60 s lease, so there is nowsl --listper socket. A stopped or unverifiable distro gets the dial refused, and the client's socket closes.wsl.exelaunch from the WSL host transport now callsnoteWslDistroLaunched, so the user's connect, which launches into the distro first, makes any older "stopped" read stale. Its own bridges then pass on a fresh read.noteWslDistroMayHaveStopped. The next dial re-reads the running list instead of trusting a cached "running".wsl-host-connector.ts) skips the cold reachability check only while the last settled running list still names the distro, viawasWslDistroLastSeenRunningSettled, a cache read with no probe. Before, a ready client counted as available even after its distro stopped.requireRunningtoensureHeld. It is checked right before the holder spawns, and a stopped distro is refused withWslDistroNotRunningError. A user ensure that arrives while a background one is in flight doesn't inherit its refusal. The holder's types move towsl-distro-holder-types.tsto keep the module under max-lines.The SSH path is unchanged:
orcad-stdio-bridge-listener.ts) and provider are untouched;Why
This is rule E9: background work never starts a stopped distro. The device trace showed the distro running within about 1 s of the stopped notice, followed by the holder and 7 bridge
--execlaunches.Gating the one place every dial goes through covers chat reconnects, runtime calls and the watch probe at once. It also leaves the reconnect code that SSH shares alone. The fan-out after the boot (holder plus bridges) was correct once the distro was running; what was wrong was the first boot.
Linked Issue
Internal E9 (device finding (c)). No public issue.
Visual Proof
N/A. No UI change. With the distro stopped, the stopped notice now stays up until the user presses Start.
Testing
New
wsl-orcad-stdio-bridge-e9.test.ts(real listener, real gate and running-list cache, fakewsl.exechildren, only the--list --runningprobe faked). It checks that:Connector test: a ready client whose distro may have stopped gets the cold check (stopped).
Holder tests: a gated ensure re-reads right before spawning and never boots; a user ensure isn't refused by a gated one in flight.
Each fix fails its test when reverted: gate (all 4 bridge cases), guest note, launch note, fix 3, fix 4.
Load rule:
pnpm tc,pnpm run typecheck:ci,check:code-quality:changed, anti-slop and the ast-grep gates pass.src/main/wsl,managed-serverandsshsuites pass (390 files); one unrelated heartbeat test flaked under load and passes alone.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Flag-off: no behavior change with
ORCA_INTERNAL_WSL_HOSTSunset; every change sits in the WSL-host (flag-on) bridge, connector, liveness and holder paths. The SSH listener and reconnect are untouched, and a test pins the SSH path as ungated.User-risk: a background redial into a stopped WSL host now fails instead of booting it. The chat shows the existing stopped notice with Start. After a guest-side bridge close, the next dial waits about 500 ms (the stop-settle window) for one running read.
Agent skill upstream boundary
Status
Ready for review: e9-reviewer and fix-reviewer-2.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)