Repository navigation
fix(wsl-host): uninstall and startup release WSL holders; a partial Remove keeps the host pending - #33843
Conversation
491ce66 to
14b7276
Compare
14b7276 to
1a6b469
Compare
|
No actionable comments were generated in the recent review.
|
1a6b469 to
a52fdf2
Compare
There was a problem hiding this comment.
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
Files selected for processing: 43-
config/nsis/orca-installer-hooks.nshsrc/main/index.tssrc/main/ipc/runtime-environments/runtime-environment-connectivity-handlers.tssrc/main/ipc/runtime-environments/runtime-environment-host-dispatch.test.tssrc/main/ipc/runtime-environments/runtime-environment-host-service-ops.tssrc/main/ipc/wsl-host-handlers.tssrc/main/startup/wsl-holder-uninstall-preflight.test.tssrc/main/startup/wsl-holder-uninstall-preflight.tssrc/main/wsl/wsl-distro-holder.test.tssrc/main/wsl/wsl-distro-holder.tssrc/main/wsl/wsl-distro-registry-id.test.tssrc/main/wsl/wsl-distro-registry-id.tssrc/main/wsl/wsl-host-add-admission.tssrc/main/wsl/wsl-host-connection-record.tssrc/main/wsl/wsl-host-connector-types.tssrc/main/wsl/wsl-host-connector.tssrc/main/wsl/wsl-host-e2e-fake-connector.tssrc/main/wsl/wsl-host-early-wake.tssrc/main/wsl/wsl-host-pending-removal.test.tssrc/main/wsl/wsl-host-records.tssrc/main/wsl/wsl-host-removal.tssrc/main/wsl/wsl-host-server-stop.test.tssrc/main/wsl/wsl-host-server-stop.tssrc/main/wsl/wsl-host-service.test-fixture.tssrc/main/wsl/wsl-host-service.test.tssrc/main/wsl/wsl-host-service.tssrc/main/wsl/wsl-orcad-deploy.test.tssrc/main/wsl/wsl-orphan-holder-release.test.tssrc/main/wsl/wsl-orphan-holder-release.tssrc/preload/api/runtime-api.tssrc/preload/api/runtime-environments-bridge.tssrc/renderer/src/components/settings/use-runtime-environment-mutation-actions.test.tsxsrc/renderer/src/components/settings/use-runtime-environment-mutation-actions.tssrc/renderer/src/components/sidebar/wsl-host-removal.test.tssrc/renderer/src/components/sidebar/wsl-host-removal.tssrc/renderer/src/components/sidebar/wsl-host-row-status.test.tssrc/renderer/src/components/sidebar/wsl-host-row-status.tssrc/renderer/src/i18n/locales/en.jsonsrc/shared/runtime-environment-wsl-host-store.tssrc/shared/runtime-environments.tssrc/shared/wsl-host-deployment-store.tssrc/shared/wsl-host-types.tstests/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' |
There was a problem hiding this comment.
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)
| /** | ||
| * 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 | ||
| } | ||
|
|
There was a problem hiding this comment.
🔎 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 }
| 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) |
There was a problem hiding this comment.
🔎 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.
| setWslHostPendingStop(userDataPath, record.environmentId, { | ||
| since: Date.now(), | ||
| reason: serverStop.reason, | ||
| verdict: serverStop.verdict ?? 'unverifiable' | ||
| }) |
There was a problem hiding this comment.
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 changesetWslHostPendingStop(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' })
This comment has been minimized.
This comment has been minimized.
38efc6d to
5a151c3
Compare
…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]>
5a151c3 to
c7b8b2a
Compare
ELI5
To keep a WSL distro running, Orca leaves a small background
wsl.exeprocess (the "holder") alive for each WSL host. Three things could leave that distro running long after you were done with it: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
Orca.exeand the terminal daemon by image name. The detached holder survived and kept the distro up.Orca.exe --orca-uninstall-release-wsl-holders. That command ends only the holders this profile recorded inwsl-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.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-dircan't be known by the uninstaller, so holders recorded there aren't released at uninstall.nsExec::Execcall itself has no timeout here. A/TIMEOUTswitch 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.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.wsl.exe. The rule re-reads host records for each holder and keeps an Add in flight.livewhen something is proven still running,unverifiablewhen Orca couldn't tell.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".runtimeEnvironments:remove. It shows the pending warning instead of "Removed".~/.orca,~/.orca-wsland~/.orca-remotein 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
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_HOSTSgate. 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
wsl-distro-holder.test.ts:releaseAllkills 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:unverifiable.wsl-host-server-stop.test.ts:liveandunverifiableverdicts.pnpm tc,check:code-quality:changedand the touched suites pass. The earlier revision passed fullpnpm lintafter 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
Notes
pendingStopfield 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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)