Skip to content

fix(pairing): drop only the syncing desktop's relayed phones - #51226

Merged
AmoabaKelvin merged 2 commits into
mainfrom
fix/delegated-sync-origin
Nov 27, 2026
Merged

AmoabaKelvin merged 2 commits into
mainfrom
fix/delegated-sync-origin

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

ELI5

When your Mac relays your phone to an Orca server, the server keeps one "phone via this Mac" entry per phone. Each time the Mac tells the server "these are my phones", the server removes the ones not on the list. Until now it removed every phone under that Mac's server pairing, even ones that belong to another Mac sharing the same pairing, and it could never remove phones a Mac left behind under an older pairing. Now the Mac says which installation it is, and the server removes only that installation's phones, wherever they were added.

Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​44 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​43
Prod 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​67 $\color{#cf222e}{\Huge{\mathbf{−}}}$​20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​47

What Changed

  • pairing.delegatedMobileDevice.sync takes an optional clientInstanceId (the desktop installation id that the account declaration already sends). A new runtime capability, pairing.delegated-mobile-devices-origin.v1, says a server accepts it. The params schema is .strict(), so a desktop sends the field only to servers that advertise the capability.
  • The server works out which rows to drop in one place, droppedDelegatedPhones:
    • It drops unwanted phones of the syncing installation under any of that installation's rows, so a phone minted under a row from before a re-pair can still be removed.
    • It drops unwanted phones that no installation has claimed, but only under the calling row, as before.
    • It never touches phones another installation claimed on a shared row.
  • When the sync carries no id (an older desktop), the server falls back to the socket's declared installation. If that declaration hasn't arrived yet (it is fire-and-forget), the sync drops only unclaimed phones, not every child under the row.
  • DeviceRegistry.listDelegatedMobileDevices had one remaining caller and is removed.

Why

Phones are about to get server pairings of their own, chained to these delegated rows (the next PRs in this stack). After that, deleting a delegated row is what revokes a phone's direct access, so the server has to delete exactly the right rows:

  • Removing too many cuts off another desktop's phones.
  • Never removing the rows under an old pairing leaves an unpaired phone with access.

The origin used to come only from the socket's async declaration, which usually arrives after the first sync. Sending it in the sync itself takes that race away for new desktops.

The capability gate keeps every version pairing working:

  • New desktop, old server: the old server never sees the new field.
  • Old desktop, new server: keeps today's behaviour, except that it no longer drops phones another installation has claimed.

Linked Issue

Part of #40079, #27988, #26291 and #10426. Those issues are fixed once phones can mint their own server pairings later in this stack; this PR makes revocation of those pairings exact.

Visual Proof

N/A: no UI changes. The proof is a real three-process run, described under Testing.

Testing

Real run on macOS with two worktree-built orca serve processes: a server, and a "desktop" paired to the server as a runtime environment. A phone-protocol client was paired to the desktop as a mobile device.

  • The phone's status.get tagged with the server's execution host was relayed and answered by the server's runtime.

  • The server's orca-devices.json gained one mobile row: parentDeviceId is the desktop's runtime row, phoneKey is the phone's device id on the desktop, and originClientInstanceId is the desktop's installation id, now sent in the sync params.

  • delegated-mobile-devices.test.ts pins the drop rule for desktops sharing one row and for a row left behind by a re-pair. It fails against the old filter.

  • I manually tested these changes locally

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

  • Every added test fails without this change and avoids the test anti-patterns

Performance

None, because this changes only how the server picks rows on a sync it already does. It is one pass over the device list instead of a filtered pass, with no new syncs, reads or writes. The desktop's installation id is already cached in memory for the account declaration.

Risk

The riskiest part is the drop rule, because it decides which phones lose access.

  • Too loose: another desktop's phones on a shared row would be cut off, and they would recover on that desktop's next sync.
  • Too strict: a phone this desktop unpaired would keep its delegated row until a later sync. Today only the desktop holds that row's token, so the phone can't use it.

A paired desktop could claim another installation's id. It already holds workspace permission on the server, which lets it run terminals there, so the claim gives it no new power. A plain revert restores the old drop rule.

Level: Medium

AI Disclosure

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

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

The server side is shared by Electron serve and orcad. The desktop side changes only the params of a sync it already sends.

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)
  • I stated the risk: what could break, for whom, and how to back it out
  • 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)

