Skip to content

feat(wsl): WSL distro hosts, main-process wiring and persistence (WSL-via-orcad C7a, experimental) - #27933

Merged
nwparker merged 19 commits into
mainfrom
nwparker/wsl-c7-host-wiring
Oct 13, 2026
Merged

nwparker merged 19 commits into
mainfrom
nwparker/wsl-c7-host-wiring

Conversation

@nwparker

@nwparker nwparker commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1380 $\color{#cf222e}{\Huge{\mathbf{−}}}$​9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1371
Prod 53 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2026 $\color{#cf222e}{\Huge{\mathbf{−}}}$​107 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1919

Stacked on #27916; folds in #27789 (C2, cherry-picked unchanged; #27789 can be closed once this lands). Part 1 of 2: the UI is in the stacked draft on top of this one.

ELI5

Windows users can (behind an Experimental switch) turn a WSL distro into a host, just like an SSH machine. This part is the plumbing: list the distros, set the distro up as a host, remember it, keep it connected, and forget it again.

What Changed

Before: the WSL pieces from C1–C6 (transport, distro holder, deploy and launch, bridge connection, liveness) existed but nothing used them; there was no way to add a distro as a host.

After (main process, nothing visible yet without part 2):

  • Distro list (wsl-host-distro-list.ts): registered distros from the Lxss registry key (name, registration GUID, WSL 1 vs 2) plus running/stopped from wsl --list --running, which never boots anything. Docker Desktop's distros are dropped.
  • Add (WslHostService.add): refuses WSL 1 (with the wsl --set-version fix), an already-added distro, and a stopped distro unless the user explicitly asked to start it. Then it runs C4 deploy and launch through the C6 supervisor's user-initiated connect, and saves the result: a plain paired runtime environment (runtime:<envId>, named <distro> (WSL)) plus its C2 record in orca-wsl-host-deployments.json (distro, unbraced registry GUID, bridge and orcad ports). The environment id is C5's own wsl:<distro> id, so liveness, the account shim (C9) and the record agree.
  • Keeping the pairing current: C5's onChange feeds the service; a relaunch's new device token (or a moved bridge port) is written to the environment and record, and the old transport is retired so clients re-authenticate.
  • When it connects: never in the background. A WSL host connects (and may boot its distro) only on an explicit add or Connect, or while a project or terminal the user has open lives on it (the renderer reports that set; part 2). That set is also C6's hasUserVisibleWork. Runtime calls to a WSL host go through the same seam SSH-managed servers use (resolveManagedRuntimeEnvironment), which skips all SSH tunnel logic for WSL.
  • Startup: holders a previous run left are adopted (C3) only when a WSL host exists; nothing is booted.
  • Remove: closes the connection, releases the distro's holder (C3 release), drops the environment and the WSL record, and retires client-side state. The generic server remove routes WSL hosts here too.
  • R25 (wsl-host-ssh-orcad-conflict.ts): before deploying, the distro's orcad identity (the public half of ~/.orca/orca-e2ee-keypair.json; the private key never leaves the distro) is compared with every server this desktop already pairs with. A match means the distro already runs the orcad of, e.g., an SSH target at 127.0.0.1:2222, and the add is refused with a message naming that server. Limits: an orcad deployed by another desktop is not ours to see (C4's activation admission still guards it), and a data dir moved off ~/.orca is not checked. Conversion is later work.
  • New desktop-only IPC (wslHosts:*) and a preload API that exists only on Windows (or under the e2e fake), plus the experimentalWslHosts setting (default off; add is refused while off, and no lazy connect or holder adoption runs).
  • ORCA_E2E_FAKE_WSL_HOSTS: an e2e-only connector that stands in for wsl.exe and points a "distro" at a headless Orca server, so CI on any OS drives the real add-host flow.

Why

Reusing the paired runtime-environment store (rather than a new host kind) makes the WSL host a normal runtime:<envId> everywhere: pickers, routing, terminals, the folder browser. The C2 record stays in its own file so builds older than #27685 never see a record they would reject; to such a build the host reads as a server it cannot reach, and nothing is lost. Lazy, user-driven connects follow the background-distro rule (a wsl.exe into a stopped distro boots it and, before WSL 3.0.1, can break interop in other distros). Refusing R25 now is safer than two desktop-side owners of one orcad install; converting reuses D0 later.

Linked Issue

Track C of WSL via orcad (C7).

Visual Proof

N/A in this part: main-process only. Screenshots of the UI that uses it are on the stacked UI draft.

Testing

  • I manually tested these changes locally (the fake-transport e2e on the UI draft drives this code end to end on macOS)
  • Automated tests added/updated, or explained why not below

New unit tests: wsl-host-service.test.ts (add, WSL 1 / added / stopped refusals, R25 refusal, deferred activation, flag off, token persistence from onChange, lazy connect only for open work, remove, startup adoption), wsl-host-distro-list.test.ts (registry parse, Docker filter, running state), runtime-environment-wsl-host-store.test.ts (add, bridge-port check, refresh, remove).

Gates run locally: pnpm tc, affected main and renderer suites (1,098 files), oxlint, check:code-quality:changed (incl. React Doctor and design system), focus-read, layout-writer, max-lines, ts-nocheck, runtime-electron, reliability, dead-classes, zustand fan-out, anti-slop, process-host and compat-boundary imports, rpc-params and ACP catalogs, localization catalogs/extraction/coverage, node pin, pnpm format.

Not run: a packaged build on a real Windows host. This isolated agent could not send commands to win-lowspec, so real-host evidence is C4–C6's harness runs; C7's own wsl.exe paths are C4/C5/C6 code plus one reg.exe query and one sed read.

AI Disclosure

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

  • Remote wire: no RPC, stream or published-content change; all new IPC is desktop-local.
  • SSH: unaffected; the only shared seam branches on orcadDeployment.kind === 'wsl' before any SSH logic.
  • Cross-platform: the service and API exist only on Windows (or under the e2e fake).
  • Existing \\wsl.localhost projects are untouched.

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)

