Skip to content

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

Merged
nwparker merged 4 commits into
mainfrom
nwparker/ssh-orcad-keep-enrolled-pairing
Oct 22, 2026
Merged

nwparker merged 4 commits into
mainfrom
nwparker/ssh-orcad-keep-enrolled-pairing

Conversation

@nwparker

@nwparker nwparker commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​177 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​167
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​54 $\color{#cf222e}{\Huge{\mathbf{−}}}$​33 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​21

ELI5

When Orca updates, rolls back or recovers a managed server on an SSH host, it used to re-pair this desktop using the server's "new client" invitation, not the pairing the desktop already had. To the host, the desktop then looked like a brand-new device after each of those actions. It now keeps its existing pairing, as WSL hosts already do.

What Changed

  • Before: after Update, Rollback or Recover on a managed SSH server, the desktop's saved credential was replaced by the token from the server's startup invitation. That invitation is only reused while nobody has accepted it. Once this desktop has paired, every restart issues a new device. So the desktop's identity to its host changed each time. Anything tied to that identity (which caller started a worker, which phone it relays, chat ownership) then pointed at an old device, and the old device was left registered.

  • After: those three actions keep the enrolled credential and pinned host key, and refresh only the local tunnel address. This is the same rule WSL hosts follow since fix(wsl): keep the desktop pairing across host restarts #29042.

  • Same class on WSL: before an update, the WSL host's terminal count authenticated with the startup offer. That marked the pending device as used, so every orcad start enrolled yet another device on the distro. The count now uses this desktop's enrolled pairing.

Mechanism: refreshPairing in src/main/ssh/orcad-runtime-maintenance.ts now passes the saved offer to tunneledOrcadPairingCode. It reads that offer from the store at that moment, because the terminal count may have repaired a refused pairing in between. WSL's incumbent count (wsl-orcad-incumbent.ts) gets the enrolled offer through a new pairedOffer deploy option. The store comment that implied the startup offer is stable across versions now says what is actually stable: the device registry.

Why

The store's comment suggested this was harmless, because "orcad keeps its pairing state across versions". The registry does persist, but the startup offer is a pending device that the registry re-mints once a client has used it. A new test pins exactly that against the real DeviceRegistry.

I chose keeping the enrolled grant over re-pairing because it is what the SSH connect and WSL already do. A credential the host no longer knows (for example after a rollback restored older server state) is still caught by the existing automatic pairing repair, which re-pairs from the startup offer only when the host refuses the token and the pinned host key matches.

Linked Issue

None; found by the SSH cleanup pass (maintainer work).

Visual Proof

N/A: no UI change; this changes which credential is saved after server maintenance.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • New tests for update, rollback and recover each fail on main (the token became the startup offer's) and pass here.

  • A registry test shows the startup offer repeats while unused and names a new device once a client pairs.

  • A WSL test with a real device registry shows three restarts grew it from 2 to 4 devices on main; with this change it stays at 2.

  • A pairing the terminal count repaired is kept, not overwritten by the copy read before it.

  • Ran the managed-server suites, pnpm tc:node and the full static job. The Docker managed-orcad lane runs in CI.

  • Verified live: nothing beyond CI.

Mixed versions: an old orcad on the host keeps its device registry the same way, so the enrolled grant stays valid. No wire change.

Review

Codex review and an independent 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

SSH and WSL. Folder workspaces are unaffected. Follow-ups, not in this PR:

  • Show a warning in the desktop UI when a restarted server names a host key other than the pinned one.
  • Give WSL the refused-pairing repair SSH has.

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)

@coderabbitai

coderabbitai Bot commented Oct 21, 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: 2e84415c-a309-41ec-b0ad-3fe8b5f5de2b
📥 Commits

Reviewing files that changed from the base of the PR and between e8f8f49 and 5109a40.

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: 5487d27c-9921-4b30-92d5-77dd96b7afc7
📥 Commits

Reviewing files that changed from the base of the PR and between 31ea86c3e1f2366b70e546fcdc7b2e3a823e73f5 and e8f8f49.

📒 Files selected for processing: 10
  • src/main/ssh/orcad-runtime-maintenance.test.ts
  • src/main/ssh/orcad-runtime-maintenance.ts
  • src/main/wsl/wsl-host-first-connect.ts
  • src/main/wsl/wsl-host-service.test.ts
  • src/main/wsl/wsl-orcad-connection-errors.ts
  • src/main/wsl/wsl-orcad-connection.test.ts
  • src/main/wsl/wsl-orcad-connection.ts
  • src/main/wsl/wsl-orcad-deploy.ts
  • src/main/wsl/wsl-orcad-incumbent.test.ts
  • src/main/wsl/wsl-orcad-incumbent.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.

📝 Walkthrough

Managed Orcad pairing refresh now passes the environment’s preferred pairing offer to pairing-code generation. Tests verify that update, rollback, and recovery preserve the enrolled device token, pairing revision, and deployment metadata when a server offers a new device. WSL deployment passes the enrolled offer to incumbent reading, which uses it during terminal census parsing. Tests cover WSL offer propagation and registry behavior. The managed pairing refresh comment was updated.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to e8f8f

A missing enrolled offer safely defers an update rather than counting terminals with a startup credential. The change is mergeable after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 12 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: preserving the enrolled pairing during managed server update, rollback, and recovery.
Description check Passed The description is complete and well aligned with the template. It explains the user impact, mechanism, rationale, testing, scope, and compatibility considerations. The missing issue link is explicitl…
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 complete and well aligned with the template. It explains the user impact, mechanism, rationale, testing, scope, and compatibility considerations. The missing issue link is explicitly justified as maintainer work, which the template permits.

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

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

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments: 1
src/main/ssh/orcad-runtime-maintenance.test.ts: 1

95-101: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Assert the pinned key and local endpoint in the maintenance tests.

The shared helper does not assert publicKeyB64 or the persisted endpoint. The fixture also gives the startup offer the same public key as the enrolled offer. A regression that selects a different startup host key would therefore pass all three maintenance tests.

Suggested fix
 import {
   createManagedLifecycleHarness,
   MANAGED_PREVIOUS_VERSION,
   MANAGED_VERSION,
+  MANAGED_LOCAL_PORT,
   managedReadiness
 } from '../managed-server/lifecycle/orcad-managed-lifecycle-test-fixture'
 
 function expectEnrolledPairing(): void {
   const [environment] = listEnvironments(harness.userDataPath)
   expect(environment?.endpoints[0]?.deviceToken).toBe('device-token')
+  expect(environment?.endpoints[0]?.publicKeyB64).toBe('public-key')
+  expect(environment?.endpoints[0]?.endpoint).toBe(
+    `ws://127.0.0.1:${MANAGED_LOCAL_PORT}/`
+  )
   expect(environment?.pairingRevision).toBe(harness.environment.pairingRevision)
   expect(environment?.orcadDeployment).toEqual(harness.environment.orcadDeployment)
 }
-export function managedReadiness(deviceToken = 'device-token'): ServeReadiness {
+export function managedReadiness(
+  deviceToken = 'device-token',
+  publicKeyB64 = 'public-key'
+): ServeReadiness {
...
-        publicKeyB64: 'public-key'
+        publicKeyB64

Pass a distinct public key, such as managedReadiness('startup-offer-token', 'startup-public-key'), in the update, rollback, and recovery cases.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 96ba517b-a0e1-46e3-a7a8-9e2d0dd7fd11
📥 Commits

Reviewing files that changed from the base of the PR and between d22fb0d and 31ea86c3e1f2366b70e546fcdc7b2e3a823e73f5.

📒 Files selected for processing: 4
  • src/main/runtime/device-registry-startup-offer.test.ts
  • src/main/ssh/orcad-runtime-maintenance.test.ts
  • src/main/ssh/orcad-runtime-maintenance.ts
  • src/shared/runtime-environment-managed-orcad-store.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.

@nwparker
nwparker force-pushed the nwparker/ssh-orcad-keep-enrolled-pairing branch from 60a8d49 to a022c4e Compare October 22, 2026 00:02
@nwparker
nwparker force-pushed the nwparker/ssh-orcad-keep-enrolled-pairing branch from 360ec1d to e8f8f49 Compare October 22, 2026 01:15
… 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.
…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.
…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.
…onto main

refreshPairing reads the enrolled offer in one statement, and the WSL connection
error classes move into their own file.
@nwparker
nwparker force-pushed the nwparker/ssh-orcad-keep-enrolled-pairing branch 2 times, most recently from e8f8f49 to 5109a40 Compare October 22, 2026 02:00
@nwparker
nwparker merged commit 5793b05 into main Oct 22, 2026
66 of 102 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