Skip to content

fix(wsl-host): uninstall and startup release WSL holders; a partial Remove keeps the host pending - #33843

Merged
nwparker merged 6 commits into
mainfrom
nwparker/wsl-host-e11-holder-cleanup
Oct 27, 2026
Merged

nwparker merged 6 commits into
mainfrom
nwparker/wsl-host-e11-holder-cleanup

Conversation

@nwparker

@nwparker nwparker commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​683 $\color{#cf222e}{\Huge{\mathbf{−}}}$​26 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​657
Prod 31 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​667 $\color{#cf222e}{\Huge{\mathbf{−}}}$​157 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​510

ELI5

To keep a WSL distro running, Orca leaves a small background wsl.exe process (the "holder") alive for each WSL host. Three things could leave that distro running long after you were done with it:

  • Uninstalling Orca never stopped the holder, so the distro, Orca's server and your shells kept running.
  • A holder left behind by a failed add or remove was kept forever.
  • If Remove couldn't stop Orca's server, Orca deleted the host anyway. The leftover server then blocked adding that distro again.

Now uninstall stops Orca's holders, startup releases the ones nothing needs, and a Remove that can't finish keeps the host listed so you can retry.

What Changed

  • Uninstall:
    • Before: Orca's uninstaller killed Orca.exe and the terminal daemon by image name. The detached holder survived and kept the distro up.
    • After: on a real uninstall (not an update), once the app and daemon are killed, the uninstaller runs Orca.exe --orca-uninstall-release-wsl-holders. That command ends only the holders this profile recorded in wsl-distro-holders/*. Each one must match on pid, process start time and command line. A holder Orca can't verify is left running and never guessed at. With no client left, the distro idle-stops on WSL's own timer, which also ends orcad and the shells.
    • The uninstaller launches the command only if a holder folder exists (wsl-distro-holders\*.json) under one of the folders Electron's userData can be: $APPDATA\${APP_FILENAME}, ${APP_PRODUCT_FILENAME} or ${APP_PACKAGE_NAME}, the same list the uninstaller's own delete-app-data step uses. Users who never ran a WSL host see no change at all. A custom --user-data-dir can't be known by the uninstaller, so holders recorded there aren't released at uninstall.
    • The command arms its 30 s exit timer before anything else, and exits 1 instead of showing an error box if its setup throws. It runs before any other startup step: no window, no single-instance lock, no IPC.
    • The command exits within 30 s, through its own timer. NSIS's nsExec::Exec call itself has no timeout here. A /TIMEOUT switch would change how NSIS reads the command, and the uninstaller can't be tested on this machine, so the app-side timer is the bound.
  • Orphaned holders at startup:
    • Before: startup kept every recorded holder, and only when some WSL host existed.
    • After: WslHostService.start() keeps the holders of registered hosts. It releases holders whose distro is no longer a host or whose Remove is pending, and every holder while WSL hosts are turned off. A build with the WSL-hosts gate closed releases them too. Releasing uses the same verified kill.
    • A build with the WSL-hosts gate closed applies the same rule: it releases only orphan and pending-removal holders, and keeps every host's. A user with no holder records costs one folder-exists check; there's no process table read and no wsl.exe. The rule re-reads host records for each holder and keeps an Add in flight.
    • Hosts turned off in Settings release every holder at launch. That matches turning the setting off at runtime, which releases holders without stopping servers, so the distro idles out.
    • If the host records can't all be read (file unreadable, or a record this build can't parse), startup keeps every holder, because it can't prove any of them orphaned.
    • A holder record with no process start time is never killed on its command line alone, since a reused pid could run the same command line. The one exception is a holder this process just spawned itself.
  • Partial Remove:
    • Before: if Remove couldn't prove the server stopped (terminals that refused to close, a daemon still running, a census that didn't answer), the host was removed anyway. Adding the distro again then hit the update deferral: the new server could not take over while the old daemon still had live terminals.
    • After: Remove drops the host only after a proven stop, meaning zero live sessions and a retired server and daemon. Otherwise the host stays listed with a pending stop recorded on its WSL record:
      • The row says "Removal didn't finish" with the reason. The toast says the host wasn't removed yet and how to retry.
      • The result carries a verdict: live when something is proven still running, unverifiable when Orca couldn't tell.
      • While a stop is pending, open projects, the liveness watch and passive calls never reconnect the host. Its holder is released.
      • Remove again retries the stop, and never boots the distro. A stopped distro proves the stop, since nothing of the host can run in it, so Remove finishes.
      • Only the user's own Connect, or Add on the same distro, withdraws the pending removal and connects. That is how re-adding after a partial failure succeeds. Any other caller's connect is refused, and Add follows the same "the distro is stopped, start it?" rule as any add.
      • If the distro is no longer registered, Remove finishes, because nothing of the host can still run. The distro is found by its recorded GUID first, then by name (resolveWslDistroName). A renamed distro is stopped under its current name, so it never reads as "stopped" under the old one. A registry that can't be read doesn't count as "gone".
      • Switching to a pending host's workspace doesn't reconnect it.
      • Removing from Settings → Remote Orca Servers carries the same result through runtimeEnvironments:remove. It shows the pending warning instead of "Removed".
  • Not changed: Remove still leaves ~/.orca, ~/.orca-wsl and ~/.orca-remote in the distro, per the 2026-10-24 decision. The opt-in "also delete server files" purge is not built; it needs owner sign-off.

Why

  • Uninstall: the uninstaller can't safely read command lines itself without PowerShell, which is an EDR signal. Running the signed app in a one-shot mode reuses Orca's own holder verification and its native process-table reader. Killing only recorded and verified holders means another Orca install's holder, or a reused pid, is never touched.
  • Partial Remove: ending terminals and counting sessions both go through the host's saved pairing. So a stop can only be retried while the host's records exist. Keeping the host listed makes retrying possible. The other option was to drop the host and force past the deferral on re-add, but that would end the leftover terminals without the user asking.

Linked Issue

Internal: WSL via orcad, gate E11 (uninstall and orphan holder cleanup).

Visual Proof

N/A for screenshots. WSL hosts are behind the internal ORCA_INTERNAL_WSL_HOSTS gate. The only UI change is text: a row label ("Removal didn't finish") and a toast, both covered by unit tests. The uninstall and idle-stop acceptance needs a Windows box (see Testing).

Testing

  • I manually tested these changes locally. Not done: this needs a Windows install and uninstall plus a partial Remove on a real distro. Acceptance for the next verify pass:
    • after uninstall, no Orca process is left in the distro and it idle-stops;
    • re-add after a partial Remove succeeds.
  • Automated tests added/updated:
    • wsl-distro-holder.test.ts: releaseAll kills only verified holders. A reused pid running something else is never killed. A holder it can't verify, because the process table failed, is kept along with its record.
    • wsl-holder-uninstall-preflight.test.ts: exit code 0 only when every holder is proven gone. The uninstaller runs the command only on a real uninstall, after the app and daemon are killed.
    • wsl-host-service.test.ts:
      • Startup keeps host holders and releases orphans, and releases all when hosts are off.
      • A partial Remove keeps the host pending, and nothing reconnects it.
      • Remove again finishes it on a proven stop, and stays pending on unverifiable.
      • A stopped distro is never booted.
      • An unregistered distro finishes.
      • Add or Connect withdraws the removal.
      • The pending state shows from launch.
    • wsl-host-server-stop.test.ts: live and unverifiable verdicts.
    • Renderer: the row label and the pending toast.
  • Review fixes: each fix has a test that fails on the code before it, and I ran them that way.
  • Rebased onto main, merged with main's pairing-key binding on WSL records.
  • pnpm tc, check:code-quality:changed and the touched suites pass. The earlier revision passed full pnpm lint after the two new English strings were added to the catalog. CI runs full lint and tests on this revision.

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

  • Windows-only paths, behind the internal WSL-hosts gate. No SSH code is changed, and nothing goes over the wire.
  • Older builds read the new pendingStop field as absent. If an older build rewrites that host's record, the field is dropped, and the host then just looks like a normal host again.

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)

@nwparker
nwparker force-pushed the nwparker/wsl-host-e11-holder-cleanup branch 2 times, most recently from 491ce66 to 14b7276 Compare October 26, 2026 21:08
@nwparker
nwparker marked this pull request as ready for review October 26, 2026 21:12
@nwparker
nwparker force-pushed the nwparker/wsl-host-e11-holder-cleanup branch from 14b7276 to 1a6b469 Compare October 26, 2026 21:15
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent 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: 75c18e8a-9069-4fc6-b3c8-08343ba35610
Commits

Reviewing files that changed from the base of the PR and between 5a151c3 and c7b8b2a.

Files selected for processing: 1
  • src/renderer/src/i18n/locales/en.json
Files skipped from review as they are similar to previous changes: 1
  • src/renderer/src/i18n/locales/en.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Walkthrough

The changes add verified WSL holder release during uninstall and startup cleanup. WSL host removal now records unresolved stops, retains the host entry, and blocks automatic reconnection and waking while removal is pending. Removal responses include server-stop details. The interface displays pending-removal status and warnings.

Priority: Normal

Merge Risk: Moderate · up to c7b8b

Removal can remain pending for a running renamed distro, an overlong stop reason can prevent the pending state from being saved, and a hung preflight can stall uninstall. Resolve or explicitly accept these risks before merging.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly summarizes the main changes: WSL holder cleanup during uninstall and startup, plus pending state for incomplete host removal.
Description check Passed The description is detailed and covers the user impact, implementation, rationale, testing, limitations, compatibility, and checklist. The Linked Issue section does not include an actual issue referen…
Docstring Coverage Passed Docstring coverage is inconclusive: files from earlier reviews still need to be rechecked within the check's analysis limits. Not blocking.
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: Description check

Explanation

The description is detailed and covers the user impact, implementation, rationale, testing, limitations, compatibility, and checklist. The Linked Issue section does not include an actual issue reference, and several final checklist items remain unchecked, but the description is otherwise mostly complete.

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

@nwparker
nwparker force-pushed the nwparker/wsl-host-e11-holder-cleanup branch from 1a6b469 to a52fdf2 Compare October 26, 2026 22:37

@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: 4


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: 4c74c5df-632f-4271-837a-d6df4d932875
Commits

Reviewing files that changed from the base of the PR and between 8291297 and 23b3fba.

Files selected for processing: 43
  • config/nsis/orca-installer-hooks.nsh
  • src/main/index.ts
  • src/main/ipc/runtime-environments/runtime-environment-connectivity-handlers.ts
  • src/main/ipc/runtime-environments/runtime-environment-host-dispatch.test.ts
  • src/main/ipc/runtime-environments/runtime-environment-host-service-ops.ts
  • src/main/ipc/wsl-host-handlers.ts
  • src/main/startup/wsl-holder-uninstall-preflight.test.ts
  • src/main/startup/wsl-holder-uninstall-preflight.ts
  • src/main/wsl/wsl-distro-holder.test.ts
  • src/main/wsl/wsl-distro-holder.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-types.ts
  • src/main/wsl/wsl-host-connector.ts
  • src/main/wsl/wsl-host-e2e-fake-connector.ts
  • src/main/wsl/wsl-host-early-wake.ts
  • src/main/wsl/wsl-host-pending-removal.test.ts
  • src/main/wsl/wsl-host-records.ts
  • src/main/wsl/wsl-host-removal.ts
  • src/main/wsl/wsl-host-server-stop.test.ts
  • src/main/wsl/wsl-host-server-stop.ts
  • src/main/wsl/wsl-host-service.test-fixture.ts
  • src/main/wsl/wsl-host-service.test.ts
  • src/main/wsl/wsl-host-service.ts
  • src/main/wsl/wsl-orcad-deploy.test.ts
  • src/main/wsl/wsl-orphan-holder-release.test.ts
  • src/main/wsl/wsl-orphan-holder-release.ts
  • src/preload/api/runtime-api.ts
  • src/preload/api/runtime-environments-bridge.ts
  • src/renderer/src/components/settings/use-runtime-environment-mutation-actions.test.tsx
  • src/renderer/src/components/settings/use-runtime-environment-mutation-actions.ts
  • src/renderer/src/components/sidebar/wsl-host-removal.test.ts
  • src/renderer/src/components/sidebar/wsl-host-removal.ts
  • src/renderer/src/components/sidebar/wsl-host-row-status.test.ts
  • src/renderer/src/components/sidebar/wsl-host-row-status.ts
  • src/renderer/src/i18n/locales/en.json
  • src/shared/runtime-environment-wsl-host-store.ts
  • src/shared/runtime-environments.ts
  • src/shared/wsl-host-deployment-store.ts
  • src/shared/wsl-host-types.ts
  • tests/e2e/wsl-host-fake-transport.spec.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.

SetShellVarContext all
${endIf}
${if} $1 == "1"
nsExec::Exec '"$INSTDIR\${APP_EXECUTABLE_FILENAME}" --orca-uninstall-release-wsl-holders'

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.

Major · Stability & Availability · Heavy lift

Bound the uninstall wait outside Electron.

If the launched app hangs before the JavaScript timeout runs, nsExec::Exec can wait indefinitely and block uninstall. Add an installer-controlled deadline for this process. nsExec has no timeout by default, and its /TIMEOUT option does not provide a hard deadline when the process keeps writing output. (github.com)

Comment on lines +87 to +107
/**
* The distro's current registered name: by its recorded GUID first (it survives a rename), else
* by name. False when neither is registered; null when the registrations can't be read.
*/
export async function resolveWslDistroName(
distro: string,
distroGuid?: string,
query: RegQuery = defaultRegQuery
): Promise<string | false | null> {
const registrations = await readWslDistroRegistrations(query)
if (!registrations) {
return null
}
const guid = distroGuid?.trim().replace(/[{}]/g, '').toLowerCase()
const wanted = distro.trim().toLowerCase()
const match =
(guid && registrations.find((entry) => entry.id === guid)) ||
registrations.find((entry) => entry.distro.toLowerCase() === wanted)
return match ? match.distro : false
}

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.

Major · Functional Correctness · Quick win

🔎 Supported by static analysis

Script executed:

rg -n -C 4 'distroId:|distroId =|getWslDistroId|resolveWslDistroName|readWslDistroRegistrations|registered.*Guid' src/main/wsl src/shared/runtime-environment-wsl-host-store.ts
sed -n '1,115p' src/main/wsl/wsl-distro-registry-id.ts
sed -n '150,185p' src/main/wsl/wsl-host-connector.ts

Repository: stablyai/orca

Length of output: 20986


Script executed:

set -e
printf '%s\n' '--- removal implementation ---'
sed -n '1,180p' src/main/wsl/wsl-host-removal.ts
printf '%s\n' '--- host service types and removal callers ---'
rg -n -C 5 -F -- 'stopServer' src/main/wsl src/shared
rg -n -C 6 -F -- 'removeWslHost' src/main/wsl src/shared
printf '%s\n' '--- persisted WSL record type/store ---'
rg -n -C 8 -F -- 'distroId' src/shared/runtime-environment-wsl-host-store.ts src/main/wsl/wsl-host-registration.ts src/main/wsl/wsl-host-service.ts
printf '%s\n' '--- relevant removal tests ---'
rg -n -C 8 -e 'resolveDistroName|distroId|stopServer|renamed|reused|Remove' src/main/wsl/wsl-host-service.test.ts src/main/wsl/wsl-host-server-stop.test.ts src/main/wsl/wsl-host-connector.test.ts 2>/dev/null || true

Repository: stablyai/orca

Length of output: 41737


Do not fall back to the name after a recorded GUID lookup fails.

record.distroId identifies the original WSL registration. Unregistering and reimporting a distro changes that GUID. If the old name is reused, the current fallback resolves the replacement by name, and Remove passes that name to stopServer, which can stop the replacement distro.

Use name lookup only when no GUID was recorded. Return false when a recorded GUID is no longer registered.

Suggested fix
-  const match =
-    (guid && registrations.find((entry) => entry.id === guid)) ||
-    registrations.find((entry) => entry.distro.toLowerCase() === wanted)
+  const match = guid
+    ? registrations.find((entry) => entry.id === guid)
+    : registrations.find((entry) => entry.distro.toLowerCase() === wanted)
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
/**
* The distro's current registered name: by its recorded GUID first (it survives a rename), else
* by name. False when neither is registered; null when the registrations can't be read.
*/
export async function resolveWslDistroName(
distro: string,
distroGuid?: string,
query: RegQuery = defaultRegQuery
): Promise<string | false | null> {
const registrations = await readWslDistroRegistrations(query)
if (!registrations) {
return null
}
const guid = distroGuid?.trim().replace(/[{}]/g, '').toLowerCase()
const wanted = distro.trim().toLowerCase()
const match =
(guid && registrations.find((entry) => entry.id === guid)) ||
registrations.find((entry) => entry.distro.toLowerCase() === wanted)
return match ? match.distro : false
}
/**
* The distro's current registered name: by its recorded GUID first (it survives a rename), else
* by name. False when neither is registered; null when the registrations can't be read.
*/
export async function resolveWslDistroName(
distro: string,
distroGuid?: string,
query: RegQuery = defaultRegQuery
): Promise<string | false | null> {
const registrations = await readWslDistroRegistrations(query)
if (!registrations) {
return null
}
const guid = distroGuid?.trim().replace(/[{}]/g, '').toLowerCase()
const wanted = distro.trim().toLowerCase()
const match = guid
? registrations.find((entry) => entry.id === guid)
: registrations.find((entry) => entry.distro.toLowerCase() === wanted)
return match ? match.distro : false
}

Comment on lines +27 to +34
const current = await connector
.resolveDistroName(record.distro, record.distroId)
.catch(() => null)
if (current !== false) {
// Under its current name: a renamed distro never reads as running under the old one.
// Never boots: a stopped distro is itself a proven stop.
serverStop = await connector
.stopServer(current ?? record.distro, record.environmentId)

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
rg -nP -C4 'isKnownDistro' src/main/wsl/wsl-host-connector.ts src/main/wsl/wsl-host-service.ts
rg -nP -C6 'connect\s*\(' src/main/wsl/wsl-orcad-liveness.ts

Repository: stablyai/orca

Length of output: 3872


Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- candidate files ---'
rg --files src/main/wsl | sort
printf '%s\n' '--- stopServer and liveness references ---'
rg -n -F --glob '*.ts' -e 'stopServer' -e 'createWslOrcadLiveness' -e 'coldReachability' -e 'liveness.connect' src/main/wsl || test "$?" -eq 1
printf '%s\n' '--- removal implementation ---'
sed -n '1,120p' src/main/wsl/wsl-host-removal.ts
printf '%s\n' '--- connector implementation ---'
sed -n '1,180p' src/main/wsl/wsl-host-connector.ts

Repository: stablyai/orca

Length of output: 20373


Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- connector stopServer remainder ---'
sed -n '155,215p' src/main/wsl/wsl-host-connector.ts
printf '%s\n' '--- liveness wiring ---'
sed -n '1,180p' src/main/wsl/wsl-orcad-liveness-wiring.ts
printf '%s\n' '--- liveness supervisor ---'
sed -n '1,260p' src/main/wsl/wsl-orcad-liveness-supervisor.ts
printf '%s\n' '--- service record lookup and known-distro logic ---'
rg -n -C8 -F -- 'recordForDistro' src/main/wsl/wsl-host-service.ts
printf '%s\n' '--- related renamed-distro tests ---'
rg -n -C8 -F -e 'resolveDistroName' -e 'renamed' -e 'distroId' src/main/wsl/wsl-host-connector.test.ts src/main/wsl/wsl-host-server-stop.test.ts src/main/wsl/wsl-host-pending-removal.test.ts src/main/wsl/wsl-host-service.test.ts

Repository: stablyai/orca

Length of output: 23669


Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- connection manager ensure ---'
rg -n -C12 -F -e 'async ensure' -e 'ensure(' src/main/wsl/wsl-orcad-connection.ts
printf '%s\n' '--- distro comparison definition ---'
rg -n -C10 -F -e 'function sameWslDistro' -e 'const sameWslDistro' -e 'sameWslDistro' src/main/wsl

Repository: stablyai/orca

Length of output: 12866


Script executed:

#!/bin/bash
set -u
sed -n '90,230p' src/main/wsl/wsl-orcad-connection.ts

Repository: stablyai/orca

Length of output: 5971


Use the recorded distro name for admission guards during removal.

A renamed, running distro reaches stopServer under its current name. isKnownDistro only recognizes the recorded name, so recovery calls deployAndLaunch with an unknown distro and rejects. Removal catches that rejection as unverifiable, leaving the host pending.

Use the recorded name for known-distro guards during removal, while using the current name for WSL operations.

Comment on lines +49 to +53
setWslHostPendingStop(userDataPath, record.environmentId, {
since: Date.now(),
reason: serverStop.reason,
verdict: serverStop.verdict ?? 'unverifiable'
})

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 · Data Integrity & Integration · Quick win

Truncate serverStop.reason before persisting it as pendingStop.

WslHostPendingStopSchema limits reason to 4,096 characters. writeWslHostDeployment calls WslHostDeploymentRecordSchema.parse, which throws a ZodError for a longer string.

serverStop.reason has no length bound. stopWslHostServer joins one line per refused terminal through describeLeftovers. About 50 refused terminals can pass 4,096 characters.

When the write throws, removeWslHostServer rejects after it has already called disconnect and releaseHolder. The record then stays without pendingStop. The user sees a schema error instead of the pending-removal state. Each retry hits the same error.

Cap the persisted reason:

Proposed fix
--- "a/src/main/wsl/wsl-host-removal.ts"
+++ "b/src/main/wsl/wsl-host-removal.ts"
@@ -46,11 +46,11 @@
     removeWslHostEnvironment(userDataPath, record.environmentId)
     return { serverStop, removed: true }
   }
   setWslHostPendingStop(userDataPath, record.environmentId, {
     since: Date.now(),
-    reason: serverStop.reason,
+    reason: serverStop.reason.slice(0, 4_096),
     verdict: serverStop.verdict ?? 'unverifiable'
   })
   return { serverStop: { ...serverStop, kept: true }, removed: false }
 }
 
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
setWslHostPendingStop(userDataPath, record.environmentId, {
since: Date.now(),
reason: serverStop.reason,
verdict: serverStop.verdict ?? 'unverifiable'
})
setWslHostPendingStop(userDataPath, record.environmentId, {
since: Date.now(),
reason: serverStop.reason.slice(0, 4_096),
verdict: serverStop.verdict ?? 'unverifiable'
})

@blacksmith-sh

This comment has been minimized.

@nwparker
nwparker force-pushed the nwparker/wsl-host-e11-holder-cleanup branch 2 times, most recently from 38efc6d to 5a151c3 Compare October 27, 2026 01:56
nwparker and others added 6 commits October 26, 2026 20:01
…rca left running

The detached wsl.exe holder outlives the app, so an uninstall left its distro,
orcad and shells running. The uninstaller now runs Orca with
--orca-uninstall-release-wsl-holders after killing the app and its daemon; it
ends only the holders this profile recorded, each verified by pid, start time
and command line, and keeps any it cannot verify.

At startup the WSL host service now releases holders whose distro is no longer
a host (a failed add or remove), and every holder while WSL hosts are off; a
closed gate releases them too.

Co-Authored-By: Claude <[email protected]>
… host, pending

A partial Remove dropped the host anyway, leaving a server whose live
terminals block the next add's activation. Remove now drops the host only on a
proven stop; otherwise it records a pending stop on the WSL record, keeps the
host listed and says why (live or unverifiable). Remove again retries without
ever booting a stopped distro (it says to start it); Connect or Add on the same
distro keeps the host; a distro that is no longer registered finishes. Nothing
reconnects a pending host on its own.

Co-Authored-By: Claude <[email protected]>
… finish removals a stopped or renamed distro proves

- Startup keeps every holder when the WSL host records can't all be read
  (unverifiable), and no longer re-adopts a pending host's holder.
- Remove matches a renamed distro by GUID (isWslDistroRegistered), and a
  stopped distro finishes a pending Remove: the cold probe proves the stop.
- Only the user's Connect or Add withdraws a pending Remove; other connects
  are refused, and re-adding respects startIfStopped.
- Settings' Remove carries the kept result, so it warns instead of 'Removed'.
- A holder record without a start time is never killed on its command line
  alone, except the one this process just spawned.

Co-Authored-By: Claude <[email protected]>
…; stop a renamed distro by its current name

- With the gate closed, a launch releases only orphan holders (no host record,
  or a pending Remove), under the same keep rule as startup; a user with no
  holder records costs one folder check, nothing else.
- The keep rule re-reads host records per holder and keeps an Add in flight.
- Remove resolves the distro's current name from its GUID and stops it there.
- The uninstall command arms its exit timer first and exits 1 if setup throws;
  NSIS launches it only when a userData holder folder exists.

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

Early wake built its host list from every record, so a host focused when its
Remove ended pending was booted at each launch, undoing the stop's proof. It
now skips pending records, and Remove forgets the host's early wake whatever
the outcome.

Co-Authored-By: Claude <[email protected]>
…idged server like the real one

- mayWake skips a host whose Remove is pending, so a due automation can't
  boot it (focus already couldn't).
- The e2e fake connector read a host with no bridge as stopped. Since E9 a
  re-enable connects nothing, so Remove after off/on left the host's shells
  running. Like the real connector, it now reconnects the always-running fake
  distro to stop its server.
- Status bookkeeping moves to WslHostStatusBoard, and the pending-host connect
  rule to admitConnectToPendingHost, to keep the service under max-lines.

Co-Authored-By: Claude <[email protected]>
@nwparker
nwparker force-pushed the nwparker/wsl-host-e11-holder-cleanup branch from 5a151c3 to c7b8b2a Compare October 27, 2026 03:01
@nwparker
nwparker merged commit 284411d into main Oct 27, 2026
52 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