Skip to content

fix(mobile): follow a paired desktop's new LAN address after it changes - #50032

Merged
AmoabaKelvin merged 8 commits into
mainfrom
refresh-direct-endpoint-48680
Nov 26, 2026
Merged

AmoabaKelvin merged 8 commits into
mainfrom
refresh-direct-endpoint-48680

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

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.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​68 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​68
Prod 16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​514 $\color{#cf222e}{\Huge{\mathbf{−}}}$​40 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​474

What Changed

Before: HostProfile.endpoint was 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:

  • Desktop: a new phone-only RPC, pairing.getDirectEndpoints, returns every direct endpoint the live WebSocket listener answers on. These are the addresses from getPairingNetworkInterfaces, formatted with the same resolveAdvertisedPairingEndpoint as the QR, at the actual bound port, in QR preference order.
    • It is empty for a loopback-only listener, and returns just the bound endpoint for a pinned specific-IP bind.
    • Interfaces are read fresh on every call. Only the Windows Hyper-V default-route lookup (a PowerShell spawn) is cached for 30 s, with one shared in-flight promise.
    • It is on the paired-desktop allowlist with pairing-admin, so delegated phones and other paired desktops can't call it.
  • Phone: the native endpoint lifecycle asks on each foreground connected edge and foreground nudge.
    • A saved row gets directEndpointOrigin: 'host' the first time the desktop lists its endpoint. Edit Host sets 'manual'.
    • For a '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.
    • The supervisor's return probes read the saved endpoint through getters, so they follow the move without dropping the Relay session. The existing hysteresis still decides when to switch back to direct.

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.getEndpoints was 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:

  • "While on Relay, switch to the desktop's current auto-pick" breaks phones that work today. If Tailscale is installed on the desktop only, the auto-pick becomes 100.x, the phone rewrites to an address it can't reach, and it stops going direct at home.
  • Saving an address only because the desktop lists it strands the row when an address leaves for a moment (Wi-Fi reconnect, Tailscale restart) or when a multi-homed desktop lists one the phone can't reach.
  • So the desktop decides "this is no longer mine", and the phone decides "I can reach the new one". Tunnels, custom pairing addresses and Edit Host values are never 'host', so they are never rewritten.
  • Carrying the list on status.get was rejected: a phone's status.get can 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

  • 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

Checks run on macOS:

  • Desktop, live: a hidden worktree orca serve --serve-mobile-pairing on 0.0.0.0:6871, called over a real E2EE phone-protocol socket.
    • pairing.getDirectEndpoints returned ["ws://100.94.41.14:6871","ws://192.168.1.251:6871"]. The LAN entry matches the QR's endpoint string byte for byte.
    • After restarting the serve on 6872 it returned only the :6872 addresses.
    • An unknown pairing method comes back forbidden, which is the older-desktop path the phone treats as "stop asking".
  • Phone logic, live: the real follower, logical client, DirectRpcClient, probe helper and host persistence ran against that serve. AsyncStorage was held in memory, and an authenticated socket labelled relay stood in for the Relay leg.
    • Saved row ws://192.168.1.251:6871 (origin host): a direct dial to it fails.
    • The desktop lists :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.
    • When the replacement can't be reached, the saved row stays :6871.
  • Real iOS app (simulator): today's 0.0.71 release build, with its JS bundle swapped for this branch's Hermes bundle.
    • It paired with the worktree serve and connected.
    • The saved row gained "directEndpointOrigin":"host" after the first answer.
    • With the final bundle it reconnected with the row unchanged.
  • Not tested: a real Orca Relay session end to end, because no local relay exists and it needs a signed-in desktop. Windows and Linux desktops were not run. The Windows path reuses the existing route lookup.
  • Automated: mobile/src/host-catalog/host-direct-endpoint-refresh.test.ts covers the rule and the persistence compare-and-swap with real storage code:
    • only a same-kind, nearest replacement is offered;
    • a still-listed address is kept;
    • Tailscale is never swapped for LAN;
    • unknown-origin and Edit Host rows are never overwritten.
    • It fails with the rule stubbed out.
  • Gates: pnpm check:changed passes (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.

  • Desktop: one 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.
  • Phone: one small RPC per foreground connected edge or foreground nudge. Rows that can't follow (manual, unknown) stop asking after one answer, and nothing runs in the background or on a timer.
    • The first answer seeds from the in-memory settled host list instead of rereading storage.
    • A verification dial runs only when the desktop no longer lists the saved endpoint, at most once a minute per candidate.
    • Storage is written once to mark origin and once per actual address move.
  • A perf pass priced this at fleet scale: 120 unchanged refreshes per client caused zero dials and zero storage reads or writes.

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:

  • A rewrite requires that the desktop no longer lists the old address, that the row was once listed by the desktop, and that the phone authenticated at the new address with the desktop's pinned key.
  • Edit Host values and tunnels are never touched.

Mixed versions: an old phone never calls the method. A new phone on an old desktop gets forbidden and 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

  • 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

  • Security: mobile-scope authenticated sockets only, never delegated phones. Replacements must pass E2EE auth with the pinned key.
  • Cross-platform: wildcard, pinned and loopback binds are handled, and IPv6 addresses are bracketed the way the QR does it.
  • SSH/remote: the method is answered by the paired desktop and never forwarded.
  • Mobile web page: no-op storage stubs, and the page never runs the lifecycle.

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)

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.
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The desktop now provides its current direct endpoints through pairing RPC. The mobile app selects eligible replacements, verifies them with a direct probe, and saves successful updates for host-owned profiles. Manual endpoints remain unchanged. The mobile connection lifecycle uses the follower’s current endpoint and manages follower refresh and cancellation.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 08f87 · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the mobile app now follows a paired desktop's new LAN address after the address changes. The changeset adds a phone-only direct-endpoints RPC, a host-owned endpoint fo…
Linked Issues check Passed [#48680] Requirement: a paired phone must refresh a stale desktop direct endpoint after the desktop address changes, using the desktop's current auto-advertised address, without overwriting manual edi…
Out of Scope Changes check Passed All listed changes connect to the endpoint refresh objective. The desktop RPC, its contract, reader, and allowlist entry expose the endpoint list. runtime-rpc-socket-pairing-context.ts and `runtime-…
Description check Passed The description follows the template closely: ELI5, What Changed, Why, Linked Issue (Fixes #48680), Visual Proof (N/A with reason), Testing with platforms and live runs, Performance, Risk with level M…
Full details: Title check

Explanation

The title names the main change: the mobile app now follows a paired desktop's new LAN address after the address changes. The changeset adds a phone-only direct-endpoints RPC, a host-owned endpoint follower, and compare-and-swap endpoint persistence, all of which serve that goal. The title uses the conventional fix(mobile) prefix and is specific, and it does not include file lists or vague wording. Its scope is LAN-focused, while the changeset also handles Tailscale endpoints. That is a minor omission and does not make the title misleading.

Full details: Linked Issues check

Explanation

[#48680] Requirement: a paired phone must refresh a stale desktop direct endpoint after the desktop address changes, using the desktop's current auto-advertised address, without overwriting manual edits, and with attention to older phone and desktop compatibility. Implementation in the reviewed diff: (1) Desktop: new phone-only pairing.getDirectEndpoints RPC (pairing-direct-endpoints-contract.ts, pairing.ts, pairing-direct-endpoints.ts) lists endpoints from the live listener, formatted with resolveAdvertisedPairingEndpoint. It is on the paired-desktop allowlist. (2) Phone: host-direct-endpoint-refresh.ts and host-direct-endpoint-follower.ts replace a saved endpoint only when its origin is host, the desktop no longer lists it, and a same-kind replacement authenticates with the pinned key. host-store.ts marks Edit Host values manual, so they are not rewritten. (3) Compatibility: the new method is separate from the strict pairing.getEndpoints result. Older desktops return forbidden, and the phone then keeps its current behavior. The issue's reproduction is a connected phone whose saved address is stale. The PR covers the Relay-connected case the issue describes. Limitation, not a gap in the stated requirement: a local-only phone with no working path cannot ask, as the PR states. Evidence is the PR summary, the described automated tests, and the stated live checks. I did not inspect code with tools in this assessment. Unverified: exact test contents and the excluded generated RPC catalog.

Full details: Out of Scope Changes check

Explanation

All listed changes connect to the endpoint refresh objective. The desktop RPC, its contract, reader, and allowlist entry expose the endpoint list. runtime-rpc-socket-pairing-context.ts and runtime-rpc-websocket-dispatch.ts route the method to the socket-bound pairing context, replacing inline context, which is needed to pass pairingDirectEndpoints. RpcContext and dispatcher-stream-options carry the new callback. On the phone, host-profile.ts adds the origin field, host-direct-endpoint-persistence.ts holds the compare-and-swap writes, and the follower and lifecycle use the saved endpoint through getters. The web stubs match the native persistence module. The test file covers the rule. No change was found that is unrelated to #48680. Not inspected with tools: the ignored generated file src/shared/rpc-contract/rpc-params-catalog.generated.ts. It is excluded and does not appear to define behavior for this objective.

Full details: Description check

Explanation

The description follows the template closely: ELI5, What Changed, Why, Linked Issue (Fixes #48680), Visual Proof (N/A with reason), Testing with platforms and live runs, Performance, Risk with level Medium and back-out plan, Review, and Notes. The AI Disclosure section is empty, but the template says to fill it in only for non-StablyAI team members. The author's checklist leaves the lint, typecheck, test, and build item unchecked, but the item allows CI to cover it. The description is thorough and specific.

  • 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: 75643db1-2265-4dd5-8da7-71bab30cd303
Commits

Reviewing files that changed from the base of the PR and between dc43999 and 08f87d0.

Files ignored due to path filters: 1

  • src/shared/rpc-contract/rpc-params-catalog.generated.ts is excluded by !**/*.generated.*
Files selected for processing: 16

  • mobile/src/host-catalog/host-direct-endpoint-persistence.ts
  • mobile/src/host-catalog/host-direct-endpoint-persistence.web.ts
  • mobile/src/host-catalog/host-direct-endpoint-refresh.test.ts
  • mobile/src/host-catalog/host-direct-endpoint-refresh.ts
  • mobile/src/host-catalog/host-profile.ts
  • mobile/src/host-catalog/host-store.ts
  • mobile/src/transport/connection/host-direct-endpoint-follower.ts
  • mobile/src/transport/connection/mobile-endpoint-lifecycle.ts
  • src/main/runtime/rpc/core.ts
  • src/main/runtime/rpc/dispatch/dispatcher-stream-options.ts
  • src/main/runtime/rpc/methods/pairing/pairing.ts
  • src/main/runtime/rpc/server/pairing/network/pairing-direct-endpoints.ts
  • src/main/runtime/rpc/server/runtime-rpc-mobile-paired-desktop-methods.ts
  • src/main/runtime/rpc/server/runtime-rpc-socket-pairing-context.ts
  • src/main/runtime/rpc/server/runtime-rpc-websocket-dispatch.ts
  • src/shared/remote-runtime/pairing/pairing-direct-endpoints-contract.ts

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

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]: Mobile never refreshes a paired desktop's direct endpoint after the desktop's address changes

1 participant