Skip to content

feat(pairing): re-pairing the same server keeps its environment - #27197

Merged
OrcaWin merged 2 commits into
mainfrom
OrcaWin/d4-d4-i2b-2
Oct 10, 2026
Merged

OrcaWin merged 2 commits into
mainfrom
OrcaWin/d4-d4-i2b-2

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

ELI5

When you open a fresh browser link for an Orca server the browser already knows, the browser used to treat it as a brand-new server. Your open terminals still pointed at the "old" server, so they broke with "Workspace identity is ambiguous across hosts". Now the browser recognises the same server and keeps its identity, so the terminals keep working.

What Changed

Before: every runtime browser-access link made the web client mint a new web-… environment id, even when the link's server key matched the server it was already paired with. New project and workspace data was labelled with the new id while open terminals still held handles with the old id, and terminal routing refused them as ambiguous. An alias list (compatibleEnvironmentIds) let selector lookups find the old ids, but it could not stop two ids naming one server.

After: re-pairing the same server keeps its environment id. The device token and endpoint are refreshed and the pairing revision is bumped, so requests captured under the old token are still fenced, exactly as a desktop re-pair of an existing server does. A link from a different server still gets a new id.

How it decides (one shared rule, classifyRuntimeHostRePair, for the web now and desktop next):

  • The server key, which the pairing handshake proves, is the trust root. A different key is always a different server.
  • Same key, and the server's host descriptor (published since feat(hosts): servers publish a host descriptor #27193) has the same installationId as the one pinned at the last pairing: same server, keep the id.
  • Same key but a different installationId: a deliberate copy that kept the key. It gets a new id.
  • Same installation, different machine binding (profile moved, Docker volume recreated, reinstall): same server, keep the id and pin the new binding. This is the design's default answer to "moved or a copy?".
  • A server that used to send a descriptor and no longer does (downgraded): keep the id by key, keep the old pin, and never learn a replacement from it.
  • No pin yet (paired before descriptors existed): keep by key and pin the first descriptor the pairing brings.

Because the id no longer changes, the web client's own fences now also compare the pairing revision. A request that started before the re-pair can neither reopen a connection with the replaced token nor save the old pairing back over the new one. Before, the id change did this by accident.

The web client stores the pin next to its saved pairing and never exposes it through runtimeEnvironments.list. The alias list is no longer extended. Aliases saved by earlier builds are still read and carried forward, so terminals that already hold an old id keep resolving.

Why

The id is the server's execution-host identity, and everything the client keeps (layouts, terminal handles, workspace rows) is keyed by it. Keeping it stable fixes the root cause. Adding more aliases only hides it, because routing still sees two hosts.

Alternatives considered:

  • Key only (the approach in fix(web): preserve host identity across same-server re-pairing #11575, whose test is harvested here) fixes the bug. But it can't tell a server that kept its key while resetting its installation apart from the original, and it gives desktop no rule to share. The descriptor check costs a few lines and is the rule the next PR applies on desktop.
  • Dropping the legacy alias list entirely would strand terminals that already hold an id minted by an earlier re-pair, so it is read-only instead.

Scope, adapted from the design (I2b-2 grew past one reviewable PR, so it is split):

Linked Issue

Fixes #11574

Visual Proof

N/A: the change is in how the browser saves a pairing. Nothing new is drawn. The visible effect, terminals no longer failing as ambiguous after opening a new link, is covered by the tests below.

Testing

  • Automated tests added/updated
  • web-runtime-environment-repair.test.ts (new): re-pairing the same key keeps web-server-a, keeps createdAt, bumps the pairing revision, stores the fresh token and the pin, adds no alias, and does not expose the pin in the public environment. A same-key offer with a different pinned installation gets a new id. A downgraded offer with no descriptor keeps the id and the old pin. A malformed stored pin is dropped, not trusted. All four fail on origin/main @ cbeb703 (the id changes to a fresh web-…).
  • Same file: a reply to a request sent before the re-pair doesn't overwrite the new pairing, and the next request connects with the fresh token. This test fails without the revision fence.
  • runtime-host-pairing-identity.test.ts (new): every branch of the rule.
  • web-pairing.test.ts: a readable descriptor in a pairing link is kept; an unreadable one is dropped without refusing the link.
  • Existing web-preload-api-runtime-environment.test.ts (different key never resolves the old id, legacy aliases, malformed aliases) passes unchanged.
  • pnpm tc, oxlint, check:code-quality:changed pass. Tested on macOS; Linux and Windows are covered by CI.

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

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)

m4air and others added 2 commits October 10, 2026 01:36
The web client minted a new environment id on every runtime-scope pairing link,
even for the same server key, so existing terminals kept the old id and failed
as ambiguous. A key-matched re-pair now keeps the id (bumping the pairing
revision) and pins the server's host descriptor; a same-key server with a
different installation gets a new id, and a downgraded server never replaces
the pin.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…erver re-pair

Re-pairing now keeps the environment id, so fence on the pairing revision too:
a request captured before the re-pair can neither reopen a client with the
replaced token nor save the old pairing back over the new one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: e54aacd5-0f30-494c-92a5-20b7f7f9fe77


📥 Commits

Reviewing files that changed from the base of the PR and between 180e8c1 and c185bc5.



📒 Files selected for processing (7)
  • src/renderer/src/web/preload-api/web-runtime-session.ts
  • src/renderer/src/web/web-pairing.test.ts
  • src/renderer/src/web/web-pairing.ts
  • src/renderer/src/web/web-runtime-environment-repair.test.ts
  • src/renderer/src/web/web-runtime-environment.ts
  • src/shared/runtime-host-pairing-identity.test.ts
  • src/shared/runtime-host-pairing-identity.ts


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




📝 Walkthrough
📝 Walkthrough

Walkthrough

Web pairing offers can include a validated host descriptor. Re-pairing compares host keys and installation IDs to decide whether to retain the stored environment identity and pin. Runtime requests and response updates now check the active pairing revision as well as the environment ID. Tests cover descriptor validation, re-pair classification, stored environment updates, and stale RPC replies.



Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to c185b

Same-server re-pairing preserves the environment ID while refreshing credentials. The inspected client lifecycle does not leave requests using the replaced token; no merge blocker was identified.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed Issue #11574 requires same-key web re-pairing to retain the execution-host ID and refresh credentials, while a different key receives a new ID. createStoredWebRuntimeEnvironment matches the offer ke…
Out of Scope Changes check Passed The changed files support issue #11574. Host-descriptor parsing and pinning define same-key server identity. Pairing-revision checks prevent stale requests from restoring replaced credentials. The add…
Title check Passed The title clearly and concisely describes the main change: preserving the environment when re-pairing the same server.
Description check Passed The description follows the required template and explains the user impact, implementation, rationale, linked issue, testing, scope, compatibility, and checklist status. It provides no visual proof be…

  • Fix all pre-merge checks with AI
✨ 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.

@OrcaWin
OrcaWin merged commit b80c420 into main Oct 10, 2026
53 of 55 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.

[Bug]: Same-server web re-pairing changes execution-host identity and strands existing sessions

1 participant