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
fix(mobile): send phone unpairing to servers the desktop reaches later - #51227
When you unpair a phone on your Mac, the Mac has to tell every Orca server it relays that phone to, so each server drops the phone too. It used to tell only servers it had talked to since it last started, and only right away: a server that was offline, or any server after a Mac restart, kept the phone. Now the Mac remembers which servers hold its phones and tells each of them as soon as it reaches them again.
Files
Added
Deleted
Net
Test
1
$\color{#1a7f37}{\Huge{\mathbf{+}}}$165
0
$\color{#1a7f37}{\Huge{\mathbf{+}}}$165
Prod
11
$\color{#1a7f37}{\Huge{\mathbf{+}}}$340
$\color{#cf222e}{\Huge{\mathbf{−}}}$43
$\color{#1a7f37}{\Huge{\mathbf{+}}}$297
What Changed
What triggers a re-sync
Any change to the phone list. The device registry's change listener now drives phonesChanged(), so cascade revokes and edits made on disk count too. The explicit call in revokeMobileDevice is gone. The listener is deferred one microtask, because a save announces before the registry holds the saved list, and it is merged so a cascade runs once.
A server coming back into contact. The desktop watches the existing hosts.onStatusChanged and re-syncs a server when it goes from out of contact to in contact. WSL's bulk call, which carries no contact, is ignored.
The registry becoming ready. This catches servers that came into contact before the phone list could be read.
What gets sent
A server gets the new list only if it may still hold a dropped phone. Added phones still sync on their first relayed request, as before. A server that never held this desktop's phones is never contacted.
relayed-phone-servers.json in userData records which servers may hold this desktop's phones, so this survives restarts:
The record is written durably after the server says it can mint phones and before the sync that may mint one. If the write fails, the sync doesn't go out.
It is cleared after an empty sync is answered.
At launch, servers no longer saved on this desktop are pruned from it.
A null or unreadable registry is never sent as an empty list, which would revoke every phone on every server. The sync is refused instead.
Ordering
Syncs to one server go out one at a time, so an older list can never land after a newer one.
One check runs per server. A trigger that arrives during a check runs it once more afterwards.
A phone paired while a sync is in flight re-checks once that sync answers, instead of being refused.
Why
The next PRs in this stack let a phone hold its own pairing with a server, chained to its delegated row there. Unpairing the phone on the desktop then has to reach every server that holds it, including servers that were offline at the time and servers the desktop next reaches after a restart. Otherwise the phone keeps direct access.
Re-syncing every server on each launch would also mint the desktop's phones on servers nobody uses from the phone, such as a teammate's server. It would also wake idle desktops. Recording only the servers that actually hold phones keeps the nothing-to-do case at zero calls and zero writes.
Linked Issue
Part of #40079, #27988, #26291 and #10426. This is the revocation half; the phone's own server pairing comes later in this stack.
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 it. A phone-protocol client was paired to the desktop.
The phone's relayed status.get reached the server. The server minted the delegated row, and the desktop wrote relayed-phone-servers.json with the server's id.
I stopped the server, removed the phone's row from the desktop's registry on disk, then restarted the server. Within 10 seconds the desktop saw the server back in contact, re-synced, and the server's delegated row count went from 1 to 0.
delegated-phone-grant-cache.test.ts runs the real cache over a real record file. It pins four cases:
A phone dropped while the server was unreachable is sent after a restart.
Contact flaps and added phones send nothing.
A phone dropped while the previous removal is still in flight is sent.
An unreadable phone list is never sent, and the check runs once the list is readable.
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
No phones ever relayed: the desktop does no host lists, server resolves, RPCs, writes or timers. It reads one small file at launch, and status events cost one map update each.
Desktop with phones: each server holding its phones gets at most one extra sync per phone removal, and one after a reconnect when a removal is still pending.
Cascades: a cascade of registry saves runs one check.
The record file: it is written only when a server starts or stops holding phones. An unchanged set copies nothing.
Risk
The riskiest parts are the record file and the ordering, because they decide whether a revocation reaches a server.
If the record is lost (deleted or unreadable), a phone unpaired while its server was unreachable stays on that server until the next relayed request or the next phone change. That is today's behaviour.
A failed record write fails that relayed request; the phone retries it.
A plain revert restores the old behaviour. It leaves relayed-phone-servers.json behind, and nothing older reads it.
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
On Windows, WSL hosts that this desktop hasn't started stay recorded: the launch prune compares against every saved server, not just the ones a phone can reach now. Builds on #51226 (merged).
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)
Unpairing a phone re-synced only servers already in the relay's memory, and a
failed sync was never retried, so a server offline at the time, or any server
after a desktop restart, kept the phone's grant. The relay now re-syncs a
server when it comes back into contact, reacts to every registry change
(cascades and disk edits too), sends only when a phone was dropped, and never
sends an unreadable registry's empty list.
No actionable comments were generated in the recent review.
Walkthrough
The relay cache now tracks phone keys sent to each server and persists server IDs that may hold relayed phones. It checks for dropped phones after contact or phone-list changes, and serializes syncs. Phone-list reads distinguish an unreadable registry from an empty list. RPC paths queue relay refreshes, and tests cover restart recovery, sequential removals, and unreadable phone lists.
Merge Risk: Low · up to 54901
Phone unpairing now reaches servers that were offline or contacted after a restart, and unreadable phone lists are refused rather than sent as empty. One narrow ordering gap remains: if a server is retired while a sync is in flight, an older request could arrive after a newer revocation. It is low impact and bounded, so this is mergeable with owner awareness.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: phone unpairing is now sent to servers the desktop reaches later. It uses the fix(mobile) convention. The changeset matches: servers that were offline or reached after…
Description check
The description follows the template. It has ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, Performance, Risk, Level, AI Disclosure, Review, Agent skill boundary, Notes, and Checklist s…
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 names the main change: phone unpairing is now sent to servers the desktop reaches later. It uses the fix(mobile) convention. The changeset matches: servers that were offline or reached after restart now receive revocations via a persisted record of relayed-phone servers and a re-sync on contact.
Full details: Description check
Explanation
The description follows the template. It has ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, Performance, Risk, Level, AI Disclosure, Review, Agent skill boundary, Notes, and Checklist sections. The What Changed, Why, Performance, and Risk sections are detailed and match the code changes. The Linked Issue section cites related issues but uses 'Part of' rather than the template's 'Fixes #', which is acceptable for a stacked PR. The AI Disclosure and Review sections are empty, and the final pnpm checklist item is unchecked. These are minor gaps.
Resolution
Fill in the empty AI Disclosure and Review sections, or mark them N/A. Confirm the unchecked pnpm lint, typecheck, test, and build item before merge.
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; 0 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
⚠️ Outside diff range comments (1)
Minor · Keep per-server sync ordering after a server is retired. · delegated-phone-grant-cache.ts:54
src/main/runtime/mobile-desktop-relay/delegated-phone-grant-cache.ts:54 Minor · Security & Privacy · Quick win
Keep per-server sync ordering after a server is retired.
delete() removes the only record of the last sync to a server. After retirement, sync() starts a new sync without waiting for an older sync that is still in flight. If the older sync sends phones and the newer sync sends an empty list, the older request can arrive last. The server then keeps a phone the desktop has dropped. The newer sync has already cleared the durable record, so a restart does not retry the revocation. This can happen when the environment is retired by transport invalidation or same-ID re-pairing and the server remains configured.
Keep the last sync for each server in a map that delete() does not clear. Chain each new sync behind that entry.
Suggested fix
private readonly entries = new Map<string, GrantsEntry>()
+ // Last sync per server. Kept past delete(), so a later sync still waits for an in-flight one.+ private readonly tails = new Map<string, Promise<unknown>>()
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
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
When you unpair a phone on your Mac, the Mac has to tell every Orca server it relays that phone to, so each server drops the phone too. It used to tell only servers it had talked to since it last started, and only right away: a server that was offline, or any server after a Mac restart, kept the phone. Now the Mac remembers which servers hold its phones and tells each of them as soon as it reaches them again.
What Changed
What triggers a re-sync
phonesChanged(), so cascade revokes and edits made on disk count too. The explicit call inrevokeMobileDeviceis gone. The listener is deferred one microtask, because a save announces before the registry holds the saved list, and it is merged so a cascade runs once.hosts.onStatusChangedand re-syncs a server when it goes from out of contact to in contact. WSL's bulk call, which carries no contact, is ignored.What gets sent
relayed-phone-servers.jsonin userData records which servers may hold this desktop's phones, so this survives restarts:Ordering
Why
The next PRs in this stack let a phone hold its own pairing with a server, chained to its delegated row there. Unpairing the phone on the desktop then has to reach every server that holds it, including servers that were offline at the time and servers the desktop next reaches after a restart. Otherwise the phone keeps direct access.
Re-syncing every server on each launch would also mint the desktop's phones on servers nobody uses from the phone, such as a teammate's server. It would also wake idle desktops. Recording only the servers that actually hold phones keeps the nothing-to-do case at zero calls and zero writes.
Linked Issue
Part of #40079, #27988, #26291 and #10426. This is the revocation half; the phone's own server pairing comes later in this stack.
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 serveprocesses: a server, and a desktop paired to it. A phone-protocol client was paired to the desktop.status.getreached the server. The server minted the delegated row, and the desktop wroterelayed-phone-servers.jsonwith the server's id.delegated-phone-grant-cache.test.tsruns the real cache over a real record file. It pins four cases:A phone dropped while the server was unreachable is sent after a restart.
Contact flaps and added phones send nothing.
A phone dropped while the previous removal is still in flight is sent.
An unreadable phone list is never sent, and the check runs once the list is readable.
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
Risk
The riskiest parts are the record file and the ordering, because they decide whether a revocation reaches a server.
A plain revert restores the old behaviour. It leaves
relayed-phone-servers.jsonbehind, and nothing older reads it.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
On Windows, WSL hosts that this desktop hasn't started stay recorded: the launch prune compares against every saved server, not just the ones a phone can reach now. Builds on #51226 (merged).
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)