You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(pairing): let a relayed phone mint its own pairing with a server - #51277
Your phone reaches the Orca servers your Mac is paired with by going through the Mac, so when the Mac sleeps the phone loses them. This adds the server side of a fix: the phone, still talking through the Mac, can ask a server for a pairing of its own. After the phone confirms it, the phone talks to that server directly, and closing the Mac no longer cuts it off. Unpairing the phone on the Mac, or removing the Mac from the server, still removes that pairing.
Files
Added
Deleted
Net
Test
1
$\color{#1a7f37}{\Huge{\mathbf{+}}}$113
0
$\color{#1a7f37}{\Huge{\mathbf{+}}}$113
Prod
17
$\color{#1a7f37}{\Huge{\mathbf{+}}}$283
$\color{#cf222e}{\Huge{\mathbf{−}}}$20
$\color{#1a7f37}{\Huge{\mathbf{+}}}$263
What Changed
The new method. A new server method, pairing.delegatedMobileDevice.createOffer, advertised by the runtime capability pairing.delegated-phone-server-offers.v1.
Only a phone row that a paired desktop relays (it has a parentDeviceId) gets the context. Any other caller gets delegated_phone_required.
Permission is workspace: a relayed phone can already open terminals on that server, so this grants nothing new and never pairing-admin.
The offer it mints. An ordinary phone pairing offer:
createdByDeviceId is the phone's relayed row, so the existing revoke cascade removes the offer, its Relay credential and its push registration when the desktop is revoked on the server, or when the desktop's sync drops the phone.
It copies the relayed row's reach, so the new row never makes a restart bind every interface.
It never widens the listener. createMobilePairingOffer gains exposure: 'as-bound', which skips ensureNetworkExposure.
It offers a direct address only when the listener already answers off this host, using the same pinnedListenerAddress rule as orca pair.
Otherwise it mints through the server's own Orca Relay, so the server's sign-in and team policy decide.
It expires after 10 minutes and is named " via " in the server's device list.
If Relay is unavailable and the server has a direct address, it falls back to a LAN offer. A mint superseded by a newer request is answered as is instead.
The desktop's part.
It forwards the method as an execution-host call; one line in the phone allowlist.
It overwrites connectionMode with how the phone itself paired with the desktop, so a LAN-only phone never gets a Relay pairing.
Smaller changes.
A paired client's offer rotation now drops only its own pending offers. Before, a phone's mode switch rotated away every pending offer, including the owner's QR. The owner's own rotation still drops them all.
Messages typed from the phone over its own pairing name the same person and computer as when it was relayed.
Why
The phone had no credential or route of its own to any server, so every server went through the desktop. The phone deliberately never gets the desktop's delegated token: delegated rows refuse key forks and ticket exchange, and the phone's encryption ends at the desktop. Asking the server for a normal pairing that hangs off the phone's relayed row reuses everything that already exists: offers, Relay invites, pair-confirm on the phone, and the revoke cascade. It adds one method instead of a new credential type.
Rejected alternatives:
The desktop minting offers as itself would widen pairing-admin to every runtime client.
Running a hub on an always-on box doesn't help when the hub is the laptop.
Linked Issue
Part of #40079, #27988, #26291 and #10426. The phone's menu item comes in the next PR. #51226 and #51227 made the revocation side reach the server.
Visual Proof
N/A: no UI in this PR. The phone action and its screenshots come in the next PR.
Testing
delegated-phone-server-offers.test.ts runs a real OrcaRuntimeRpcServer that is unpinned and on loopback, like the desktop app's own server. It covers four cases:
A LAN-only request with no off-host listener is refused.
A Relay request mints an automatic offer and the listener stays on 127.0.0.1.
The minted row copies the relayed row's reach and createdByDeviceId.
Revoking the desktop removes the minted row.
loopback-pinned-pairing-offer.test.ts still passes. Typecheck and lint pass.
The full phone → desktop → server run is in the next PR, where the phone action lives.
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 the method runs once per tap on the phone and reuses the existing offer pipeline. The relayed-frame rewrite returns early for every other method and reads the phone's connection mode only for this one.
Risk
The riskiest part is pairing authority.
The context exists only for relayed phone rows, and the offer is chained to that row.
An old desktop doesn't know the method and refuses it. An old server doesn't advertise the capability, so the phone won't offer the action.
If something goes wrong, the extra pairing appears in the server's device list as " via " and can be revoked there.
A plain revert removes the method. Pairings already minted stay until revoked.
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. On SSH-managed orcad, which listens only on loopback, the only route is Relay, so the server must be signed in to Orca.
Follow-up: a delegated request still bumps the shared offer generation, so a phone tapping at the same moment the owner mints a Relay QR supersedes the owner's in-flight mint, which then has to be retried. This was already possible between the owner and orca pair callers.
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)
No actionable comments were generated in the recent review.
Walkthrough
The change adds an RPC operation for relayed phones to create server pairing offers. The offer flow selects automatic or local-only pairing and returns an available offer or phone-specific guidance. Pairing offers can specify reach and exposure, and rotation can filter pending offers by creator. Relay frame rewriting supplies the phone’s connection mode. Paired-device identification handles devices minted through a relayed mobile owner.
Merge Risk: Low · up to 771eb · assessed changes only
Path filters excluded changed files. This rating applies only to the assessed changes.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title "feat(pairing): let a relayed phone mint its own pairing with a server" matches the main change: a new server method, pairing.delegatedMobileDevice.createOffer, lets a relayed phone request …
Description check
The description follows the repository template closely. It includes ELI5, What Changed, Why, Linked Issue, Visual Proof (marked N/A with a reason), Testing with checkboxes, a Performance line, a Risk…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title "feat(pairing): let a relayed phone mint its own pairing with a server" matches the main change: a new server method, pairing.delegatedMobileDevice.createOffer, lets a relayed phone request its own server pairing offer. The changeset includes the delegated offer contract, the RPC context service, the offer creation logic, and the relay forwarding changes, all of which serve this goal. The title is specific, concise, and follows a conventional commit style. It omits secondary changes such as the rotation scoping and the connection-mode overwrite, which is acceptable.
Full details: Description check
Explanation
The description follows the repository template closely. It includes ELI5, What Changed, Why, Linked Issue, Visual Proof (marked N/A with a reason), Testing with checkboxes, a Performance line, a Risk section with a level and rollback path, and the Notes and Checklist sections. The AI Disclosure section is empty, which is acceptable for the template's internal-contributor case only if the author is a team member; the author has not stated this. The Linked Issue section uses 'Part of' and 'Refs'-style references instead of a 'Fixes #' link, which the template says outside contributors must provide. The lint, typecheck, test, and build checkbox is unchecked. These gaps are non-critical, so the description is mostly complete.
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Security & Privacy · Quick win
Reject mints whose creator row was removed before the credential is saved.
The delegated offer callback captures the phone's device row. It awaits the default-address lookup before minting. The offer then names that row as createdByDeviceId. If the phone's row is revoked during that await, the mint still runs and createAndPersistDevice saves the new row. The merge in device-registry-disk-merge.ts keeps any row whose ID is not already known, so the new row is written to disk. The revoke cascade had already run, so it does not remove this row. The row keeps a createdByDeviceId that names a removed row, and it stays pending until its 10-minute expiry.
Add a commit-time check that the creator row still exists before the credential is saved. Reject the mint with an error when it does not. Apply the check in the same save path that persists the new row, not only in the callback, because the removal can land between the callback's check and the save. Add a test that revokes the phone's row during the address lookup and asserts that no pending row is persisted.
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 0397f8c. After the mint, the offer is discarded (with its Relay invite revoked) if the phone's relayed row is gone, and the phone gets revoked. The check runs synchronously right after the awaited mint, so a revoke landing after it is caught by the existing createdByDeviceId cascade. Covered in delegated-phone-server-offers.test.ts.
@[REDACTED]moabaKelvin The post-mint check handles the normal cleanup path, but one case remains: if queueRelayDeviceRevoke fails, discardPendingMobilePairingDevice returns without removing the pending row. The caller still receives revoked, but the orphaned credential remains persisted.
[REDACTED]lso, the test revokes the desktop before the late request starts. It does not revoke the phone during address lookup or test a cleanup failure.
Please make the credential unusable when cleanup cannot be queued, while retaining the Relay binding for retry. [REDACTED]dd a regression test for that failure and the in-flight revocation. I’m not marking the finding as addressed. I could not run the tests in this environment.
If you found this review helpful, would you consider giving us a shout-out on X?
A phone reached a server only through its desktop, so closing the lid cut it
off. The phone, still talking through the desktop as its delegated row, can now
ask the server for an ordinary phone pairing chained to that row. The server
never widens its listener for it, copies the row's reach, offers a direct
route only when it already listens off-host, and otherwise mints through its
own Relay. The desktop stamps the phone's own connection mode, so a LAN-only
phone never gets a Relay pairing. Revoking the desktop, or unpairing the phone
on it, revokes the minted pairing through the existing cascade.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Major · Security & Privacy · Heavy lift
Take the phone's connection mode from trusted state, not from request params.
delegatedPhoneServerOffers gates only on scope === 'mobile' and parentDeviceId. The desktop stamps connectionMode only on frames relayed through the desktop. On a direct authenticated socket, a delegated phone can omit connectionMode or send automatic. mintOffer then requests a Relay offer before it checks the address.
The server must take the mode from the authenticated caller's stored state, or reject any request whose mode is not desktop-stamped. A local-only phone must not obtain a Relay pairing through any reachable path. Confirm first that the delegated row stores the phone's mode before choosing the source.
The reason will be displayed to describe this comment to others. Learn more.
Partly. The relayed row's token is held only in the desktop's memory (relayed-phone-socket.ts). Delegated rows refuse key forks and ticket exchange (device-key-fork.ts, pairing-ticket-exchange.ts), so no phone can open a direct socket as that row. The desktop's only forward path stamps the mode (withRelayedPhoneConnectionMode). Delegated rows store no mode of their own, so there is no stored state on the server to read. As hardening, in 771eb4f only an explicit automatic opens Relay; a missing mode now means LAN only.
The reason will be displayed to describe this comment to others. Learn more.
@Amo[REDACTED]Kelvin: Your expl[REDACTED]n[REDACTED]ion [REDACTED]ddresses mos[REDACTED] of [REDACTED]he concern. I h[REDACTED]ve no[REDACTED] verified i[REDACTED] [REDACTED]g[REDACTED]ins[REDACTED] [REDACTED]he code in [REDACTED]his reply, so [REDACTED]he poin[REDACTED]s [REDACTED]elow res[REDACTED] on your descrip[REDACTED]ion.
Re[REDACTED]ch[REDACTED]ili[REDACTED]y: Deleg[REDACTED]ed rows hold [REDACTED]heir [REDACTED]oken only in desk[REDACTED]op memory, [REDACTED]nd [REDACTED]hey refuse key forks [REDACTED]nd [REDACTED]icke[REDACTED] exch[REDACTED]nge. If [REDACTED]h[REDACTED] holds, no phone c[REDACTED]n open [REDACTED] direc[REDACTED] socke[REDACTED] [REDACTED]s [REDACTED] deleg[REDACTED]ed row. The desk[REDACTED]op forw[REDACTED]rd p[REDACTED]h [REDACTED]hen s[REDACTED]mps connec[REDACTED]ionMode on every fr[REDACTED]me, so [REDACTED]he mode is [REDACTED]rus[REDACTED]ed on [REDACTED]he only re[REDACTED]ch[REDACTED]le p[REDACTED]h.
S[REDACTED]ored s[REDACTED]e: The server s[REDACTED]ores no mode for deleg[REDACTED]ed rows, so [REDACTED]here is no[REDACTED]hing [REDACTED]o re[REDACTED]d. T[REDACTED]king [REDACTED]he mode from s[REDACTED]ored s[REDACTED]e is no[REDACTED] possi[REDACTED]le wi[REDACTED]hou[REDACTED] [REDACTED] d[REDACTED] model ch[REDACTED]nge.
H[REDACTED]rdening in 771e[REDACTED]4f8720: Tre[REDACTED]ing [REDACTED] missing mode [REDACTED]s LAN only closes [REDACTED]he g[REDACTED]p I fl[REDACTED]gged. A c[REDACTED]ller [REDACTED]h[REDACTED] omi[REDACTED]s [REDACTED]he mode c[REDACTED]n no longer ge[REDACTED] [REDACTED] Rel[REDACTED]y offer. This is [REDACTED] s[REDACTED]fe def[REDACTED]ul[REDACTED].
One residu[REDACTED]l risk rem[REDACTED]ins. An explici[REDACTED] [REDACTED]u[REDACTED]om[REDACTED]ic s[REDACTED]ill opens Rel[REDACTED]y. If [REDACTED] fu[REDACTED]ure ch[REDACTED]nge [REDACTED]dds [REDACTED] direc[REDACTED] p[REDACTED]h for deleg[REDACTED]ed rows, [REDACTED] c[REDACTED]ller could send [REDACTED]u[REDACTED]om[REDACTED]ic i[REDACTED]self. Bo[REDACTED]h [REDACTED]he rel[REDACTED]yed-phone-socke[REDACTED].[REDACTED]s [REDACTED]oken h[REDACTED]ndling [REDACTED]nd [REDACTED]he refus[REDACTED]ls in device-key-fork.[REDACTED]s [REDACTED]nd p[REDACTED]iring-[REDACTED]icke[REDACTED]-exch[REDACTED]nge.[REDACTED]s [REDACTED]re [REDACTED]herefore securi[REDACTED]y-relev[REDACTED]n[REDACTED] for [REDACTED]his me[REDACTED]hod. A regression [REDACTED]es[REDACTED] [REDACTED]h[REDACTED] [REDACTED] direc[REDACTED]-socke[REDACTED] reques[REDACTED] c[REDACTED]rrying [REDACTED]u[REDACTED]om[REDACTED]ic is refused would gu[REDACTED]rd [REDACTED]h[REDACTED] [REDACTED]ound[REDACTED]ry. I do no[REDACTED] consider i[REDACTED] required for [REDACTED]his PR.
I [REDACTED]m no[REDACTED] m[REDACTED]rking [REDACTED]his [REDACTED]hre[REDACTED]d [REDACTED]s [REDACTED]ddressed. I [REDACTED]m le[REDACTED]ving resolu[REDACTED]ion [REDACTED]o [REDACTED] m[REDACTED]in[REDACTED]iner.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
Your phone reaches the Orca servers your Mac is paired with by going through the Mac, so when the Mac sleeps the phone loses them. This adds the server side of a fix: the phone, still talking through the Mac, can ask a server for a pairing of its own. After the phone confirms it, the phone talks to that server directly, and closing the Mac no longer cuts it off. Unpairing the phone on the Mac, or removing the Mac from the server, still removes that pairing.
What Changed
The new method. A new server method,
pairing.delegatedMobileDevice.createOffer, advertised by the runtime capabilitypairing.delegated-phone-server-offers.v1.parentDeviceId) gets the context. Any other caller getsdelegated_phone_required.workspace: a relayed phone can already open terminals on that server, so this grants nothing new and neverpairing-admin.The offer it mints. An ordinary phone pairing offer:
createdByDeviceIdis the phone's relayed row, so the existing revoke cascade removes the offer, its Relay credential and its push registration when the desktop is revoked on the server, or when the desktop's sync drops the phone.createMobilePairingOffergainsexposure: 'as-bound', which skipsensureNetworkExposure.pinnedListenerAddressrule asorca pair.The desktop's part.
connectionModewith how the phone itself paired with the desktop, so a LAN-only phone never gets a Relay pairing.Smaller changes.
Why
The phone had no credential or route of its own to any server, so every server went through the desktop. The phone deliberately never gets the desktop's delegated token: delegated rows refuse key forks and ticket exchange, and the phone's encryption ends at the desktop. Asking the server for a normal pairing that hangs off the phone's relayed row reuses everything that already exists: offers, Relay invites, pair-confirm on the phone, and the revoke cascade. It adds one method instead of a new credential type.
Rejected alternatives:
Linked Issue
Part of #40079, #27988, #26291 and #10426. The phone's menu item comes in the next PR. #51226 and #51227 made the revocation side reach the server.
Visual Proof
N/A: no UI in this PR. The phone action and its screenshots come in the next PR.
Testing
delegated-phone-server-offers.test.tsruns a realOrcaRuntimeRpcServerthat is unpinned and on loopback, like the desktop app's own server. It covers four cases:127.0.0.1.createdByDeviceId.loopback-pinned-pairing-offer.test.tsstill passes. Typecheck and lint pass.The full phone → desktop → server run is in the next PR, where the phone action lives.
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 the method runs once per tap on the phone and reuses the existing offer pipeline. The relayed-frame rewrite returns early for every other method and reads the phone's connection mode only for this one.
Risk
The riskiest part is pairing authority.
A plain revert removes the method. Pairings already minted stay until revoked.
Level: Medium
AI Disclosure
Review
Agent skill upstream boundary
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. On SSH-managed orcad, which listens only on loopback, the only route is Relay, so the server must be signed in to Orca.
Follow-up: a delegated request still bumps the shared offer generation, so a phone tapping at the same moment the owner mints a Relay QR supersedes the owner's in-flight mint, which then has to be retried. This was already possible between the owner and
orca paircallers.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)