Follow-up commits (review decisions)

  • 78f9b911576 One registry reader: C4's readWslDistroRegistryId and the host distro list now share readWslDistroRegistrations, which returns the canonical lowercase unbraced GUID (what C2's schema accepts) plus each distro's WSL version. C7's private parser is gone. Tests cover braced registry output.
  • 6617ceefc3c With the experiment off, main refuses to connect a WSL host (explicit or background); removal still works. The pre-deploy refusals moved to wsl-host-add-admission.ts.
  • dd1f76076f5 Removing a connected WSL host now ends its orcad right away (only in a distro already running; never boots one), then releases the holder.

Follow-up commits (win-lowspec smoke)

  • 757393ca4d8 (B2) A build without the orcad template now refuses WSL host add and connect before any deploy work, and skips lazy connects and holder adoption. The message is "This build of Orca can’t run WSL hosts (server files missing)." It uses the same hasOrcadTemplate() check SSH hosts use, exposed as wslHosts:getCapability, an optional preload call (older preloads leave it unknown).
  • bd8af001c83 Test support: the e2e WSL fake can re-read its distro list from a file, so a test can register a distro mid-run.

Follow-up commits (win-lowspec smoke 2)

  • 4162831657d (B1) Remove ends what Orca runs in the distro: terminals through orcad's terminal RPC (terminal.list then terminal.stop per worktree), the terminal census until it proves zero sessions, then the managed decommission SSH hosts use (--complete-managed-stop with retireIdleDaemon), which stops orcad and retires the now idle daemon. Anything left running (terminals, an unanswered census, a daemon that did not retire) is returned to the UI; the host is removed regardless. A host that isn't connected but whose distro is running is connected first (no boot) so the same path runs; a stopped distro runs nothing.
  • 4162831657d (B3) Turning the experiment off closes every connection and liveness watch, releases the holders so distros can idle-stop, and stops liveness relaunching for visible work; turning it on reconnects only hosts that open work needs.
  • 3182141e74b (B2, main half) WSL hosts are left out of the servers a phone lists or routes to through this desktop.

