Skip to content

fix(wsl): WSL host bridge dials, ready clients and holder re-ensures never boot a stopped distro (E9) - #35707

Merged
nwparker merged 2 commits into
mainfrom
nwparker/e9-wsl-bridge-listener-gate
Oct 29, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/e9-wsl-bridge-listener-gate

Conversation

@nwparker

@nwparker nwparker commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​304 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​303
Prod 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​156 $\color{#cf222e}{\Huge{\mathbf{−}}}$​74 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​82

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.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

  1. 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.
  2. A bridge the guest ends first now calls noteWslDistroMayHaveStopped. The next dial re-reads the running list instead of trusting a cached "running".
  3. 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.
  4. 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.
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 3/5

[Medium impact] The changes affect background connection and recovery paths for WSL hosts.

The PR needs another fix before merging because background redials can still restart a stopped distro.

Findings

  1. P1 Stopped distro starts again ▶
  2. P1 Normal closes stop session indexing ▶

Summary

Adds running-state checks to WSL bridge dials, ready-client checks, and background holder starts.

  • WSL bridge dials check that the distro is running before opening a channel.
  • A ready runtime client counts as available only while its distro is confirmed running.
  • Background liveness only starts a holder when its distro is already running.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Last socket closes normally] --> B[Stop note starts cooldown]
  B --> C[Next dial refreshes running list]
  C --> D[User stops distro within cooldown]
  D --> E[Exit callback is skipped]
  E --> F[Background redial trusts cached running list]
  F --> G[Bridge launch restarts distro]
Loading

Reviews (2) · Last reviewed commit: "fix(wsl): note a possible stop only on t..." · Reviewed by Greptile

Comment thread src/main/wsl/wsl-orcad-stdio-bridge.ts Outdated
Comment on lines +56 to +57
if (byGuest) {
noteWslDistroMayHaveStopped(distro)

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 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.

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 11 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: 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: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning 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 Passed checks: 4 passed
Check name Status Explanation
Title check Passed 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 Passed 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 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: 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.

❤️ 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.

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.

Comment thread src/main/wsl/wsl-orcad-stdio-bridge.ts Outdated
Comment on lines +54 to +60
ended: (byGuest) => {
// The guest ending a bridge is the first sign it may have stopped: later dials re-read.
if (byGuest) {
noteWslDistroMayHaveStopped(distro)
}
events?.ended(byGuest)
}

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.

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

Repository: stablyai/orca

Length of output: 13859


Script executed:

set -o pipefail
printf '%s\n' '--- listen/event call sites ---'
rg -n -F --glob '*.ts' -e 'listenWslOrcadStdioBridge(' -e 'listenWslOrcadStdioBridgeOnPreferredPort(' -e 'events: activity.events' -e 'activity.events(' -e 'WslOrcadBridgeChannelEvents' src/main || test "$?" -eq 1
printf '%s\n' '--- bridge provider channel contract ---'
nl -ba src/main/managed-server/install/remote-install-transport.ts | sed -n '1,70p'
nl -ba src/main/managed-server/lifecycle/orcad-stdio-bridge-provider.ts | sed -n '1,230p'
printf '%s\n' '--- relevant bridge setup owners ---'
rg -n -F --glob '*.ts' -e 'probeThenWatchWslOrcadBridges' -e 'WslOrcadBridgeActivity' -e 'wsl-orcad:' src/main/wsl src/main/managed-server src/main/ssh | head -180

Repository: stablyai/orca

Length of output: 9574


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.
byGuest && (last === undefined || this.now() - last >= WSL_ORCAD_BRIDGE_EXIT_COOLDOWN_MS)
if (exit) {
this.lastExitAt.set(key, this.now())
onExit?.()

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 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!

@nwparker
nwparker merged commit 4296f77 into main Oct 29, 2026
87 of 89 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