Skip to content

fix(wsl): keep the desktop pairing across host restarts - #29042

Merged
brennanb2025 merged 6 commits into
mainfrom
brennanb2025/wslchat-stable-client-identity
Oct 20, 2026
Merged

brennanb2025 merged 6 commits into
mainfrom
brennanb2025/wslchat-stable-client-identity

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​65 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​62
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​60 $\color{#cf222e}{\Huge{\mathbf{−}}}$​27 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​33

ELI5

Restarting a WSL host made the desktop forget who it was to that host. A federated worker could then report “dispatch_not_found” even though its saved dispatch still existed, because the host correctly refused access from the desktop's new identity. The desktop now keeps the same pairing across host restarts, so restart recovery can reach the existing worker.

What Changed

The host's device registry and encryption key already survive restart. Startup publishes a pairing offer for a new client, but WSL was replacing its existing, authenticated credential with that new offer. WSL now follows the existing managed SSH behavior: keep the saved client credential and pinned host key, and update only the bridge address. An existing bridge also verifies that saved credential when reconnecting, and a registered host with missing or unreadable saved credentials refuses reconnect rather than silently enrolling again. Revoked credentials and another host's key remain refused; explicit re-pairing establishes a different caller.

Neil's C5/C7 files touched: src/main/wsl/wsl-orcad-connection.ts, src/main/wsl/wsl-orcad-connection.test.ts, src/main/wsl/wsl-host-connector.ts, src/main/wsl/wsl-host-connection-record.ts, src/main/wsl/wsl-orcad-pairing-identity.ts, and src/shared/runtime-environment-wsl-host-store.ts. The shared tunnel pairing encoder accepts an optional existing pairing; existing SSH callers retain their behavior.

Why

Ownership belongs to a paired client, not a server process. Reusing the saved pairing fixes federation ownership, native-chat caller ownership, and delegated phone parentage together, without adding another identity store or weakening federation's ownership check. Notification replay already uses event IDs and epochs, and client capabilities are negotiated on each connection.

The common pattern retains enrollment across daemon restarts. Intended difference: Windows still reaches the host through the existing WSL stdio bridge; changing transport is unnecessary for stable enrollment. Existing gates remain in place, and no wire format changes are required for older hosts.

Linked Issue

Live Windows QA finding F1 in QA-PR11-REPORT.md: restarting the guest server changed the caller and prevented federated-worker recovery.

Visual Proof

N/A. Connection identity and restart recovery change; no UI elements change.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

One real authenticated RPC contract covers retaining the caller across host and desktop connection-manager restarts, refusing a revoked pairing, and changing the caller after explicit re-pairing. The bridge lifecycle test now expects startup offers to leave the enrolled identity intact. CI runs the checks; local lint, typecheck, tests, and builds are prohibited on this shared Mac for this lane.

CI passed on 5f9723e0a78b89b7f2d33f955689751050d7df26: PR workflow and aggregate gate, including static analysis/typecheck, all five unit shards, relay integration, and both packaging jobs. Completed logs confirm all 3 managed-tunnel restart tests and all 14 WSL connection tests passed. WSL2 systemd off/on also passed.

Windows QA handed to the coordinator: use a disposable imported distro and isolated profiles, launch a federated worker, record the pairing device ID and caller fingerprint without logging the token, restart only the recorded guest server PID mid-dispatch, then reconnect and verify the same dispatch is found and recovers without a duplicate worker. Recreate the desktop connection and repeat; explicit revoke must fail closed, and explicit re-pair must create a different caller without granting access to the old caller's dispatch.

Review

The saved host key and credential are still verified. Federation's exact fingerprint comparison is unchanged. No mover internals or new persisted fields are involved.

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

WSL-specific connection selection stays in WSL code. Managed SSH behavior, Linux execution ownership, folder workspaces, and mixed-version protocol compatibility are preserved. Attachments already orphaned by a discarded pre-fix credential are not reassigned to another caller. Live Windows mid-dispatch recovery is pending coordinator QA; the RPC contract is transport-independent and does not prove that live workflow.

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)

@brennanb2025

brennanb2025 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Problem. When the Orca server inside a WSL distro restarted, the desktop threw away its saved pairing and enrolled as a brand-new client from the server's fresh startup pairing offer. To the host that was a different caller, so a worker the desktop had already started there became unreachable ("dispatch not found") even though the host still had it.

User-facing change. Restarting the WSL server, or the desktop, no longer cuts the desktop off from work it started on that host. The desktop reconnects with the pairing it saved and the host key it pinned, and only picks up the server's new bridge address. A desktop whose pairing was revoked on the host is still refused, and removing and re-adding the host still creates a new pairing that cannot claim the old work.

Review. One full brennan-pr-review round on 5f9723e0a78 (independent architecture challenger, correctness review, user-visible behavior trace, persistent fixer). No confirmed findings and no review fixes. One late candidate (a same-port reconnect after an authentication failure) was traced independently and refuted: the failure is published and rethrown, and re-arming the existing watch does not mark the host ready. No new saved fields and no wire changes.

