Skip to content

fix(pairing): pair a phone with a loopback-only server through Relay - #51211

Merged
AmoabaKelvin merged 5 commits into
mainfrom
fix/pair-mobile-loopback-pinned-relay
Nov 27, 2026
Merged

AmoabaKelvin merged 5 commits into
mainfrom
fix/pair-mobile-loopback-pinned-relay

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

ELI5

An Orca server that only listens on its own machine (127.0.0.1), such as the one Orca installs on an SSH host, refused every orca pair with network_exposure_failed. That included --relay, which doesn't need a network address at all. Now such a server pairs a phone through Orca Relay. When Relay isn't available, it says what's missing.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​83 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​83
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​101 $\color{#cf222e}{\Huge{\mathbf{−}}}$​23 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​78

What Changed

Before, on a server bound to 127.0.0.1 (SSH-managed orcad, or orca serve --bind 127.0.0.1):

  • orca pair --mobile, orca pair --mobile --relay and orca pair all printed Pairing is unavailable (network_exposure_failed). Could not expose the runtime to the network for pairing….

After:

  • orca pair --mobile --relay mints a Relay-only offer. It has no direct endpoint, and the listener stays on 127.0.0.1.
  • orca pair --mobile --relay on a host that isn't signed in prints: Orca Relay needs this host signed in to Orca. Run orca auth login here, then retry.
  • orca pair --mobile (LAN only) prints: This Orca listens only on loopback, so nothing can dial it directly. Give an address that forwards to it, such as a tunnel or SSH port-forward. Or pair the phone through Orca Relay.
  • orca pair --mobile --address 127.0.0.1 (an SSH port-forward) now mints a working offer.
  • A server bound to one network address (--bind 100.64.1.20) now pairs on that address instead of refusing.

Mechanism:

  • ensureNetworkExposure() returns without widening for any pinned bind. Before, it threw for every pinned bind except 0.0.0.0.
  • Which addresses a pinned listener answers on is now decided in one place, pinnedListenerAddress(): none for loopback, and only its own address for a network bind.
    • getPairingNetworkInterfaces(), getDefaultPairingAddress() and the phone's pairing.getDirectEndpoints list all use it.
    • So automatic selection, the pairing window's address picker and the endpoints phones follow all agree.
    • IPv6 spellings are canonicalized first, so ::ffff:127.0.0.1 and 0:0:0:0:0:0:0:1 count as loopback, and an IPv4-mapped wildcard offers IPv4 only.
  • The owner orca pair path turns relay_signed_out, relay_not_entitled and a missing provider into guidance that names the fix. It never suggests LAN to a loopback-only host.

Why

ensureNetworkExposure() threw for any pinned bind because, when orcad gained --bind (#16398), every caller widened the bind so it could advertise a LAN address. Refusing kept unreachable addresses out of QR codes. Relay-only mobile offers came later, and they need no direct route, so that premise stopped holding. Since managed orcad always pins 127.0.0.1, the hand-pairing workaround in #27988 and #40079 couldn't work on it.

The rule against widening a bind the operator chose (STA-2370) still holds: a pinned bind is never rebound. The throw was also doing a second job, keeping unreachable addresses out of offers. That job now sits in address selection, which only offers addresses the pinned listener actually answers. The alternative was to keep the throw and bypass it for Relay offers. That would leave --address port-forwards and network-pinned binds broken, and it would add a second exception path later Relay offers would have to copy.

Linked Issue

#27988, #40079: SSH-managed orcad can now be hand-paired with a phone through Relay. A phone reaching the server with no desktop step at all is still to come.

Visual Proof

N/A: no UI change. The CLI output before and after is in What Changed.

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

On macOS, against a real orcad built from this branch, bound to 127.0.0.1 with its own profile:

  • On main, all of orca pair --mobile, --mobile --relay and plain orca pair returned network_exposure_failed.
  • On this branch, signed out, they print the guidance above. lsof shows the listener still on 127.0.0.1 only.
  • An offer from orca pair --mobile --address 127.0.0.1 was paired by a client speaking the phone's direct E2EE protocol. It authenticated as a mobile device, and status.get answered.
  • A live phone pairing through Relay wasn't run: the scratch server wasn't signed in to an Orca account. The Relay mint path itself is unchanged; the test below drives it with a stubbed provider.
  • Address selection was checked for 127.0.0.1, ::1, ::ffff:127.0.0.1, 0:0:0:0:0:0:0:1, 0.0.0.0, ::, ::ffff:0.0.0.0 and a Tailscale address.

loopback-pinned-pairing-offer.test.ts runs a real OrcaRuntimeRpcServer pinned to 127.0.0.1 with only the Relay provider stubbed. It checks three things: a Relay offer comes back with a null endpoint, a LAN-only offer is refused, and the listener never leaves 127.0.0.1. It fails on main with network_exposure_failed.

Performance

None. Pinned binds now skip the interface scan and route lookup entirely. Unpinned listeners add one string normalization per pairing request or phone endpoint read, and nothing here polls, writes or retries.

Risk

The riskiest part is that a pinned bind no longer refuses pairing. If address selection were wrong, an offer could carry an address the listener doesn't answer, and the phone would fail to connect. Selection now only returns addresses the pinned listener answers, and every loopback spelling was checked. An explicit --address is still advertised as given, as serve --pairing-address already is, because a tunnel or proxy can make any address reach the listener.

The desktop app is never pinned, so its pairing is unchanged. An older host still returns network_exposure_failed to a newer CLI. Nothing changes on the wire or in saved data. A plain revert backs it out.

Level: Low

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

  • Security: no path widens a pinned bind.
  • Remote SSH: this is the SSH-managed path.
  • Mobile: the phone app is unchanged, and Relay-only offers have the same shape the desktop already mints when it has no LAN address. No store build is needed.
  • Cross-platform: address selection is shared code, and the Windows Hyper-V route lookup is skipped for pinned binds.

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 started on a fixed address (SSH-managed orcad, orca serve --bind)
refused every orca pair with network_exposure_failed, even with --relay:
pairing always tried to widen the listener first, and a pinned bind threw.
A pinned bind is now never widened and never an error; offers advertise
only the address it answers, so a loopback pin mints a Relay-only offer.
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

Pairing address selection now distinguishes wildcard, loopback, and other pinned listener addresses. Pairing offers provide listener-specific guidance, including Relay guidance for loopback-bound servers. Network exposure now returns for any pinned bind host. The pull request adds an integration test and updates CLI and remote-server documentation.

Merge Risk: Moderate · up to 045d1

Pairing a loopback-bound server through Relay may produce a link that also carries a loopback direct address. A phone could try that address first, which would make Relay pairing slower or fail. This should be confirmed or fixed before merge; the rest of the change appears sound.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the primary change: pairing a phone with a loopback-only server through Relay. It is specific and matches the changeset, which adds Relay-only offers for 127.0.0.1-pinned binds and rem…
Description check Passed The description follows the template closely. It has ELI5, What Changed (before and after, with mechanism), Why (with alternatives considered), Linked Issue, Visual Proof marked N/A with a reason, Tes…
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 primary change: pairing a phone with a loopback-only server through Relay. It is specific and matches the changeset, which adds Relay-only offers for 127.0.0.1-pinned binds and removes the network_exposure_failed refusal. The 'fix(pairing)' prefix follows a conventional-commit style and is clear.

Full details: Description check

Explanation

The description follows the template closely. It has ELI5, What Changed (before and after, with mechanism), Why (with alternatives considered), Linked Issue, Visual Proof marked N/A with a reason, Testing with manual and automated test details, Performance, Risk with level and revert path, and Notes and Checklist. The AI Disclosure and Review sections are empty, but the template says to skip AI Disclosure for team members, and Review has no required content. The Linked Issue section cites #27988 and #40079 rather than a 'Fixes #' issue, which is a minor template deviation for a maintainer PR.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

LanguageTool

docs/site/content/docs/remote-servers.mdx

LanguageTool could not check every text chunk; analysis is incomplete

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

@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: eac89a00-87cd-4e3c-a453-760445794318
Commits

Reviewing files that changed from the base of the PR and between 61171b3 and 045d195.

Files selected for processing: 7

  • docs/site/content/docs/remote-servers.mdx
  • src/cli/specs/pair.ts
  • src/main/runtime/rpc/server/pairing/loopback-pinned-pairing-offer.test.ts
  • src/main/runtime/rpc/server/pairing/network/pairing-direct-endpoints.ts
  • src/main/runtime/rpc/server/pairing/network/pairing-network-interfaces.ts
  • src/main/runtime/rpc/server/pairing/pairing-offer-requests.ts
  • src/main/runtime/rpc/server/runtime-rpc-network-exposure.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.

@AmoabaKelvin
AmoabaKelvin merged commit 08e4629 into main Nov 27, 2026
63 checks passed
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