Follow-up commits (awin smoke)

  • 72d623a4a60 Remove ends terminals through the host's routed environment (by environment id, with the saved pairing every other call uses) instead of the bridge's raw pairing offer, which failed fast against a real orcad. Removal first stops tracking the host (open work, connects, runtime calls), and a spawn guard in the connector refuses any holder, deploy or bridge for a distro whose host is gone, which ends the respawn loop seen after removal. A WSL host that isn't connected answers runtime calls with the reason instead of failing as an unreachable network server.
  • 20fd1a791d2 Unreachable-server hints are chosen by the owner host's kind: WSL hosts get a reconnect hint, never Tailscale.
  • 7f94d922012 The terminal list is parsed with a schema; the e2e fake logs its connects to a file and runs the real terminal steps against the headless server.

Follow-up commit (awin re-smoke)

  • 678f9e4ed26 Remove closes each terminal by handle (terminal.close), so a terminal whose project is already gone no longer throws selector_not_found and aborts the removal; failures are named and the server is still asked to stop. "Stopped" is reported only when the census shows no session left, the daemon retired, and the orcad the distro records as active is the one this computer was connected to (by runtime id). A re-add that adopted an orcad the record does not name is reported, not claimed stopped.

@nwparker
nwparker force-pushed the nwparker/wsl-c6-liveness branch from 9ac0ba7 to 2b419a3 Compare October 12, 2026 10:39
@nwparker
nwparker force-pushed the nwparker/wsl-c7-host-wiring branch from dd1f760 to e03eef2 Compare October 12, 2026 10:39
@nwparker
nwparker force-pushed the nwparker/wsl-c6-liveness branch from 2b419a3 to caf2132 Compare October 12, 2026 12:00
@nwparker
nwparker force-pushed the nwparker/wsl-c7-host-wiring branch 2 times, most recently from 678f9e4 to 82b4a9c Compare October 12, 2026 16:25
@nwparker
nwparker force-pushed the nwparker/wsl-c6-liveness branch from caf2132 to 7d5d2c4 Compare October 12, 2026 16:25
nwparker added a commit that referenced this pull request Oct 13, 2026
C7a (#27933) predates the main sync-spawn ratchet (#27756); drop once C7a carries this row.
@nwparker
nwparker force-pushed the nwparker/wsl-c6-liveness branch from 7d5d2c4 to 4e4aa55 Compare October 13, 2026 13:14
…mental flag (WSL-via-orcad C7a)

Main-process wiring for WSL hosts: list registered WSL 2 distros, add one (C4 deploy and
launch through C6 liveness, then persist the paired environment and its C2 record), keep a
relaunch's new device token, connect a host only for the user or an open project or terminal,
adopt holders at startup, and remove a host (release its holder, drop both records). Refuses a
distro whose orcad this desktop already reaches as another server (R25).
…he canonical unbraced GUID

C4's registry reader returned the braced GUID while the C2 record only accepts it unbraced, and
C7 parsed the same output a second time. The one reader now yields lowercase unbraced ids and
each registration's WSL version; the host distro list uses it.
Adding, connecting and background connects all stop while Experimental → WSL distros as hosts
is off; removing still works. The pre-deploy refusals move to their own module.
Remove ended the bridge and released the distro's holder but left orcad to exit with the
distro. A connected server is now ended right away, only in a distro already running.
… say so up front

A build shipped without the orcad deployment template let the add dialog run and fail after
seconds with a raw internal error. Main now checks the template as SSH hosts do, refuses add
and connect (and skips lazy connects and holder adoption) before any deploy work, and exposes
the capability so the UI can show it.
…ts when the experiment is off

Remove now ends the host's terminals through orcad's terminal RPC, waits for the terminal census
to prove none remain, closes the bridge, and runs the managed decommission SSH hosts use, which
stops orcad and retires its idle terminal daemon. What it could not end is reported back.

Turning Experimental → WSL distros as hosts off closes every connection and liveness watch,
releases the holders so distros can idle-stop, and keeps liveness from relaunching for visible
work; turning it on resumes only the hosts open work needs.
…his desktop

They are this desktop's own distros, connected only for work open here; a phone listing or
routing to one would wake it behind the user's back.
…ever respawn it

Removal reached orcad with the bridge's raw pairing offer rather than the routed environment and
saved pairing the app already uses for the host; on a real orcad ending terminals failed fast and
left them, the daemon and orcad running. It now calls by environment id through the same
transport as every other call to the host, and the e2e fake runs these real steps against a
headless server.

Removal also stops tracking the host first (open work, connects, runtime calls), so nothing
reconnects it while it stops, and a spawn guard in the connector refuses any holder, deploy or
bridge for a distro whose host is gone (the respawn loop after removal). A WSL host that isn't
connected answers runtime calls with why, instead of failing as an unreachable network server.
…'t be reached

Unreachable-server hints are chosen by the owner host's kind: a WSL host is a distro on this
computer, so it points at its reconnect instead of the Tailscale advice for network servers.
…ed only on proof

Removal stopped terminals per workspace, so one orphan whose project was gone threw
selector_not_found and aborted before orcad was stopped. It now closes each terminal by handle,
keeps going past failures and names them, and still asks orcad to stop.

It reports stopped only when the census shows no session left, the daemon retired, and the
orcad the distro records as active is the one this computer was connected to; a re-add that
adopted an orcad the record does not name is reported instead of claimed stopped.
WSL distros as hosts must not be reachable by users until moving a project
between hosts is lossless and the feature matches today's WSL support.
ORCA_INTERNAL_WSL_HOSTS=1 opens the gate; otherwise main creates no WSL host
service (no holder adoption, wsl.exe spawn or reconnect), refuses add,
connect, remove and every runtime call to a WSL host, keeps persisted WSL
hosts out of the server list, startup status probes and AI vault scans while
leaving them on disk, and the preload exposes no WSL host API.
…ent file holds

An unreadable WSL record no longer hides an SSH-linked server, and with the internal gate closed a corrupt WSL file is warned about instead of failing the whole registry.
A WSL host always pairs over a loopback endpoint, so a stale record can no longer remove a remote paired server from the list.
…ate is closed

A newer or stale record could otherwise hide a re-paired loopback server for users who never open the gate.
@nwparker
nwparker changed the base branch from nwparker/wsl-c6-liveness to main October 13, 2026 14:45
@nwparker
nwparker marked this pull request as ready for review October 13, 2026 14:45
@nwparker
nwparker force-pushed the nwparker/wsl-c7-host-wiring branch from cec0e91 to 84d5cc7 Compare October 13, 2026 14:45
@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The changes add WSL distributions as managed runtime environments. They introduce deployment storage, distro discovery, host connection and shutdown flows, service lifecycle management, and IPC/preload APIs. Runtime routes apply the internal gate and handle WSL deployments separately from SSH deployments. SSH target consumers now use SSH-specific deployment lookups, and unreachable errors can include a WSL distro reconnect hint.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 84d5c

The WSL host support is off by default behind an internal flag. When the flag is enabled, there are three edge cases: a host can get stuck after a failed save or removal, and WSL hosts can appear in the SSH server list with actions that fail. These are low-risk follow-ups.

Pre-merge checks · Passed 4 · Inconclusive 1

Failed Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 30.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 75 functions across 50 files. (17 skipped… 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 clearly identifies the main change: experimental WSL distro hosts, main-process wiring, and persistence.
Description check Passed The description is detailed and covers the required explanation, changes, rationale, testing, visual proof, compatibility notes, and checklist. The linked issue is described as “Track C of WSL via orc…
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: Docstring Coverage

Explanation

Docstring coverage is 30.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 75 functions across 50 files. (17 skipped: 17 over the file limit.)

✨ 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: 3


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 69b5a96d-6bed-4baa-b15a-ca81df208be7
📥 Commits

Reviewing files that changed from the base of the PR and between 5e9489c and 84d5cc7.

📒 Files selected for processing (67)
  • src/main/ai-vault/runtime-session-scanner.ts
  • src/main/ephemeral-vm-runtime-environment-release.ts
  • src/main/ipc/managed-orcad-actions.ts
  • src/main/ipc/register-core-handlers/register-core-handlers.test.ts
  • src/main/ipc/register-core-handlers/register-core-handlers.ts
  • src/main/ipc/runtime-environment-connectivity-handlers.ts
  • src/main/ipc/runtime-environment-managed-tunnel.ts
  • src/main/ipc/runtime-environment-mobile-relay-hosts.test.ts
  • src/main/ipc/runtime-environment-mobile-relay-hosts.ts
  • src/main/ipc/runtime-environment-status-probe.ts
  • src/main/ipc/runtime-environment-support-routing.ts
  • src/main/ipc/runtime-environment-tailscale-response.ts
  • src/main/ipc/runtime-environment-transport-routing.ts
  • src/main/ipc/runtime-environment-unreachable-hint.test.ts
  • src/main/ipc/runtime-environment-unreachable-hint.ts
  • src/main/ipc/runtime-environments.ts
  • src/main/ipc/wsl-host-gate-off.test.ts
  • src/main/ipc/wsl-host-handlers.ts
  • src/main/runtime/mobile-desktop-relay/mobile-desktop-relay-hosts.ts
  • src/main/ssh/orcad-managed-migration-status.ts
  • src/main/ssh/orcad-managed-runtime-context.ts
  • src/main/ssh/orcad-retained-source.ts
  • src/main/ssh/orcad-runtime-conversion.ts
  • src/main/ssh/orcad-runtime-decommission.ts
  • src/main/ssh/orcad-runtime-deployment.ts
  • src/main/ssh/orcad-ssh-provisioning.ts
  • src/main/wsl/wsl-distro-registry-id.test.ts
  • src/main/wsl/wsl-distro-registry-id.ts
  • src/main/wsl/wsl-host-add-admission.ts
  • src/main/wsl/wsl-host-connection-record.ts
  • src/main/wsl/wsl-host-connector.ts
  • src/main/wsl/wsl-host-distro-list.test.ts
  • src/main/wsl/wsl-host-distro-list.ts
  • src/main/wsl/wsl-host-e2e-fake-connector.ts
  • src/main/wsl/wsl-host-gate.ts
  • src/main/wsl/wsl-host-server-stop.test.ts
  • src/main/wsl/wsl-host-server-stop.ts
  • src/main/wsl/wsl-host-service-instance.ts
  • src/main/wsl/wsl-host-service.test.ts
  • src/main/wsl/wsl-host-service.ts
  • src/main/wsl/wsl-host-ssh-orcad-conflict.ts
  • src/main/wsl/wsl-orcad-deploy.test.ts
  • src/preload/api/runtime-api.ts
  • src/preload/api/runtime-environments-bridge.ts
  • src/preload/api/wsl-hosts-api.test.ts
  • src/preload/api/wsl-hosts-api.ts
  • src/renderer/src/components/settings/ManagedServersSection.tsx
  • src/renderer/src/lib/recipe-vm-managed-host.ts
  • src/renderer/src/lib/ssh-workspace-browser-route-eligibility.test.ts
  • src/renderer/src/lib/ssh-workspace-browser-route-eligibility.ts
  • src/renderer/src/store/slices/runtime-environment-peer-replacement.ts
  • src/shared/default-global-settings.ts
  • src/shared/execution-host-registry.ts
  • src/shared/global-settings-types.ts
  • src/shared/managed-orcad-execution-host.test.ts
  • src/shared/managed-orcad-execution-host.ts
  • src/shared/runtime-environment-managed-orcad-store.ts
  • src/shared/runtime-environment-sidecar.ts
  • src/shared/runtime-environment-store-file.ts
  • src/shared/runtime-environment-wsl-host-store.test.ts
  • src/shared/runtime-environment-wsl-host-store.ts
  • src/shared/runtime-environments.ts
  • src/shared/wsl-host-deployment-link.ts
  • src/shared/wsl-host-deployment-store.test.ts
  • src/shared/wsl-host-deployment-store.ts
  • src/shared/wsl-host-internal-gate.ts
  • src/shared/wsl-host-types.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.

Comment on lines +141 to +157
this.removing.add(environmentId)
this.visible.delete(environmentId)
const connector = this.connector
let serverStop: WslHostServerStop = { stopped: true }
if (connector) {
serverStop = await connector
.stopServer(record.distro, environmentId)
.catch((error: unknown) => ({ stopped: false, reason: errorMessage(error) }))
await connector.disconnect(record.distro)
// Without its holder the distro idles out.
await connector.releaseHolder(record.distro)
}
removeWslHostEnvironment(this.deps.userDataPath(), environmentId)
this.removing.delete(environmentId)
this.statuses.delete(environmentId)
await this.deps.removed(environmentId)
return serverStop

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Clear removing in a finally block.

remove adds the id to this.removing at Line 141 and deletes it only at Line 154. removeWslHostEnvironment can throw at Line 153. For example, writeWslHostDeployment throws WslHostDeploymentStoreInvalidError for an unreadable record, and writeEnvironmentStore can fail. If either throws, the id stays in removing until restart. connect and ensureForRuntimeCall then refuse the host with "This WSL host is being removed." The record is still on disk, so the host looks present but cannot be used.

🐛 Proposed fix
-    removeWslHostEnvironment(this.deps.userDataPath(), environmentId)
-    this.removing.delete(environmentId)
+    try {
+      removeWslHostEnvironment(this.deps.userDataPath(), environmentId)
+    } finally {
+      this.removing.delete(environmentId)
+    }
     this.statuses.delete(environmentId)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
this.removing.add(environmentId)
this.visible.delete(environmentId)
const connector = this.connector
let serverStop: WslHostServerStop = { stopped: true }
if (connector) {
serverStop = await connector
.stopServer(record.distro, environmentId)
.catch((error: unknown) => ({ stopped: false, reason: errorMessage(error) }))
await connector.disconnect(record.distro)
// Without its holder the distro idles out.
await connector.releaseHolder(record.distro)
}
removeWslHostEnvironment(this.deps.userDataPath(), environmentId)
this.removing.delete(environmentId)
this.statuses.delete(environmentId)
await this.deps.removed(environmentId)
return serverStop
this.removing.add(environmentId)
this.visible.delete(environmentId)
const connector = this.connector
let serverStop: WslHostServerStop = { stopped: true }
if (connector) {
serverStop = await connector
.stopServer(record.distro, environmentId)
.catch((error: unknown) => ({ stopped: false, reason: errorMessage(error) }))
await connector.disconnect(record.distro)
// Without its holder the distro idles out.
await connector.releaseHolder(record.distro)
}
try {
removeWslHostEnvironment(this.deps.userDataPath(), environmentId)
} finally {
this.removing.delete(environmentId)
}
this.statuses.delete(environmentId)
await this.deps.removed(environmentId)
return serverStop

// Why: a host that already runs, or is moving to, a managed server can't take another.
const busyTargetIds = new Set([
...managed.map((environment) => environment.orcadDeployment?.sshTargetId),
...managed.map((environment) => getOrcadSshDeployment(environment)?.sshTargetId),

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Exclude WSL hosts from the SSH managed-server list.

Line 67 now treats orcadDeployment as possibly WSL. The managed filter at Line 63 still keeps every environment whose orcadDeployment is truthy. When the internal gate is open, runtimeEnvironments:list returns WSL hosts with orcadDeployment.kind === 'wsl'. Each WSL host then renders as a ManagedServerRow with SSH managed-orcad actions. Those actions go through requireManagedOrcadEnvironment, which throws "This server is not managed through an orcad SSH deployment." Line 64 also drops WSL hosts from paired, which is correct. Filter managed with getOrcadSshDeployment so the two lists agree.

🐛 Proposed fix (outside the changed range, Line 63)
-  const managed = environments.filter((environment) => environment.orcadDeployment)
+  const managed = environments.filter((environment) => getOrcadSshDeployment(environment))

Comment on lines +90 to +102
assertPairingUsesBridge(environment, args.record.localPort)
writeWslHostDeployment(userDataPath, args.id, {
...args.record,
environmentId: args.id,
createdAt: now
})
const persisted = PersistedRuntimeEnvironmentSchema.parse(environment)
writeEnvironmentStore(userDataPath, {
version: 1,
environments: [...readPersistedEnvironmentStore(userDataPath).environments, persisted].sort(
(a, b) => a.name.localeCompare(b.name)
)
})

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.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Roll back the WSL record when the environment write fails.

addWslHostEnvironment writes the deployment record first and the environment second. Line 56 treats a leftover ownerless record as harmless. WslHostService disagrees: records(), recordForDistro and isKnownDistro read orca-wsl-host-deployments.json directly and do not check that an environment exists. So writeEnvironmentStore can fail at Line 97, for example on the byte-limit error or on the unreadable-id conflict. A crash between the two writes has the same effect. After either event, these things happen:

  • admitWslHostDistro returns already-added for that distro on every later add.
  • listDistros reports an environmentId that runtimeEnvironments:list never returns. The UI then has no environment it can remove.
  • addOnce (wsl-host-service.ts Lines 314-318) disconnects and releases the holder but leaves the record in place.

The user cannot recover through the UI. Remove the record in a catch around the environment write. Separately, make the service ignore records whose environment is missing.

🐛 Proposed fix
   const persisted = PersistedRuntimeEnvironmentSchema.parse(environment)
-  writeEnvironmentStore(userDataPath, {
-    version: 1,
-    environments: [...readPersistedEnvironmentStore(userDataPath).environments, persisted].sort(
-      (a, b) => a.name.localeCompare(b.name)
-    )
-  })
+  try {
+    writeEnvironmentStore(userDataPath, {
+      version: 1,
+      environments: [...readPersistedEnvironmentStore(userDataPath).environments, persisted].sort(
+        (a, b) => a.name.localeCompare(b.name)
+      )
+    })
+  } catch (error) {
+    try {
+      writeWslHostDeployment(userDataPath, args.id, null)
+    } catch {
+      /* keep the original error */
+    }
+    throw error
+  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
assertPairingUsesBridge(environment, args.record.localPort)
writeWslHostDeployment(userDataPath, args.id, {
...args.record,
environmentId: args.id,
createdAt: now
})
const persisted = PersistedRuntimeEnvironmentSchema.parse(environment)
writeEnvironmentStore(userDataPath, {
version: 1,
environments: [...readPersistedEnvironmentStore(userDataPath).environments, persisted].sort(
(a, b) => a.name.localeCompare(b.name)
)
})
assertPairingUsesBridge(environment, args.record.localPort)
writeWslHostDeployment(userDataPath, args.id, {
...args.record,
environmentId: args.id,
createdAt: now
})
const persisted = PersistedRuntimeEnvironmentSchema.parse(environment)
try {
writeEnvironmentStore(userDataPath, {
version: 1,
environments: [...readPersistedEnvironmentStore(userDataPath).environments, persisted].sort(
(a, b) => a.name.localeCompare(b.name)
)
})
} catch (error) {
try {
writeWslHostDeployment(userDataPath, args.id, null)
} catch {
/* keep the original error */
}
throw error
}

@nwparker
nwparker merged commit a65fdc8 into main Oct 13, 2026
59 checks passed
registered2nd pushed a commit to registered2nd/orca that referenced this pull request Oct 14, 2026
…ht back (stablyai#28402)

* fix(ssh): a cancelled sign-in stays cancelled until the user reconnects

Co-Authored-By: Claude <[email protected]>

* test(ssh): drive the credential cancel through the IPC harness

Co-Authored-By: Claude <[email protected]>

* fix(ssh): an explicit server connect lifts the cancelled sign-in of its SSH host

Co-Authored-By: Claude <[email protected]>

* fix(ssh): the cancelled attempt may still offer a password; a successful sign-in lifts the decline

Co-Authored-By: Claude <[email protected]>

* test(ssh): build the managed-server link without the newer kind field

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: m4air <[email protected]>
Co-authored-by: Claude <[email protected]>
(cherry picked from commit ed18c2c)

Release pick note: runtime-environment-connectivity-handlers.ts conflicted with main's WSL host series (stablyai#27874/stablyai#27940/stablyai#27933), which is not on this release. Kept only this PR's two lines there (the clearSshCredentialDeclinedForEnvironment import and call).
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