Final head 31240e443b22519f9b7c500bc7d14a1fea76ac4e is the QA'd head 5f9723e0a78 plus a main merge (two merge commits; the second only picked up main's fix for a floating-panel test that main itself had broken). The merge only updates import paths for files main moved (the managed-server lifecycle and SSH port-forwarding moves); no PR logic changed, and the PR's diff against main is still the same 8 files. Full PR workflow is green on the final head, including the PR checks passed aggregate.

Verified.

  • Windows Electron QA (see the Windows QA comment) with a real signed-in Claude Code inside a throwaway WSL2 distro: server restart and desktop restart kept the same paired device and host key, the running worker stayed reachable by its original IDs, a revoked pairing was refused, and re-pairing created a new identity that cannot reach the old dispatch. Those steps ran on the stacked fix(runtime): keep WSL workspaces open after host recovery #29106 head, which contains this PR; this PR's own head was used for the comparison below.
  • Automated: a managed-tunnel restart test that covers the retained caller across host and desktop restarts, revocation and explicit re-pairing, plus the WSL connection suite.

Deferred.

  • When a desktop restart moves the local bridge port, this PR alone still clears the selected workspace and drops its tabs (existing behavior on main). Stacked fix(runtime): keep WSL workspaces open after host recovery #29106 fixes that; on the fix(runtime): keep WSL workspaces open after host recovery #29106 head the same restart kept everything.
  • After a pairing is rejected, the host row says "Could not restart the Orca server … after 7 attempts" instead of the real reason (pairing rejected), and after re-pairing a message to the old dispatch is accepted on the desktop without an error even though the host never receives it. Both are QA side notes on failure-path wording, not yet traced to a cause; noted as follow-up candidates, not fixed here.

