Skip to content

fix(wsl-hosts): pin the host's Linux user, refuse a second account's server, and let Remove always drop an unreachable host - #49360

Merged
nwparker merged 10 commits into
mainfrom
nwparker/wsl-default-user-change
Nov 28, 2026
Merged

nwparker merged 10 commits into
mainfrom
nwparker/wsl-default-user-change

Conversation

@nwparker

@nwparker nwparker commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Problem

WSL hosts ran every wsl.exe call as the distro's default Linux user. A managed orcad keeps its install, data and E2EE host key (~/.orca/orca-e2ee-keypair.json) under that user's home.

So when the default user changed (root to qauser in the real-WSL repro), the next connect:

  1. deployed and started a new orcad for qauser, on 127.0.0.1:6800 (managed orcads listen on 6800 or the next free port);
  2. then refused that orcad as foreign-port, because its key isn't the pinned one. The refusal comes from verifyWslOrcadPairing → resolveWslOrcadPairing;
  3. left the card on "Reconnecting" indefinitely, because liveness retried the refusal forever.

The host also couldn't be removed:

  • Remove: took about 26 s, then failed and kept the host.
  • orca environment rm: printed SSH-only advice.
  • orca environment stop and orca environment forget: said "not managed through an orcad SSH deployment".

Fix

1. Pin the Linux account (wsl -u). The deploy's single facts probe reports the account it runs as, and the host record stores it as linuxUser at Add. The pin is applied to:

  • the host transport: deploy, readiness, stdio bridge, liveness, stop, pairing repair;
  • the distro holder (see 5).

Pins come from each read of the host records. Two operations override them for their own duration, through withWslHostLinuxUser, and a records re-read can't clear that override:

  • a removal under a distro's new name;
  • the migration's trial connect.

A pin never moves.

Why pinning instead of re-pairing or redeploying for the new user:

  • The pairing stays tied to one server. Re-pairing to whatever server answers would undo "a different host key is never trusted automatically".
  • Nothing is stopped behind the user's back. Redeploying would stop the old account's server and terminals.
  • Project paths keep working. Switching accounts would leave saved project paths unreadable.

2. Never deploy for the wrong account (the repro). For an unpinned host, the facts probe also reads the default account's public key from ~/.orca/orca-e2ee-keypair.json. If that key isn't the saved pairing's key, the connect is refused before anything is deployed, with the final error WslHostAccountChangedError. Its message is neutral, since a reset identity looks the same. Because the error is final, liveness publishes it as failed, so the card shows the error instead of "Reconnecting".

Liveness treats only sealed proofs as final:

  • WslHostAccountChangedError and unsupported distros;
  • unpaired (pairing rejected);
  • a key-rejection close (4001/4003), or a repair that read a different, readable key from the slot (both now marked sealed; an unparseable published offer is not);
  • replaced-server.

A catch-all foreign answer (a status.get error, or a port briefly answered by something else during a restart) keeps the old backoff and is not given "remove and add again" wording.

3. Migration for hosts saved before pinning.

  • On the user's Connect, one wsl -u root probe reads every account's ~/.orca/orca-e2ee-keypair.json.
    • It reads only regular files that aren't symlinks (and not through a symlinked ~/.orca), and only the first 4 KiB.
    • It prints the public half only.
    • It runs under a guest-side timeout 10 when available, plus a 15 s desktop abort, so an abandoned probe can't leave a root scan running.
  • If exactly one account holds the saved pairing's key, Orca connects as that account under a token-scoped override. It runs one trial per host: a second Connect joins it. The trial is bounded at 10 minutes.
  • The pin is saved, and written to the in-memory pins, only after that connect verified the server, so the holder and liveness stay on that account right away.
  • A failed or timed-out trial saves nothing and leaves no override.
  • If no account matches, or root is unavailable, the error is final: remove the WSL host and add it again.
  • Remove on an unpinned, changed host runs the same search and stops the server as the matched account.

When a pinned account differs from the distro's current default user, Settings shows "Runs as . To use , remove the host and add it again." Reading the current default user costs one unpinned id -un, only for pinned hosts, in parallel with the context probes.

4. No port refusal (simplified). A managed orcad listens on 6800, or moves up the fallback ladder when that port is taken. Every connect dials the port its own account's server published. So two accounts' servers coexist on different ports, and a connect never meets the other account's server. The earlier port-based refusal never fired, and it guarded no real conflict, so it is gone.

The real conflict in the repro was Orca starting the new account's server, which 2 now prevents. If another account's managed orcad does run in the distro, the probe logs it once per distro so it isn't silent.

5. Holder account.

  • The holder is spawned with -u <pinned user>, so it watches that account's ~/.orca release file.
  • A recorded holder whose command line runs as another account, such as a default-user holder from before migration, is stopped and replaced. This happens only once a records read has succeeded, so an unreadable host store never gets pinned holders replaced. Every holder ensure and recovery path reads the records first.
  • spawnDetachedHolder moved to wsl-distro-holder-command.ts, with its row in the blocking-helper baseline.

