Skip to content

feat(machines): add a PC through the relay with the code it shows - #2952

Merged
devswha merged 5 commits into
mainfrom
lane/issue-2810
Nov 5, 2026
Merged

devswha merged 5 commits into
mainfrom
lane/issue-2810

Conversation

@devswha

@devswha devswha commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

Fixes #2810

What

#2829 added Settings → Remote PCs → Add a PC through the relay, which pairs this PC with another one by its pasted pairing link: no SSH, no open port, no Tailscale, end-to-end encrypted, B's key pinned, revocation on either side ending it, offline/reconnect through the remote-PC backoff, and a phone paired with A seeing B through A. The piece of #2810 still missing was the typed code: a desktop has no camera for the QR code, and copying a link from one PC to another needs some channel between them.

The same row now takes either the link or the ten-character code the other PC shows under Settings → Phone & devices → Show a code to type (#2883):

  1. Type the code, Add PC.
  2. This PC's server finds the other PC through the relay, exactly as the hosted app's code screen does, and answers only that PC's ID and name.
  3. The row asks Does {name}'s screen show this ID? with the ID in eight groups, the same wording and check as the phone's code screen. It matches adds the PC; Cancel goes back.

A pasted link still adds the PC in one step, as before.

How

  • src/lib/relay/pairCode.ts (the device side of the typed-code exchange: one CPace exchange per call, offer key checked against its id, offer must carry a pairing code) moves to shared/relay-code-offer.ts, so the server can run it too (server code may not import src/). pairCode.ts re-exports it, so the hosted app is unchanged. The only code changes in the moved file: the forged-offer check calls deriveServerId(importPublicKey(...)) directly instead of shellState.forgedOffer, the socket type is RelaySocket, and the answer frame is sent as an ArrayBuffer.
  • New POST /api/machines/relay/code { code } → 200 { ticket, server_id, name }, or typed_code_<failure> (not-a-code 400, no-pc 404, wrong 400, expired 410, busy 409, unreachable 502, forged 502). Same guards as every PC change (same origin, X-Herdr-Machine: 1, HTTPS or localhost, watch devices refused).
  • The offer it found holds B's one-time six-digit code, so it never goes back to the browser (src/AGENTS.md: secret input stays in the DOM). MachineManager keeps each found offer in memory under a random 32-byte ticket that only the asking window gets (at most 8, 10 minutes each, B's own pairing-code lifetime); POST /api/machines/relay { found: <ticket> } takes it once. Another client that knows B's public ID gets nothing. The find also stops when its request is aborted.
  • From there addRelay runs unchanged: the pairing, key storage and reconnects are feat(machines): add a PC through the relay, without SSH #2829's.
  • codeFailureText (the code screen's failure sentences) moves out of RelayShell.tsx into src/components/codeFailureText.ts, so both screens word failures the same. Those keys move from the relay dictionary part to the base dictionaries, since two features now use them.

Wire changes (additive)

  • New POST /api/machines/relay/code.
  • POST /api/machines/relay accepts found instead of link.
  • Nothing changes between PCs or on the relay: A is one more typed-code guest, as a phone is.

UI

The design follows GitHub's device sign-in (one screen shows a short code, the other asks for it in a single field), as #2883 does. One input takes a link or a code, so the row stays one control. The ID comparison reuses the phone's wording and KeyId. Screenshots at 390 and 1280, light and dark, from the demo build with the two API answers stubbed in the page: entry row, ID comparison, and a wrong-code message. There is no sideways scroll at either width, and It matches is 44 px tall on the phone.

Validation

  • Failing-first: server/relay-pc.contract.test.ts "finds a PC by the code it shows, keeps its offer while its ID is compared, and adds it once that ID is confirmed" uses two isolated servers (mkdtemp state, port 0) and a local Bun relay. B mints a code, and A checks a non-code (400), a code no PC holds (404), the real code (a ticket, the ID and the name, with no pairing code in the answer), the spent code (404), found set to B's public ID instead of the ticket (400), the ticket (201, connected), and the same ticket again (400). On origin/main's server it fails at its first request (404). With the change, all 4 tests in the file pass.
  • src/components/AddRelayPc.test.tsx: a code goes to /relay/code and leaves the field; the ID shows; It matches posts { found }; a typed_code_wrong answer shows the code screen's sentence; a link still posts { link } in one step.
  • bun test src/lib/i18n.test.ts src/components/conventions.test.ts src/lib/relay src/components/RelayShell.test.tsx shared/relay-pair-code.test.ts server/conventions.test.ts: pass.
  • bun run typecheck: pass.
  • bun run check fast at f8dc4a8 (origin/main merged in), on old-desktop through the heavy runner: workflow syntax, generated types/themes, typecheck, build and unit tests ok (11917 pass, 0 fail, 46 skip).
  • Not run: bun run check full, browser/e2e, native Windows (CI runs them). The changelog fragment of feat(machines): add a PC through the relay, without SSH #2829 (relay-remote-pcs.md, unreleased) is extended rather than adding another.

Not in this PR

Settings > Remote PCs > Add a PC through the relay now also takes the ten-character code the other PC shows under Show a code to type. This PC's server runs the device side of the typed-code exchange (moved to shared/relay-code-offer.ts), keeps the offer it found, and answers only the PC's ID for the person to match before the PC is added.

Fixes #2810
@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 3 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 00421a3 and f796401.

Files selected for processing: 22

  • changelog.d/relay-remote-pcs.md
  • docs/remote-pcs.md
  • server/machine-api.ts
  • server/machines.ts
  • server/relay-pc.contract.test.ts
  • shared/relay-code-offer.ts
  • src/components/AddRelayPc.test.tsx
  • src/components/RelayShell.tsx
  • src/components/SettingsDialog.css
  • src/components/SettingsDialog.tsx
  • src/components/codeFailureText.ts
  • src/lib/api.ts
  • src/lib/i18n.ja.ts
  • src/lib/i18n.ko.ts
  • src/lib/i18n.zh.ts
  • src/lib/i18n/relay.ja.ts
  • src/lib/i18n/relay.ko.ts
  • src/lib/i18n/relay.zh.ts
  • src/lib/i18n/settings.ja.ts
  • src/lib/i18n/settings.ko.ts
  • src/lib/i18n/settings.zh.ts
  • src/lib/relay/pairCode.ts
  • 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

…ng window holds

Another driving client could add the PC by naming its public ID; two windows finding PCs at once undid each other; a find kept running after its request ended.
@devswha

devswha commented Nov 5, 2026

Copy link
Copy Markdown
Owner Author

Review round (Codex terra xhigh, omo)

omo at 2f81440: CLEAR.

Codex at 2f81440, all fixed in f8dc4a8:

  • HIGH (reproduced by reading the guards): the found offer was redeemable by B's public ID, so another driving client (for example a Portal visitor with drive access) could make this PC pair with B after the owner's find, even after Cancel. Fixed: the offer is held under a random 32-byte ticket only the asking window receives; found takes that ticket, once. The contract test now posts B's ID as found and expects 400.
  • MEDIUM: two windows finding PCs at once overwrote each other's held offer. Fixed by the same ticket map (up to 8 at a time, 10 minutes each).
  • LOW: a find kept running after its request ended. The request's abort signal now reaches the exchange, and a find that finishes after shutdown keeps nothing.

Codex re-review at f8dc4a8: the three are fixed; one new LOW, left as is: the ticket is spent before pairing starts, so a pairing that fails (relay down at that moment) needs a new code on the other PC. That is the same one-try-per-code rule the phone's code screen keeps.

bun run check fast at f8dc4a8: ok (11917 pass, 0 fail).

@devswha

devswha commented Nov 5, 2026

Copy link
Copy Markdown
Owner Author

Local merge gate (owner-approved): origin/main merged (clean), bun run check fast passed at this head, omo CLEAR at this exact head, threads resolved; Codex HIGH (offer redeemable by public ID) fixed in the one round. Merged without waiting for GitHub CI.

@devswha
devswha merged commit c024f94 into main Nov 5, 2026
20 of 21 checks passed
@devswha
devswha deleted the lane/issue-2810 branch November 5, 2026 10:53
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.

Relay: add another PC through the Ovis relay, with no SSH, open port or Tailscale

1 participant