For Brennan's review

  • Screenshots from the Windows QA run (details in the Windows QA comment):

    Real Claude worker in the distro, started from the desktop coordinator:
    29042-C1-5-worker-terminal.png

    After a simulated revoke, reconnect is refused:
    29042-C5b-1-failed.png

    This PR alone after a desktop restart that moved the bridge port: no workspace selected and the tabs are gone (existing behavior; fixed by stacked fix(runtime): keep WSL workspaces open after host recovery #29106):
    29042-C6c-1-after-restart.png

  • src/main/ssh/orcad-tunneled-pairing.ts: a saved pairing now takes priority over the server's startup offer; the startup offer is used only for a client that has never paired.

  • src/main/wsl/wsl-orcad-pairing-identity.ts: a server that answers but is not the host we paired with is refused; one that does not answer only logs a warning.

@OrcaWin

OrcaWin commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Windows QA for head 5f9723e (Windows high spec, real signed-in Claude Code 2.1.302 inside a throwaway WSL2 distro, Codex driving the UI over CDP)

Note: steps 4-7 below ran on the #29106 head (7f2c19b), which contains this PR. This PR's own head was used only for the comparison at the end.

  • Step 4 PASS: added the WSL host, opened a folder project inside the distro and started a worker from a coordinator on the desktop; the worker was a real Claude Code session inside the distro.
  • Step 5, restart only the in-distro server, PASS: the desktop relaunched it in about 11 seconds. The paired device and the host's key stayed the same and only the process changed. The running worker survived, and the server's new startup pairing offer was not adopted.
  • Step 5 again after a full desktop restart PASS: the same held after the desktop itself restarted (its local connection port moved) and the in-distro server was then restarted again.
  • Step 6 PASS: the existing worker was still found by its original IDs (live, running). There was no "dispatch not found" error, still exactly one dispatch, and a message from the desktop reached the host.
  • Step 7 revoke PASS (simulated revoke): there is no product UI that revokes a desktop on a WSL host, so I removed the desktop's device record inside the distro and restarted the server. Reconnect then failed with "Remote Orca runtime rejected the pairing token" and nothing was adopted.
  • Step 7 re-pair PASS: removing and re-adding the host paired a new device with a new identity, and the old dispatch was refused with "dispatch_not_found".

Comparison with this PR alone (5f9723e): after a desktop restart that moved the local connection port, this PR alone cleared the selected workspace and dropped the editor and Claude tabs. On the #29106 head the same kind of restart kept the selection and all tabs.

Side notes: after the pairing was rejected, the host row said "Failed to start — Could not restart the Orca server in OrcaQaB3 after 7 attempts" although the server was running; the real reason (pairing rejected) only shows in the log. Also, after re-pairing, the desktop accepted a message to the old dispatch without an error, though the host correctly never received it.

Real Claude worker in the distro, started from the desktop coordinator:
29042-C1-5-worker-terminal.png

After the simulated revoke, reconnect fails:
29042-C5b-1-failed.png

This PR alone after a desktop restart: no workspace selected and the tabs are gone:
29042-C6c-1-after-restart.png

Final head 31240e4 = QA'd head 5f9723e plus a main merge; CI green on it

…stable-client-identity

# Conflicts:
#	src/main/wsl/wsl-orcad-connection.ts
#	src/main/wsl/wsl-orcad-pairing-identity.ts
@brennanb2025
brennanb2025 marked this pull request as ready for review October 19, 2026 05:07
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a1b963bb-ac66-4abf-a759-55298141062b
📥 Commits

Reviewing files that changed from the base of the PR and between 3fbbc13 and 31240e4.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 56dcd13e-422a-477f-8f6a-e78087d84ccf
📥 Commits

Reviewing files that changed from the base of the PR and between 70d00aa and 3fbbc13.

📒 Files selected for processing: 8
  • src/main/managed-server/lifecycle/orcad-managed-tunnel-identity-restart.test.ts
  • src/main/ssh/orcad-tunneled-pairing.ts
  • src/main/wsl/wsl-host-connection-record.ts
  • src/main/wsl/wsl-host-connector.ts
  • src/main/wsl/wsl-orcad-connection.test.ts
  • src/main/wsl/wsl-orcad-connection.ts
  • src/main/wsl/wsl-orcad-pairing-identity.ts
  • src/shared/runtime-environment-wsl-host-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.

📝 Walkthrough

WSL connections now resolve pairing offers using a saved pairing when available and verify the server identity during connection setup and same-port refresh. The host connector supplies saved offers for environments with a WSL host deployment. Tests cover caller fingerprint persistence across host restarts, rejection after paired-device removal, and pairing refresh behavior.

Estimated code review effort

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 3fbbc

No PR-caused issue was established that prevents merging. The reported workspace and dispatch behaviors warrant separate follow-up.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description is detailed and covers the change, rationale, testing, security considerations, compatibility, and visual proof. However, the required Linked Issue section does not contain an actual i… Add the actual linked issue in the Linked Issue section, such as Fixes #<issue-number>, unless the author is a maintainer and the repository exception applies.
Docstring Coverage Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 8 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: preserving the desktop pairing across WSL host restarts.
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 change, rationale, testing, security considerations, compatibility, and visual proof. However, the required Linked Issue section does not contain an actual issue link or issue number; it only references a QA report.

Resolution

Add the actual linked issue in the Linked Issue section, such as Fixes #&lt;issue-number&gt;, unless the author is a maintainer and the repository exception applies.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@brennanb2025
brennanb2025 merged commit 65d671e into main Oct 20, 2026
54 checks passed
brennanb2025 added a commit that referenced this pull request Oct 20, 2026
nwparker added a commit that referenced this pull request Oct 20, 2026
Its CI ran before #30863 added the check. Formatting pushed wsl-orcad-connection.ts past its line
limit, so its port-fallback listen moves next to the stdio bridge it wraps.
nwparker added a commit that referenced this pull request Oct 22, 2026
… rollback and recovery

orcad's startup offer names a pending device, which it re-mints once a client
has paired with it. Update, rollback and recovery re-paired the desktop from
that offer, so the desktop became a new device to its host after each one.
They now keep the enrolled grant, as WSL does since #29042.
nwparker added a commit that referenced this pull request Oct 22, 2026
… rollback and recovery

orcad's startup offer names a pending device, which it re-mints once a client
has paired with it. Update, rollback and recovery re-paired the desktop from
that offer, so the desktop became a new device to its host after each one.
They now keep the enrolled grant, as WSL does since #29042.
nwparker added a commit that referenced this pull request Oct 22, 2026
… rollback and recovery

orcad's startup offer names a pending device, which it re-mints once a client
has paired with it. Update, rollback and recovery re-paired the desktop from
that offer, so the desktop became a new device to its host after each one.
They now keep the enrolled grant, as WSL does since #29042.
nwparker added a commit that referenced this pull request Oct 22, 2026
… rollback and recovery (#31684)

* fix(ssh): keep the enrolled pairing across a managed server's update, rollback and recovery

orcad's startup offer names a pending device, which it re-mints once a client
has paired with it. Update, rollback and recovery re-paired the desktop from
that offer, so the desktop became a new device to its host after each one.
They now keep the enrolled grant, as WSL does since #29042.

* fix(orcad): count WSL incumbent terminals with the enrolled pairing, and warn on a changed host key

The WSL incumbent's terminal count authenticated with the startup offer, which
marked that pending device used, so every orcad start enrolled another device.
It now uses this desktop's enrolled pairing. After an SSH update, rollback or
recovery, a server that names a host key other than the pinned one is reported
with a warning instead of a plain success.

* fix(ssh): keep a pairing the terminal count repaired; leave the host-key warning to a follow-up

The census can repair a refused pairing before the update re-pairs, so the
enrolled grant is re-read from the store rather than taken from the copy read
first. The host-key warning goes back out: only the CLI would show it, and
surfacing it in the desktop lifecycle UI is a separate change.

* refactor: keep two touched files under the line limit after rebasing onto main

refreshPairing reads the enrolled offer in one statement, and the WSL connection
error classes move into their own file.
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.

2 participants