6. Remove and the CLI.

  • Remove: a first Remove that can't prove the stop keeps the host pending, as before (E11). Removing it again drops it only when the stop verdict is unverifiable. A live verdict and a removalUnrecorded record stay listed.
  • Renamed distro: removal stops the server as the record's account even after a records re-read.
  • orca environment forget: drops a WSL host without contacting its distro.
  • orca environment rm: on a WSL host, explains how to remove a WSL host.
  • orca environment stop, update, rollback, recover and cancel-stop: refused with a WSL message that points to Remove or forget.

Other desktop-side wsl.exe and \\wsl.localhost paths

  • Hook relay: only for desktop-spawned local WSL terminals, not on the WSL host path.
  • $HOME probe and \\wsl.localhost: both run as the default user. On the host path, the Claude/Codex account services use them to prepare a WSL target's account home, which is then handed to orcad. Left unpinned because \\wsl.localhost writes always run as the default user.
    • Root pinned with a non-root default: root can read the default home, so this keeps working.
    • Non-root pinned with root as default: per-account Claude/Codex sign-in for that host breaks. Remove the host and add it again.
  • Other discovery, filesystem and execution wsl.exe callers: serve local WSL projects, not the host transport.

Tests

Each test fails if its fix is reverted:

  • wsl-orcad-account-facts.test.ts, which runs the real probe in sh/dash:
    • the facts output still parses
    • the probe's own shell is never reported as another account's server
    • another account's managed orcad is named
    • the repro: an unpinned host whose default account lacks the paired key is refused before deploy
  • wsl-host-other-account-refusal.test.ts:
    • the account-changed error is final, and liveness stops with failed after one attempt
    • an unsealed foreign answer keeps backing off, while a sealed one stops
    • the root probe is valid sh
    • the account search pins only a single holder of the key
    • pin only after verify: a failing trial saves nothing; a verified one saves the pin and keeps it in memory
    • single-flight and bounded: concurrent trials join, and a hung trial is aborted at the cap (through the connect's signal, which ends its deploy and wsl.exe calls) and drops its override
  • wsl-distro-holder-user.test.ts:
    • the holder argv carries -u
    • a holder is kept while pins are unloaded, and replaced once it runs as another account than the pin
  • wsl-orcad-public-key-read.test.ts: the Add-time SSH conflict read, the facts probe's key line and the root probe all run in sh against a pretty-printed and a single-line key file holding a fake secret. Each prints only the publicKeyB64 value.
  • wsl-host-removal.test.ts:
    • unreachable host: pending, then removed
    • live stays listed
    • forget never calls stop
    • a renamed distro is stopped as the record's account despite a records re-read
  • wsl-orcad-host-user.test.ts and runtime-environment-wsl-host-user-pin.test.ts: transport -u, and the pin is set once and never moves.

pnpm check:changed passes. Blocking-helper baseline:

  • rows added for the two new files that create a wsl.exe transport, with notes;
  • the holder spawn's row moved with it;
  • the rest pruned by the ratchet tool.

Real-WSL validation is still pending for this revision, on win-lowspec.

Performance

  • Every connect: no new process. The account, key and other-server checks run inside the facts probe that every connect already makes; they add one id, one sed, one ps and one awk there.
  • Pinned hosts whose default differs: one extra short wsl.exe (id -un) per connect, run in parallel.
  • Unpinned hosts after a mismatch: one wsl -u root probe, on the user's Connect only.
  • Holder adoption: compares the command line it already reads.

Fixes #49180
Fixes STA-18401

Files Added Deleted Net
Test 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​603 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​603
Prod 43 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​798 $\color{#cf222e}{\Huge{\mathbf{−}}}$​111 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​687

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review
Walkthrough

The changes add Linux-account detection and pinning for WSL hosts, including connection retry handling when the paired account differs from the default account. WSL host removal can now proceed without stopping the server, and eligible pending removals can be completed when Orca cannot confirm a stop. The CLI, pairing guards, status messages, and removal warnings now distinguish WSL hosts and these outcomes.

Severity of issue fixed: Medium

Merge Risk: Moderate · previous review 773bc

This change lets WSL hosts survive a changed default Linux user and makes unreachable hosts removable. Several edge cases remain open: a timed-out account migration may keep running under the wrong account, a stale pairing token may be saved, and a spoofed or transient handshake close may permanently fail a host. Resolve or accept these before merging, and run real-WSL validation.

Pre-merge checks: Passed 3 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Description check Warning The description is detailed and follows most of the template. It has a Problem, Fix, Tests, and Performance section, and it links issues #49180 and STA-18401. It is missing several required template p… Add an ELI5 section in plain language. Add a Visual Proof section with before and after screenshots or videos of the WSL host status and Remove messages, or write N/A with a reason. State which platforms were manually tested, and tick the T…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title names three real changes in the changeset: pinning the WSL host's Linux user, refusing a second account's server, and letting Remove drop an unreachable host. It is long and dense, but it is…
Linked Issues check Passed Only #49180 is an active direct target. Its coding requirements, and the changes that address them, are:

(1) Changed default Linux user must not break connect. The facts probe reports the running acc…
Out of Scope Changes check Passed Each changed area connects to #49180 or to the stated PR objectives:

(a) Account pinning and migration: wsl-orcad-host-user.ts, wsl-orcad-host-transport.ts, wsl-distro-holder*.ts, wsl-host-deployment…
Full details: Title check

Explanation

The title names three real changes in the changeset: pinning the WSL host's Linux user, refusing a second account's server, and letting Remove drop an unreachable host. It is long and dense, but it is related to the main change and is not misleading. Its scope is broader than one headline change, which is acceptable.

Full details: Linked Issues check

Explanation

Only #49180 is an active direct target. Its coding requirements, and the changes that address them, are:

(1) Changed default Linux user must not break connect. The facts probe reports the running account and its public key (wsl-orcad-account-facts.ts). Host records store linuxUser (wsl-host-registration.ts, wsl-host-deployment-store.ts). The host transport applies the pin with wsl -u (wsl-orcad-host-user.ts, wsl-orcad-host-transport.ts). For unpinned hosts, a default account without the paired key is refused before deploy with WslHostAccountChangedError (wsl-orcad-held-context.ts, wsl-orcad-account-facts.ts). Liveness treats that error as final, so the card shows failed instead of Reconnecting (wsl-orcad-liveness-recovery.ts). This addresses the reported loop and the new-server deployment.

(2) Supported repair or reset of a stale pairing, without manual file edits. Automatic re-pairing is refused by design. Remove followed by Add is the supported reset. The Connect migration (wsl-host-account-migration.ts, wsl-host-user-connect.ts) repairs older unpinned records through Orca.

(3) Removal of an inaccessible host without a successful connection. forgetWslHostEnvironment (wsl-host-forget.ts) drops a WSL host without contacting the distro. wsl-host-removal.ts keeps a first Remove pending when the stop cannot be proven, and a repeated Remove drops the host only when the verdict is unverifiable. This two-step Remove is a design choice; forget is the one-step path. wsl-host-removal.test.ts covers these cases.

(4) CLI distinguishes WSL from SSH. managed-orcad-actions.ts tries the WSL forget path first. managed-server.ts selects WSL wording when no sshTargetId is present. orcad-managed-runtime-context.ts rejects WSL deployments for stop and other lifecycle actions with WSL guidance.

The named tests cover these behaviors. Evidence comes from the whole-PR summary, the PR description and the named files. I did not inspect the diff or run the tests. Real-WSL validation is pending. It is a manual check, not a coding requirement.

Full details: Out of Scope Changes check

Explanation

Each changed area connects to #49180 or to the stated PR objectives:

(a) Account pinning and migration: wsl-orcad-host-user.ts, wsl-orcad-host-transport.ts, wsl-distro-holder*.ts, wsl-host-deployment-store.ts, wsl-host-registration.ts, wsl-host-connection-record.ts, wsl-host-account-migration.ts and wsl-host-user-connect.ts. These implement the pin and the one-time migration for older records.

(b) Account refusal and liveness: wsl-orcad-account-facts.ts, wsl-orcad-held-context.ts, wsl-orcad-deploy.ts, wsl-orcad-connection.ts, wsl-orcad-liveness-recovery.ts, wsl-orcad-pairing-identity.ts, orcad-managed-tunnel-identity.ts, orcad-managed-pairing-repair.ts and the status copy. These support the refusal, its final-error handling and its messages.

(c) Removal, forget and CLI: wsl-host-removal.ts, wsl-host-service.ts, wsl-host-types.ts, wsl-host-forget.ts, managed-orcad-actions.ts, managed-server.ts, the CLI spec, orcad-managed-runtime-context.ts and orcad-managed-runtime.ts. These implement the Remove, forget and CLI requirements.

(d) Renderer copy, i18n, protected-copy keys and the remote-pairing failure copy: these support the user-visible behavior in (a) to (c).

(e) Tests: the new test files cover pinning, refusal, migration, liveness, removal, holder behavior and public-key-only reads.

(f) config/main-blocking-helper-baseline.txt: updates the ratchet for the new WSL transport files and the moved holder spawn, as the PR description states.

(g) spawnDetachedHolder moved to wsl-distro-holder-command.ts, and the fake connector and fixture updates. These support the holder and pin changes.

The Claude/Codex account-home and hook-relay paths are documented as intentionally left unpinned. The summary shows no unrelated feature or refactor. Evidence comes from the whole-PR summary. I did not inspect the diff.

Full details: Description check

Explanation

The description is detailed and follows most of the template. It has a Problem, Fix, Tests, and Performance section, and it links issues #49180 and STA-18401. It is missing several required template parts. The ELI5 section is absent. The Visual Proof section is absent, even though the change alters user-visible WSL host status, Remove, and CLI messages. The Testing checklist boxes are unchecked, and the description does not state which platforms were tested. The Risk section has no Level value, and it does not describe how to back out the change. The AI Disclosure, Review, and Agent skill upstream boundary sections are missing or unfilled. The Notes and Checklist sections are also absent. The author says real-WSL validation is still pending, which is a material gap for a Windows-specific change.

Resolution

Add an ELI5 section in plain language. Add a Visual Proof section with before and after screenshots or videos of the WSL host status and Remove messages, or write N/A with a reason. State which platforms were manually tested, and tick the Testing checkboxes that apply. Fill in the Risk level (Low, Medium, or High) and describe the rollback path. Complete the Agent skill upstream boundary checkbox. Complete the Review and Checklist sections, or remove the template text that does not apply. Mention the real-WSL validation status in the Testing section.

  • 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

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Minor · Propagate a newly available Linux user when reusing a… · wsl-orcad-connection.ts:329-330

src/main/wsl/orcad/wsl-orcad-connection.ts:329-330
Minor · Data Integrity & Integration · Quick win

Propagate a newly available Linux user when reusing a connection.

If the first probe returns linuxUser: null and a later probe returns alice, the same-port reuse path keeps the old null. refreshOffer neither compares nor copies launch.linuxUser. The persistence caller therefore cannot pin the older record on that verified connect.

Include a newly available non-null linuxUser in the change check and copied fields. Preserve a known account when a later probe cannot read it.

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: f6e6333f-fe31-4ee0-9560-05e858f5652d
Commits

Reviewing files that changed from the base of the PR and between e97406c and 2f09c1e.

Files selected for processing: 33

  • src/cli/hosts/managed-server.ts
  • src/cli/specs/managed-server.ts
  • src/main/ipc/runtime-environments/managed-orcad/managed-orcad-actions.ts
  • src/main/ipc/wsl/wsl-host-forget.ts
  • src/main/wsl/host-lifecycle/wsl-host-connection-record.ts
  • src/main/wsl/host-lifecycle/wsl-host-e2e-fake-connector.ts
  • src/main/wsl/host-lifecycle/wsl-host-registration.ts
  • src/main/wsl/host-lifecycle/wsl-host-removal.test.ts
  • src/main/wsl/host-lifecycle/wsl-host-removal.ts
  • src/main/wsl/host-lifecycle/wsl-host-service.ts
  • src/main/wsl/orcad/wsl-orcad-account-facts.test.ts
  • src/main/wsl/orcad/wsl-orcad-account-facts.ts
  • src/main/wsl/orcad/wsl-orcad-connection-types.ts
  • src/main/wsl/orcad/wsl-orcad-connection.ts
  • src/main/wsl/orcad/wsl-orcad-deploy.ts
  • src/main/wsl/orcad/wsl-orcad-held-context.ts
  • src/main/wsl/orcad/wsl-orcad-host-transport.ts
  • src/main/wsl/orcad/wsl-orcad-host-user.test.ts
  • src/main/wsl/orcad/wsl-orcad-host-user.ts
  • src/main/wsl/orcad/wsl-orcad-launch-contract.ts
  • src/main/wsl/orcad/wsl-orcad-liveness-idle-stop.test.ts
  • src/renderer/src/components/sidebar/host-lifecycle/wsl-host-removal.ts
  • src/renderer/src/i18n/en-runtime-required.json
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/lib/remote-pairing/remote-server-pairing-error-copy.ts
  • src/shared/plugins/languages/protected-copy-keys.json
  • src/shared/remote-runtime/host-store/runtime-environment-pairing-replace-guards.ts
  • src/shared/remote-runtime/host-store/runtime-environment-wsl-host-operations.ts
  • src/shared/remote-runtime/host-store/runtime-environment-wsl-host-user-pin.test.ts
  • src/shared/remote-runtime/host-store/wsl-host-deployment-store.ts
  • src/shared/remote-runtime/orcad-lifecycle/orcad-managed-runtime.ts
  • src/shared/remote-runtime/pairing/remote-server-pairing-failure-copy.ts
  • src/shared/remote-runtime/wsl-hosts/wsl-host-types.ts

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

@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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Minor · Refresh the account fields when reusing a bridge. · wsl-orcad-connection.ts:331

src/main/wsl/orcad/wsl-orcad-connection.ts:331
Minor · Functional Correctness · Quick win

Refresh the account fields when reusing a bridge.

If a host stays pinned to alice and the distro default changes to bob, the next launch returns defaultLinuxUser: 'bob'. The same-port path calls refreshOffer, but this assignment retains the old account fields. The changed predicate also ignores them.

As a result, the connection can retain defaultLinuxUser: null, and runsAsOtherUserDetail does not show the account change. Compare and copy linuxUser and defaultLinuxUser with the other launch metadata. Keep the refresh quiet when all fields match.

Minor comments: 1

src/main/wsl/orcad/wsl-orcad-account-facts.ts: 1

37-37: Minor · Functional Correctness · Poor tradeoff

Refuse another account only when its managed orcad owns the port listener.

The probe matches a listener by UID alone. The awk program records the UID of each listener on the managed port. It then reports any process of that UID whose arguments contain ORCAD_ARGV, regardless of the port that process uses. If one account has a listener on the managed port and also runs an orcad on a different port, the probe reports that account as the other-account server. The held-context check then refuses Add and connect with WslOrcadOtherAccountServerError, and the message names the wrong owner.

The trigger requires a specific setup: one account must own a listener on the managed port while running its own orcad elsewhere. The refusal does not block a working deployment. Linux does not let this account's orcad bind a port that another UID's listener holds, so the deployment would fail with a port conflict without the refusal. The impact is a misleading error and a misdirected recovery step.

Correlate the listener with the process that owns its socket. The probe must return a peer only when that process is another account's managed orcad. The current ps -eo uid=,args= output has no PID, so the correlation also requires the PID. The socket inode is in column 10 of /proc/net/tcp and /proc/net/tcp6. When the probe cannot establish that ownership, it must not report an other-account refusal.

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: ef59fa1e-46d4-406d-a314-e82fc34b5829
Commits

Reviewing files that changed from the base of the PR and between 2f09c1e and 7ca288d.

Files selected for processing: 30

  • config/main-blocking-helper-baseline.txt
  • src/main/managed-server/lifecycle/orcad-managed-tunnel-identity.ts
  • src/main/wsl/discovery/wsl-distro-holder-command.ts
  • src/main/wsl/discovery/wsl-distro-holder.ts
  • src/main/wsl/host-lifecycle/wsl-host-account-migration.ts
  • src/main/wsl/host-lifecycle/wsl-host-connection-record.ts
  • src/main/wsl/host-lifecycle/wsl-host-e2e-fake-connector.ts
  • src/main/wsl/host-lifecycle/wsl-host-first-connect.ts
  • src/main/wsl/host-lifecycle/wsl-host-other-account-refusal.test.ts
  • src/main/wsl/host-lifecycle/wsl-host-removal.test.ts
  • src/main/wsl/host-lifecycle/wsl-host-removal.ts
  • src/main/wsl/host-lifecycle/wsl-host-ssh-orcad-conflict.ts
  • src/main/wsl/host-lifecycle/wsl-host-user-connect.ts
  • src/main/wsl/orcad/wsl-orcad-account-facts.test.ts
  • src/main/wsl/orcad/wsl-orcad-account-facts.ts
  • src/main/wsl/orcad/wsl-orcad-connection-types.ts
  • src/main/wsl/orcad/wsl-orcad-connection.ts
  • src/main/wsl/orcad/wsl-orcad-deploy.ts
  • src/main/wsl/orcad/wsl-orcad-held-context.ts
  • src/main/wsl/orcad/wsl-orcad-host-transport.ts
  • src/main/wsl/orcad/wsl-orcad-host-user.ts
  • src/main/wsl/orcad/wsl-orcad-launch-contract.ts
  • src/main/wsl/orcad/wsl-orcad-liveness-idle-stop.test.ts
  • src/main/wsl/orcad/wsl-orcad-liveness-recovery.ts
  • src/main/wsl/orcad/wsl-orcad-pairing-identity.ts
  • src/renderer/src/components/sidebar/host-admission/wsl/wsl-host-failure-text.ts
  • src/renderer/src/i18n/en-runtime-required.json
  • src/renderer/src/i18n/locales/en.json
  • src/shared/remote-runtime/host-store/wsl-host-deployment-store.ts
  • src/shared/remote-runtime/wsl-hosts/wsl-host-failure-copy.ts
Files skipped from review as they are similar to previous changes: 3

  • src/renderer/src/i18n/en-runtime-required.json
  • src/renderer/src/i18n/locales/en.json
  • src/shared/remote-runtime/host-store/wsl-host-deployment-store.ts

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

import { orcadPublicKeyCommand } from './wsl-host-ssh-orcad-conflict'

/** One line per account with an orcad key: `<name> <public key>`; run as root to read every home. */
export const WSL_ACCOUNT_KEYS_COMMAND = `getent passwd | while IFS=: read -r _orca_n _ _ _ _ _orca_h _; do [ -n "$_orca_h" ] && [ -d "$_orca_h/.orca" ] || continue; _orca_k=$(${orcadPublicKeyCommand('$_orca_h')}); [ -n "$_orca_k" ] && printf '%s %s\\n' "$_orca_n" "$_orca_k"; done`

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

Make the account-key scan exit 0 when the last account has no key.

The scan's exit status comes from its last account that has an .orca directory. If that account has no readable key, the && list fails and the scan exits 1. execCommand then rejects, and pinUnpinnedWslHostAccount returns null with a warning. A unique account that already printed a matching key is therefore discarded. The record stays unpinned, and the user must remove and re-add the host.

Use an if statement for the print. An if whose condition is false and has no else exits 0, so a missing key no longer fails the scan.

Suggested fix

--- "a/src/main/wsl/host-lifecycle/wsl-host-account-migration.ts"
+++ "b/src/main/wsl/host-lifecycle/wsl-host-account-migration.ts"
@@ -12,7 +12,7 @@
 import { orcadPublicKeyCommand } from './wsl-host-ssh-orcad-conflict'
 
 /** One line per account with an orcad key: `<name> <public key>`; run as root to read every home. */
-export const WSL_ACCOUNT_KEYS_COMMAND = `getent passwd | while IFS=: read -r _orca_n _ _ _ _ _orca_h _; do [ -n "$_orca_h" ] && [ -d "$_orca_h/.orca" ] || continue; _orca_k=$(${orcadPublicKeyCommand('$_orca_h')}); [ -n "$_orca_k" ] && printf '%s %s\\n' "$_orca_n" "$_orca_k"; done`
+export const WSL_ACCOUNT_KEYS_COMMAND = `getent passwd | while IFS=: read -r _orca_n _ _ _ _ _orca_h _; do [ -n "$_orca_h" ] && [ -d "$_orca_h/.orca" ] || continue; _orca_k=$(${orcadPublicKeyCommand('$_orca_h')}); if [ -n "$_orca_k" ]; then printf '%s %s\\n' "$_orca_n" "$_orca_k"; fi; done`
 
 /** The single account whose key is `publicKeyB64`; null when none or several hold it. */
 export function accountHoldingKey(output: string, publicKeyB64: string): string | null {
Committable suggestion

IMPORTANT
Review the replacement and indentation, then test before committing.

Suggested change
export const WSL_ACCOUNT_KEYS_COMMAND = `getent passwd | while IFS=: read -r _orca_n _ _ _ _ _orca_h _; do [ -n "$_orca_h" ] && [ -d "$_orca_h/.orca" ] || continue; _orca_k=$(${orcadPublicKeyCommand('$_orca_h')}); [ -n "$_orca_k" ] && printf '%s %s\\n' "$_orca_n" "$_orca_k"; done`
export const WSL_ACCOUNT_KEYS_COMMAND = `getent passwd | while IFS=: read -r _orca_n _ _ _ _ _orca_h _; do [ -n "$_orca_h" ] && [ -d "$_orca_h/.orca" ] || continue; _orca_k=$(${orcadPublicKeyCommand('$_orca_h')}); if [ -n "$_orca_k" ]; then printf '%s %s\\n' "$_orca_n" "$_orca_k"; fi; done`

}
serverStop = noteServerKeptForPeers(userDataPath, record.environmentId, serverStop)
if (serverStop.stopped) {
if (!serverStop.stopped && (forget || (record.pendingStop && mayForgetOnRetry(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.

Minor · Data Integrity & Integration · Quick win

Keep a host listed when its unrecorded peer-kept state is still unresolved.

A Remove that finds a server kept for another Orca, but cannot save the kept-for-peers marker, stores reasonCode: 'removalUnrecorded' in pendingStop. A later Remove then checks only the new stop result. If that retry fails or stays unverifiable, mayForgetOnRetry allows removal. The host is dropped without the marker ever being saved. Undo of a move onto this host then reads wasWslHostKeptForPeers as false. It reports stopped while the server may still run for another Orca. This breaks the invariant stated at line 108.

The retry path must not drop the host while the stored removalUnrecorded state remains unresolved. The exact behavior is a policy choice. The host can stay listed until the marker is saved or the server is proven stopped. Another option is to save the marker from the stored pending state before the host is dropped. Either option must leave wasWslHostKeptForPeers true for this environment, or leave the host listed, for every removal path that can reach undo.


it("flags another account's orcad only while it holds this host's port", () => {
const holding = run(
wslAccountFactsCommand(sources(`${ROOT_ORCAD}\n`, `${HEADER}\n${listener('1A70', '0')}\n`))

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

Use a peer UID that differs from the test process UID.

If this suite runs as root, the fixture and the current account both have UID 0. The probe correctly excludes the current account, so the assertion on Line 59 fails.

Select a fixture UID different from process.getuid() and use that UID in the process row, listener row, and assertion. This keeps the test valid for both root and non-root execution.

…in only after verify, replace other-account holders, drop the port refusal (#49180)

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

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: 2451b5a1-a6b1-4b09-a8a7-5adda5caef07
Commits

Reviewing files that changed from the base of the PR and between 7ca288d and 03376f4.

Files selected for processing: 21

  • config/main-blocking-helper-baseline.txt
  • src/main/managed-server/lifecycle/orcad-managed-runtime-context.ts
  • src/main/managed-server/lifecycle/orcad-managed-tunnel-identity.ts
  • src/main/wsl/discovery/wsl-distro-holder-command.ts
  • src/main/wsl/discovery/wsl-distro-holder-process-classification.ts
  • src/main/wsl/discovery/wsl-distro-holder-user.test.ts
  • src/main/wsl/discovery/wsl-distro-holder.ts
  • src/main/wsl/host-lifecycle/wsl-host-account-migration.ts
  • src/main/wsl/host-lifecycle/wsl-host-other-account-refusal.test.ts
  • src/main/wsl/host-lifecycle/wsl-host-removal.test.ts
  • src/main/wsl/host-lifecycle/wsl-host-removal.ts
  • src/main/wsl/host-lifecycle/wsl-host-user-connect.ts
  • src/main/wsl/orcad/wsl-orcad-account-facts.test.ts
  • src/main/wsl/orcad/wsl-orcad-account-facts.ts
  • src/main/wsl/orcad/wsl-orcad-held-context.ts
  • src/main/wsl/orcad/wsl-orcad-host-user.ts
  • src/main/wsl/orcad/wsl-orcad-liveness-recovery.ts
  • src/renderer/src/components/sidebar/host-admission/wsl/wsl-host-failure-text.ts
  • src/renderer/src/i18n/en-runtime-required.json
  • src/renderer/src/i18n/locales/en.json
  • src/shared/remote-runtime/wsl-hosts/wsl-host-failure-copy.ts
Files with no reviewable changes: 2

  • src/renderer/src/components/sidebar/host-admission/wsl/wsl-host-failure-text.ts
  • src/renderer/src/i18n/en-runtime-required.json
Files skipped from review as they are similar to previous changes: 3

  • config/main-blocking-helper-baseline.txt
  • src/main/managed-server/lifecycle/orcad-managed-tunnel-identity.ts
  • 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; 1 remain after this review.

pinnedWslHostLinuxUser(distro)
)
// One spawned for another account watches that account's release file: replace it (#49180).
const state = found === 'other-account' ? await stopRecordedHolder(read.record) : found

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

Do not adopt a mismatched holder when its termination fails.

If killProcess throws or the holder remains alive, stopRecordedHolder returns live. This line discards other-account, so ensureHeld returns adopted without creating a holder for the pinned account. The retained holder watches the other account's release file, so the pinned server's idle-release request cannot release it.

If termination does not reach exited, retain an unverifiable result or reject the ensure. Preserve replacement after confirmed termination.

...args: Parameters<typeof refreshWslHostPairing>
) => Promise<unknown> = refreshWslHostPairing
): Promise<void> {
await withWslHostLinuxUser(record.distro, found.linuxUser, async () => {

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 · Stability & Availability · Quick win

Overlapping migrations for one distro can clear the account override early.

withWslHostLinuxUser keeps one override per distro. The first scope to finish deletes it, even while another migration for the same distro is still running. Nothing in the Connect path serializes that scope. If two Connect requests for the same unpinned distro overlap, a connect that starts after the first scope ends can run as the default user and fail with the account mismatch this change fixes. The second scope then restores the account as a stale override. That override can remain until the process restarts.

Require the override for a distro to stay set until the last active migration for that distro ends. Choose the mechanism yourself: serialize the migration per distro, or keep a reference count in withWslHostLinuxUser. The fix must cover the whole scope, including the connect and the cleanup.


Minor · Functional Correctness · Quick win

Set the in-memory pin for the migrated account when the migration saves it.

connectAsPairedWslAccount saves linuxUser only to disk through persist. The in-memory pin changes only when readWslHostRecordsQuietly runs. When the withWslHostLinuxUser scope ends, pinnedWslHostLinuxUser(distro) returns undefined until the next record read. A transport process started in that window selects the distro default account, which the saved pairing does not match.

The window closes at the next record read, so the impact is transient. The migration should make the pin take effect as soon as the account is saved, so the next command does not depend on a record read.

Comment on lines +71 to +75
await persist(userDataPath, record.environmentId, {
pairingCode: encodePairingOffer(found.offer),
localPort: record.localPort,
remotePort: record.remotePort,
linuxUser: found.linuxUser

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

Stale pairing write after a connect that repairs the token.

The write at lines 71-76 always passes found.offer, which was read before connect() ran. The comment at line 70 assumes connect() leaves the saved pairing unchanged. That assumption fails when the server refuses the enrolled token. The repair then saves a replacement token, and this write can restore the refused token. The persisted host then holds credentials the server no longer accepts. The next reconnect must repair again.

Use the pairing that is stored after connect() completes, not found.offer. The write should then add only the pin, as the comment at line 70 states. Keep the port fields as they are; the evidence does not show a port change here.

throw new WslDistroVersion1Error(name)
}
if (facts.otherServerAccount) {
noteWslOtherAccountServer(name, facts.otherServerAccount)

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 · Heavy lift

Refuse Connect when another account's orcad holds the saved port.

The peer check looks only for another Linux account running a managed orcad. It does not check which port that orcad uses or whether it owns a listener. It only logs a warning, so Connect continues to context resolution and deployment. The warning says the host "keeps its own account's server and port," but the managed port is the single constant 6_768 for every account. A peer on the default port is therefore not excluded. The PR's stated behavior requires refusing Connect when another account owns a listener on the host's port and runs a managed orcad. Add that refusal before deployment. Keep the warning for a peer on a different port. Identity verification on connect still rejects a foreign server, but that check does not replace the required refusal before deployment.

…answers, single-flight and bound the trial, stop unpinned hosts as their paired account, harden the root probe (#49180)

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

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: 4b698db5-8a9f-4451-991e-085d9a961ccf
Commits

Reviewing files that changed from the base of the PR and between 03376f4 and 3c8610c.

Files selected for processing: 12

  • src/main/managed-server/lifecycle/orcad-managed-pairing-repair.ts
  • src/main/managed-server/lifecycle/orcad-managed-tunnel-identity.ts
  • src/main/wsl/discovery/wsl-distro-holder-process-classification.ts
  • src/main/wsl/discovery/wsl-distro-holder-user.test.ts
  • src/main/wsl/discovery/wsl-distro-holder.ts
  • src/main/wsl/host-lifecycle/wsl-host-account-migration.ts
  • src/main/wsl/host-lifecycle/wsl-host-other-account-refusal.test.ts
  • src/main/wsl/host-lifecycle/wsl-host-removal.ts
  • src/main/wsl/host-lifecycle/wsl-host-ssh-orcad-conflict.ts
  • src/main/wsl/orcad/wsl-orcad-host-user.ts
  • src/main/wsl/orcad/wsl-orcad-liveness-recovery.ts
  • src/main/wsl/orcad/wsl-orcad-pairing-identity.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.

}
if (error instanceof RemoteRuntimeClientError && FOREIGN_CLOSE_CODES.has(error.closeCode ?? 0)) {
return { verdict: 'foreign', detail }
return { verdict: 'foreign', detail, sealed: true }

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

Do not mark hello-stage close codes as sealed.

The close-code branch sets sealed: true for codes 4001 and 4003 without checking the handshake stage. A 4001 close during the e2ee_hello exchange occurs before the client authenticates the pinned server key. The framing code already notes that an on-path party can fake such a refusal. The sealed flag asserts that the pinned key's handshake refused, so this classification is incorrect for hello-stage closes.

The effect is material. wsl-orcad-liveness-recovery.ts treats sealed as final. It publishes a failed state and stops retrying. The wslHostServer message then tells the user to remove and re-add the WSL host. A transient or spoofed hello-stage close therefore produces a destructive user action instead of a retry.

Correct the classification so that sealed is set only for a 4001 or 4003 close that follows pinned-key authentication. Hello-stage closes must stay unsealed, so recovery can back off as it does for other foreign answers. The framing module already tracks this distinction with readyAccepted, but that state is not exposed to classifyOrcadTunnelIdentityFailure. The mechanism for exposing it is a design choice.

Also confirm the premise for code 4003. The inspected source does not show when 4003 is sent, so its handshake stage is not established.

… capped trial, seal only a readable key mismatch, probe the resolved distro name (#49180)

@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: 30ce30a0-b21c-4538-ab14-adfcaf8b84d6
Commits

Reviewing files that changed from the base of the PR and between 3c8610c and 773bc81.

Files selected for processing: 7

  • src/main/managed-server/lifecycle/orcad-managed-pairing-repair.ts
  • src/main/wsl/host-lifecycle/wsl-host-account-migration.ts
  • src/main/wsl/host-lifecycle/wsl-host-other-account-refusal.test.ts
  • src/main/wsl/host-lifecycle/wsl-host-ssh-orcad-conflict.ts
  • src/main/wsl/host-lifecycle/wsl-host-user-connect.ts
  • src/main/wsl/host-lifecycle/wsl-orcad-public-key-read.test.ts
  • src/main/wsl/orcad/wsl-orcad-connection-status.ts

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

const trial = withWslHostLinuxUser(record.distro, found.linuxUser, async () => {
// Aborting, not just rejecting: once the override ends, no step of the connect may run as the default user.
const cap = AbortSignal.timeout(timeoutMs)
await raceAbort(connect(cap), cap, record.distro)

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 · Stability & Availability · Heavy lift

Stop the trial's connect before the account override ends.

raceAbort rejects when the 10-minute timeout fires. It does not stop the connect work. withWslHostLinuxUser then removes the override. The connect transport is built without the trial's abort signal (wsl-orcad-connection.ts:195), so its wsl.exe spawns do not stop on the timeout. spawnWsl resolves the Linux user at spawn time (wsl-orcad-host-transport.ts:63-65). For an unpinned record, a command that starts after the override ends runs as the distro default account, not found.linuxUser.

Require the trial to stop all connect commands before the override ends. Pass the trial signal into the connect transport. Make the transport reject every command after the signal aborts, including the loop path in execWithClosedStdin (wsl-orcad-host-transport.ts:116-118). Also wait for the connect to settle before withWslHostLinuxUser returns.

…user-change

# Conflicts:
#	src/shared/remote-runtime/host-store/wsl-host-deployment-store.ts
@nwparker
nwparker merged commit 0d62221 into main Nov 28, 2026
70 checks passed
@nwparker
nwparker deleted the nwparker/wsl-default-user-change branch November 28, 2026 04:05
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.

[Bug]: WSL Hosts: Identity mismatch after changing default WSL user prevents connecting and removing host

1 participant