A server dropped every relayed phone under a desktop's row on each sync, so
desktops sharing one row revoked each other's phones, and phones a desktop
minted under its row from before a re-pair could never be cut. The sync now
names the desktop's installation, and the server drops only that
installation's unwanted phones, on any row.
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Delegated phone sync can include the desktop client instance ID when the host advertises the origin-runtime capability. The RPC path forwards that ID to the server. The server uses the ID to select unwanted delegated child devices for removal while retaining phones associated with other installations. Tests cover selection across installations and rows.

Merge Risk: Low · up to 19df2

Delegated phone sync now removes only the syncing desktop's phones, including phones left under an older pairing. The server uses the installation ID the client sends without checking it against the caller's declared installation. A paired desktop could therefore remove another installation's relayed phones, and those would be re-created on that desktop's next sync. The author has accepted this tradeoff, and the exposure is limited to already-paired devices that hold broad workspace access. The remaining risk is low, but the owner should know about it before merging.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the server now drops only the syncing desktop's relayed phones. It is a conventional fix(pairing) title, short, and matches the changeset (droppedDelegatedPhones, clie…
Description check Passed The description follows the repository template. It includes ELI5, What Changed, Why, Linked Issue, Visual Proof (N/A with reason), Testing with a real three-process macOS run, Performance, Risk with …
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: Title check

Explanation

The title names the main change: the server now drops only the syncing desktop's relayed phones. It is a conventional fix(pairing) title, short, and matches the changeset (droppedDelegatedPhones, clientInstanceId in sync, shared-row handling). It is 60 characters, which is within a normal title length.

Full details: Description check

Explanation

The description follows the repository template. It includes ELI5, What Changed, Why, Linked Issue, Visual Proof (N/A with reason), Testing with a real three-process macOS run, Performance, Risk with level and revert path, and the checklist. Gaps: the Risk section's Level is filled in as Medium, which is fine. The AI Disclosure section is empty, but the template says to ignore it for internal contributors, so this is not a defect unless the author is external. The Linked Issue uses 'Part of' references rather than 'Fixes #', which the template says must be an actual issue. The lint/typecheck/test/build checklist item is left unchecked.

  • 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

Recent 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: a7a75369-a436-4e16-be13-522cc27780dd
Commits

Reviewing files that changed from the base of the PR and between 9c44c9e and 19df2c2.

Files selected for processing: 1

  • src/main/runtime/rpc/core.ts
Files skipped from review as they are similar to previous changes: 1

  • src/main/runtime/rpc/core.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.

@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: bcba5ee8-d522-4954-a2f2-436ddf18a094
Commits

Reviewing files that changed from the base of the PR and between 08e4629 and 9c44c9e.

Files selected for processing: 11

  • src/main/runtime/mobile-desktop-relay/delegated-phone-grants.ts
  • src/main/runtime/rpc/core.ts
  • src/main/runtime/rpc/methods/pairing/pairing.ts
  • src/main/runtime/rpc/server/pairing/delegated-mobile-devices.test.ts
  • src/main/runtime/rpc/server/pairing/delegated-mobile-devices.ts
  • src/main/runtime/rpc/server/pairing/device-registry-external-edit.test.ts
  • src/main/runtime/rpc/server/pairing/device-registry.ts
  • src/main/runtime/rpc/server/runtime-rpc-mobile-devices.ts
  • src/main/runtime/rpc/server/runtime-rpc-websocket-dispatch.ts
  • src/shared/remote-runtime/pairing/delegated-mobile-device-contract.ts
  • src/shared/remote-runtime/relay/mobile-desktop-relay-contract.ts
Files with no reviewable changes: 1

  • src/main/runtime/rpc/server/pairing/device-registry.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.

@AmoabaKelvin
AmoabaKelvin merged commit 679c18d into main Nov 27, 2026
57 checks passed
@AmoabaKelvin
AmoabaKelvin deleted the fix/delegated-sync-origin branch November 27, 2026 23:31
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