Repository navigation
fix(mobile): follow a paired desktop's new LAN address after it changes - #50032
Conversation
The phone kept the desktop's LAN endpoint from the pairing QR forever, so a DHCP renew, adapter switch or port fallback left it dialing a dead address and stuck on Relay. The desktop now lists its current direct endpoints over a new pairing.getDirectEndpoints call, and the phone rewrites its saved endpoint only when the desktop no longer lists it and the endpoint was once one of the desktop's own. Endpoints typed in Edit Host are never rewritten.
…s it A desktop address that leaves for a moment (Wi-Fi reconnect, Tailscale restart) must not strand the saved row elsewhere, so the replacement is dialed in memory and saved only when a direct connection authenticates there, never across LAN and Tailscale. Edit Host saves always mark the endpoint as the user's, a refresh requested during a cutover is replayed, and steady-state answers no longer reread the host catalog.
The desktop now lists every address its listener answers on and caches only the Windows route lookup, so a moved or returning address shows at once. The phone asks again on each return-probe dial, skips background reconnects, stops asking for rows it can never change, and seeds from the settled host list instead of rereading storage.
Prefer the replacement that shares the most address segments with the old one, so a VPN or second NIC listed first does not win over a DHCP move. A failed return-probe dial now tries the other of replacement and saved endpoint instead of asking the desktop on every dial, and a refresh queued while backgrounded waits for the next foreground.
Only a final dial failure tries the other endpoint, a network arrival resets dialing to the desktop's current address, and one save of a verified replacement runs at a time.
Return probes went back to dialing only the saved endpoint. When the desktop no longer lists it, the follower dials the desktop's replacement once, saves it only if this phone authenticates there, and retries a miss at most once a minute or on a new connection. This drops the probe-time alternation and its ordering cases.
…sconnects A verification dial is aborted when the app backgrounds or the host client stops, rechecks foreground before dialing, and a miss from an older connection no longer blocks the retry a new connection allows.
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
ELI5
The phone remembers your desktop's local network address from the moment you paired. When the desktop's address changes (a new DHCP lease, switching between Wi-Fi and Ethernet, a different port), the phone kept trying the old address forever and stayed on Relay. Now the phone asks the desktop where it can be reached. If the desktop says the old address is no longer one of its own, the phone tries the new one, and switches to it only once it actually reaches the desktop there.
What Changed
Before:
HostProfile.endpointwas written only by pairing and by Edit Host. After a desktop address change, every return probe dialed the dead address, so the phone stayed on Relay (or showed the host offline when Relay also failed) until you re-paired or typed the address by hand.After:
pairing.getDirectEndpoints, returns every direct endpoint the live WebSocket listener answers on. These are the addresses fromgetPairingNetworkInterfaces, formatted with the sameresolveAdvertisedPairingEndpointas the QR, at the actual bound port, in QR preference order.pairing-admin, so delegated phones and other paired desktops can't call it.connectededge and foreground nudge.directEndpointOrigin: 'host'the first time the desktop lists its endpoint. Edit Host sets'manual'.'host'row whose endpoint the desktop no longer lists, the phone picks the nearest replacement of the same kind (LAN or Tailscale, never across) and dials it once. It saves the new address (a compare-and-swap in the host-list mutation queue) only if that dial authenticates against the desktop's pinned key.Why
Root cause: the desktop is the only one who knows its current addresses, but nothing told an already-paired phone. The phone treated the pairing-time QR snapshot as permanent.
Why the assumption held: Relay (#8536) carried connectivity when the direct address died, and Edit Host (#8294) was the manual escape hatch.
pairing.getEndpointswas built for relay routing only, and its result is.strict()on shipped phones, so it can't carry a new field. That is why this adds a separate method.Why this design over the alternatives:
100.x, the phone rewrites to an address it can't reach, and it stops going direct at home.'host', so they are never rewritten.status.getwas rejected: a phone'sstatus.getcan be routed to an execution host other than the paired desktop.Linked Issue
Fixes #48680
Related: #15491 (a port move strands a direct-only pairing). This PR follows a moved port only for phones that still have a path to the desktop (Relay). A local-only phone whose only address died has no way to ask.
Visual Proof
N/A: nothing on screen changes. This is connection routing and saved host data. The live runs under Testing show the before and after on real processes.
Testing
Checks run on macOS:
orca serve --serve-mobile-pairingon0.0.0.0:6871, called over a real E2EE phone-protocol socket.pairing.getDirectEndpointsreturned["ws://100.94.41.14:6871","ws://192.168.1.251:6871"]. The LAN entry matches the QR's endpoint string byte for byte.6872it returned only the:6872addresses.forbidden, which is the older-desktop path the phone treats as "stop asking".DirectRpcClient, probe helper and host persistence ran against that serve. AsyncStorage was held in memory, and an authenticated socket labelledrelaystood in for the Relay leg.ws://192.168.1.251:6871(originhost): a direct dial to it fails.:6872, the follower's own dial authenticates there, and the row becomes{"endpoint":"ws://192.168.1.251:6872","origin":"host"}. Return probes then dial:6872.:6871."directEndpointOrigin":"host"after the first answer.mobile/src/host-catalog/host-direct-endpoint-refresh.test.tscovers the rule and the persistence compare-and-swap with real storage code:pnpm check:changedpasses (32 checks). Also passing:check:react-doctor:changed, the mobile tests typecheck ratchet and the focused vitest files.Performance
None material, because the method only runs in response to phone connection events, and the unchanged case does no further work.
os.networkInterfaces()per call (about 0.05 ms measured with 12 adapters). The Windows Hyper-V route lookup is shared and cached, so it runs at most twice a minute per desktop and never when no phone connects.manual, unknown) stop asking after one answer, and nothing runs in the background or on a timer.Risk
Level: Medium
The riskiest part is rewriting a saved host endpoint automatically. If it went wrong, the phone would dial a wrong address and stay on Relay, which is today's behavior after a move. Three things bound that risk:
Mixed versions: an old phone never calls the method. A new phone on an old desktop gets
forbiddenand keeps today's behavior. The result schema is not strict, so later fields won't break shipped phones.Known limitation: downgrading the phone to an older build drops
directEndpointOrigin, so after upgrading again an Edit Host value that equals a desktop address can be followed. Even then it is replaced only after the phone reached the new one.Back out with a plain revert. Rows keep a harmless optional field that older code strips.
AI Disclosure
Review
Several review rounds (Codex, Claude and a fleet-scale perf pass) shaped this. The main design changes were saving a replacement only after a verified dial, never crossing LAN and Tailscale, picking the nearest replacement, and cancelling verification on background or stop. The final scoped round came back with no findings.
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)