Skip to content

fix(relay): say why when the relay turns a new device away for the PC's account limit - #3520

Merged
devswha merged 3 commits into
mainfrom
fix/relay-new-device-refused-notice
Nov 10, 2026
Merged

devswha merged 3 commits into
mainfrom
fix/relay-new-device-refused-notice

Conversation

@devswha

@devswha devswha commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

What

The client side of #3484 / #3516. When a PC's relay pass allows no new device sessions, the relay closes a pairing phone or browser 4403. The app showed that as a failed connection.

  • shared/relay-channel.ts: a 4403 close is RelayNewSessionsRefusedError, reported before the secure channel's own close turns it into a lost socket.
  • src/lib/relay/shellState.ts, src/components/relayFailureText.ts: a new failure new-devices-refused with its own title and sentence ("{name} cannot add new devices right now": the account is past its relay limit, devices already added still connect), in en, ko, ja and zh. Try again stays, since the limit can lift.
  • src/lib/relay/transport.ts: the error is fatal for the attempt, so nothing retries it by itself.
  • src/components/AddPcSheet.tsx: the sheet keeps this text after a new PC's Add window closed, as it does for a connection failure.

Independent of #3516: it only reads the close code the relay already sends.

Validation

  • bun run check fast: all ok (unit 14387 pass, 0 fail, 50 skip).
  • New cases in src/lib/relay/channel.test.ts (a 4403 close on a code attempt and on compared digits; another close stays a lost connection) and src/components/AddPcSheet.test.tsx.
  • Browser, on the host (not in the CI runner image; CI's browser jobs run them there): scripts/relay-join-browser-qa.ts passes. scripts/relay-e2e-regression.ts fails in its relay-dashboard-browser-qa.ts part with 5 focus-return cases (keyboard-sheet, details-forget-confirm-*); the same 5 fail on unchanged origin/main (a3d930f) on this host, so they are not from this diff.
  • Skipped: check full.

🤖 Generated with Claude Code

…'s account limit

The relay closes a pairing phone or browser 4403 when the PC's relay pass
allows no new device sessions. The app read that as a lost socket. It is now
its own channel error and its own screen: the account is past its relay limit,
devices already added still connect, and Try again stays. Nothing retries it
by itself.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • New phones and browsers now receive a clear notice when the PC account has reached its relay limit. The notice explains that existing devices can still connect and offers guidance to check account settings or try again later.
    • Added devices continue to connect when the relay limit prevents new devices from being added.
    • The notice includes an available “Try again” option.

The client now recognizes the relay’s new-session refusal as a distinct fatal error. It maps the error to a device-limit notice that explains existing devices can still connect. The notice includes translations and a test for expired add windows.

Changes: Relay refusal notice

Layer / File(s) Summary
Classify and propagate relay refusal
shared/relay-channel.ts, src/lib/relay/channel.ts, src/lib/relay/shellState.ts, src/lib/relay/transport.ts, src/lib/relay/channel.test.ts
The relay close code for refusing new sessions creates a specific error. Failure mapping assigns it new-devices-refused, and transport treats it as fatal. Tests cover this path and confirm a different close code remains mapped to pc-offline.
Display the device-limit notice
src/lib/relayFailureText.ts, src/components/AddPcSheet.tsx, src/components/AddPcSheet.test.tsx, src/lib/i18n/relay.*.ts, changelog.d/relay-new-device-refused-notice.md
The notice explains that the relay limit blocks new devices while previously added devices can connect. The add-device sheet shows this failure even when the add window has expired. Japanese, Korean, and Simplified Chinese translations and a changelog entry are added.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Possibly related issues

Possibly related PRs

  • devswha/ovis#3516 — Adds the PC-to-relay new_session refusal flow that produces the close handled by this PR.
  • devswha/ovis#3345 — Adds relay-pass state used by the refusal flow that this PR handles.
Merge Risk: Minimal · previous review 8bec6

The client can explain a relay refusal, but bundled PCs do not yet trigger that refusal. No merge-blocking regression was identified.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title clearly identifies the relay refusal behavior and the PC account limit. It is concise enough to describe the main change.
Docstring Coverage Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentati…
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.
Description check Passed The description explains the change and resulting behavior, links the related issues, and lists validation results, added tests, browser QA, known baseline failures, and skipped checks. It does not st…
Full details: Docstring Coverage

Explanation

Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 11 files. (1 skipped: 1 unsupported.)

Full details: Description check

Explanation

The description explains the change and resulting behavior, links the related issues, and lists validation results, added tests, browser QA, known baseline failures, and skipped checks. It does not state whether WebSocket contract tests were run or skipped, as the template requires for WebSocket changes.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • 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

Commits

Reviewing files that changed from the base of the PR and between a3d930f and 8bec6bc.

Files selected for processing: 12

  • changelog.d/relay-new-device-refused-notice.md
  • shared/relay-channel.ts
  • src/components/AddPcSheet.test.tsx
  • src/components/AddPcSheet.tsx
  • src/components/relayFailureText.ts
  • src/lib/i18n/relay.ja.ts
  • src/lib/i18n/relay.ko.ts
  • src/lib/i18n/relay.zh.ts
  • src/lib/relay/channel.test.ts
  • src/lib/relay/channel.ts
  • src/lib/relay/shellState.ts
  • src/lib/relay/transport.ts

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

devswha and others added 2 commits November 10, 2026 16:21
… refusal

Review of this PR (Opus and Codex, reproduced): any 4403 close was the fatal
new-device refusal, also from a direct carrier's address and to a sign-in. A
paired device whose saved direct address answered with another host closing
4403 lost the relay race and was told the PC takes no new devices.

The relay sends it only to a device that is pairing, over the relay, so only
there is it read that way; the direct race no longer ends on it. The Add-a-PC
sheet marks the approval step as failed, since the digits were confirmed before
the refusal. The misplaced doc comment is back on its class.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@devswha
devswha merged commit 14fd7dc into main Nov 10, 2026
21 checks passed
@devswha

devswha commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head e079ac13422d as 14fd7dcd6e05 on GitHub's checks, with no unresolved review threads.

Reviewer Verdict Note
claude CLEAR
codex CLEAR

Merged with these checks red, none of them required: ssh;

  • Reviewers: a Claude agent (Opus 5.5) and Codex Terra 6.1 (team proxy). Round one at 8bec6bc: both reproduced a MEDIUM (any 4403 close, also from a direct carrier's address or to a sign-in, ended the relay race and told a paired device the PC takes no new devices). The merge pass fixed it on the branch in e079ac1 (the PR's session was gone); both CLEAR at that head, and Opus reran the direct-race reproduction against it.
  • LOW (Codex), not fixed: a 4403 before the relay assigned the connection, on a pairing, still reads as the account limit and does not fall back to the other relay.
  • Takes effect only once feat(relay): a PC names a new device to the relay when its pass allows no new sessions #3516 ships and the relay enforces passes; nothing sends 4403 in production today.
  • CodeRabbit did not review this head.

@devswha
devswha deleted the fix/relay-new-device-refused-notice branch November 10, 2026 07:59
devswha added a commit that referenced this pull request Nov 10, 2026
…s no new sessions (#3516)

## What
The PC side of #3484. Closes #3489, and item 1 of #3495.

While its relay enforces passes and the pass the PC holds says `new` 0
(account limits), a PC now names a client to the relay
(`{"type":"new_session","connection_id":"…"}` on its proven control
socket) once a pairing on that client's session would make a device new
to the PC. The relay then closes the client `4403`.

- **When a client counts as a new device** (`server/relay/session.ts`,
`server/devices.ts`): a pairing code that holds (`pairRelay`), or a
comparison of digits both people confirmed (`pairRelayApproved`), with a
public key no device of this PC holds. The device store asks an `admit`
callback last, after every other check, before it makes the device. A
refusal makes no device, spends no code and counts no failed pairing.
- **Known devices**: `AUTH` never asks, so a paired device signs in as
before, on a new socket too, and open sessions stay. A paired device
that pairs again with the key it saved is not asked about either
(below).
- **Nothing before identification**: a client that only knows the
`server_id` (connected, greeted, a wrong code, a comparison nobody
approved) gets what it got before, and nothing is sent on the control
socket for it.
- **The PC refuses too** (`server/relay/link.ts`): the session answers
nothing more, and the link closes the client's data socket after 2 s
should the relay not have closed the client.
- **Knowing that passes are enforced** (`relay/pass.ts`): `sync` said
`state` and `enforce_at`, which do not tell `enforce` from `grace` (an
enforcing relay may name a far `enforce_at`). `relay_pass` now also
carries the configured `mode`. A PC counts a relay as enforcing when
`mode` is `enforce` or `enforce_at` has passed; a relay that names no
mode enforces only past its `enforce_at`.

## Changes since the two reviews
Reviewed at ad89f36 by Opus and Codex (both `CLEAR` with findings).
`origin/main` is merged in (it now holds #3520 and #3535, which edits
`server/relay/service.ts` and `session.ts` too: no conflict); the fixes
are two new commits, no rebase.

1. **A phone the PC already knows that pairs again was named and cut
off** (Opus, MEDIUM). A re-scan of the QR, or "Forget this PC" and
pairing again while signed in, sends PAIR with the saved key.
`pairRelay` and `pairRelayApproved` now ask `admit` only for a key no
device row holds (`isNewKey`). The trade-off is in the code comment and
`docs/relay.md`: PAIR does not prove the key, so someone holding a
pairing that would succeed who names a paired device's public key gets
that pairing's session past the limit; it cannot sign in with the key
afterwards, so each further session takes another pairing that succeeds
(on a PC in no account, a code that session started itself).
2. **The PC owner saw no notice while new devices were refused** on a
relay in `enforce` with no `enforce_at` or a far one (Opus, MEDIUM).
**Contract change:** `RelayStatus.pass` (`GET /api/relay`, and `relay`
in `/api/health`) gains `enforced: boolean`: the relay enforces passes
now, as the PC knows it (its last `sync` said `enforce`, or an
`enforce_at` that has passed by the PC's clock, or it refused the PC for
its pass). Additive: an older client ignores it, and a client reading an
older server (no `enforced`) keeps the date rule.
`relayNoticeFromStatus` shows the data-limit notice when `new_sessions
=== false`, `enforced === true` and the PC is not refused, whatever the
date, and shows none while the PC says passes are not enforced.
3. **Codex's three MEDIUMs**, each judged against the code:
- *Pairing allowed while the relay still enforces an expired local
pass*: real. The keeper stops returning a pass 5 minutes before it runs
out (`current()`), the relay honors it until 5 minutes after, and a
phone already on a data socket could finish pairing in between when no
renewal came. `RelayPassKeeper.honored()` now gives that pass until the
relay stops honoring it (timed from receipt, like `current()`), the link
reads it (`honoredPass`) for what it says of new sessions, and it is
never sent. The link no longer compares the pass's `exp` with the PC's
own clock, which also settles the "PC clock ahead" part.
`pass.new_sessions` in the status follows the same pass.
- *A renewal can leave the PC and the relay enforcing different
restrictions*: half real. The relay refuses only whom the PC names, so
the pass the PC holds decides: a relay still holding an older or
stricter pass (a renewal it dropped, or its same-second rule) refuses
nobody by itself, and the PC's pass is the account service's later word.
What is real is the other direction: the PC refuses on a pass the relay
does not hold, so the relay drops `new_session` and the client gets the
PC's own close (`1012`) instead of `4403`, until the next renewal 12
hours later. The cause, a renewal within the relay's one-a-minute rule
being dropped unanswered, is fixed on the PC: a renewal that follows
another within the minute waits (65 s after the one before) and then
carries the pass held by then, and a pass that came while a control
socket was still being let in goes out once that socket is proven. An
acknowledged renewal (Codex's suggestion) is a relay protocol change and
is not in this PR.
- *A refused device is told the PC is offline*: fixed on the client by
#3520 (merged), which reads the `4403` close and shows "{PC} cannot add
new devices right now". A device the PC had to close by itself (the 2 s
fallback) still reads as a lost connection.
4. **Tests for the PC-only paths** (Opus, LOW), in
`server/relay/link.test.ts` against a relay of the test's own: the 2 s
close of the data socket when the relay closes nobody, the same with the
control socket lost, a relay that names no mode before and past its
`enforce_at`. A pass past its expiry is the keeper's to time now, so
that case is in `server/relay/pass.test.ts` (`honored()`), and end to
end in the contract test.

## Deploying: the relay first
`relay/` deploys apart from the app. Merging this starts the Relay
deploy workflow (the PR touches `relay/pass.ts`), which waits for the
maintainer's approval in the `production` environment and drops every
socket once (PCs and clients reconnect). The regional relay
(`relay-ap.ovis.sh`) runs its own copy of `relay/` and needs the same
update. Nothing was deployed and no relay setting was changed for this
PR: production stays as it is.

- **Order**: either order breaks nothing, since `relay_pass.mode` and
`new_session` are additions an older side ignores. For the limit to
work, the relays deploy **first**: before the app release whose PCs name
clients (0.5.3), and before passes are switched to `enforce`.
- **An old PC on the new relay**: it does not read `mode` and never
sends `new_session`, so the relay refuses nobody for new sessions on its
behalf, as today.
- **A new PC on an old relay** (no `mode` in `sync`): the PC reads it as
enforcing only past its `enforce_at`. In `enforce` with no date or one
still ahead it names nobody, so the limit is not applied (as today).
Past the date it names the client: a relay with #3484 closes it `4403`,
one from before drops the frame and the PC closes the client itself
after 2 s (`1012` to the client).

Release: this changes `server/` and `shared/`, so the release guards
will ask for a raised `REMOTE_BUNDLE_VERSION`.

## Not in this PR
- An account member who approves a join remotely still waits out
`/api/account/introduce` (2 minutes) when the join was refused for the
limit (Opus, LOW).
- A device added through account records (`POST /api/account/records`,
the mailbox) and then signing in with `AUTH` is a known device here, as
#3489 scopes it; it is a way around the limit for an account whose PCs
hold different `new` values (Opus, LOW; for #3495).
- Items 2 to 4 of #3495 (relay side), and a relay that acknowledges the
pass it holds.

## Validation
- `bun run check fast` at the pushed head (50b7395, with `origin/main`
at 12bd687 merged in): all ok (workflow syntax, generated types and
themes, typecheck, build, unit tests: 14454 pass, 0 fail, 50 skip in 877
files).
- `bun test server/relay/ server/devices.test.ts` at the same head (the
relay's unit and contract tests, on the isolated test herdr session):
382 pass, 0 fail. `relay/` and `src/components/RelayNotice.test.tsx` ran
within `check fast`.
- Each new test fails without its fix (run against the unfixed code):
`server/devices.test.ts` (a paired key pairs again unasked, by code and
by compared digits; a revoked key is new again),
`src/components/RelayNotice.test.tsx` (`enforced`),
`server/relay/pass.test.ts` (`honored()`), `server/relay/link.test.ts`
(a pass no longer sent still refuses, no pass honored names nobody,
renewals a minute apart, a pass that came during the proof), and two
cases in `server/relay/new-session.contract.test.ts` against a real Bun
relay (a known phone pairs again and gets in; a phone that finishes
pairing in the pass's last minutes is closed `4403`).
- The other new `link.test.ts` cases cover what the first commit added
and no test reached: the 2 s close, the same with the control socket
lost, and a relay without `mode` before and past its `enforce_at`.
- Test fixtures made deterministic: the new-session contract fixture
starts the PC on a saved pass, and the pass contract fixture issues
every pass at one instant. A PC that an enforcing relay refuses at the
door asks for its pass twice, and whether the second went out as a
renewal was a matter of timing; the relay takes one renewal a minute, so
a test's own renewal could be the one dropped (before this change) or
held back (after it).
- An independent review of the fixes (a fresh agent, read only) found no
defect in the production code; its two points (the pass fixture above,
and the wording of the known-key trade-off) are in.
- Skipped: `check full`, the browser regressions (the only client change
is the rule in `src/lib/relayNotice.ts`, covered by its unit test; no
component changed), a run against a deployed relay, Windows and macOS.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5.2 <[email protected]>
devswha added a commit that referenced this pull request Nov 10, 2026
The branch carried an earlier copy of #3520's RelayNewSessionsRefusedError,
which the merge of main left declared twice.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
devswha added a commit that referenced this pull request Nov 10, 2026
…3545)

Stacked on #3543: merge that first;
this PR's base is its branch.

It also contains #3520 (`fix/relay-new-device-refused-notice`, merged in
as 1c574c4), because both edit the failed case of the Add-a-PC sheet.
Until #3520 merges, this PR's diff shows its commit too; whichever of
the two merges first, the other no longer conflicts on those lines.

## What
In the hosted app's Add-a-PC sheet, a refusal or a timeout was a dead
end with the wrong explanation.

- Adding a new PC whose add window had lapsed (or whose Ovis restarted)
read "Add window closed · an account member must approve" and offered
only Close. A new PC has no member, and nothing could be pressed.
- A join showed the pairing link's texts ("Copy a new link on the PC",
"Open the link again"), although a join has no link and is never
approved on the PC.
- The join sheet's subtitle and every listed PC past ten minutes
(Overview, the PC table, Details) said "Add window closed · an account
member must approve".

Now:
- New PC, stopped waiting: "{name} stopped waiting to be added", with
where to press on the PC (Settings → Devices and PCs → Account → Add
this PC to my account), a note that it pauses after too many tries, and
**Try again**.
- New PC, declined or not approved in 90 seconds: says to try again and
press Approve on the PC, with **Try again**.
- Join refused before any number was shown: "{name} cannot take this
device yet": the PC may not know this device yet (it learns the
account's devices within a few minutes) or is paused; wait and try
again, or pair by QR or code if no device of the account uses the PC.
**Try again**.
- Join nobody approved: "No device of your account approved this one",
open the PC in Ovis on a device that already uses it, keep it open,
**Try again**.
- The join sheet says before the press that a device of the account
connected to the PC approves, and to open the PC there first. The sheet
with no PC selected says where to add the PC to the account.
- A listed PC past its window reads "Join · a device of your account
connected to it approves", only where a Join button stands beside it.
- #3520's "cannot add new devices right now" text is unchanged in both
flows.

## How
- `relayFailureText(t, failure, name, detail, flow?)` takes the sheet's
flow (`"new" | "join"`). Without a flow the texts are the pairing
link's, as before. Only `pair-unavailable` and `pair-declined` differ
per flow.
- `AddPcSheet` passes its mode as the flow; the `expiredWindowFailure`
rewrite and its two strings are gone.
- `askToJoinReason(pc, t)` in `relayPcState.tsx` is the one home of the
past-window line and of its condition (`added_at` set and a `join`
route); it returns null otherwise. Overview, the table and Details call
it.
- ko/ja/zh entries added in `relay.*` and `dashboard.*`; entries of
deleted strings removed. Changelog fragment
`changelog.d/shell-add-pc-failures.md`.

Differences from the plan's brief, on purpose:
- The brief's join + `pair-unavailable` copy ("No device of your account
is connected to {name} to approve it…") names a cause that never
produces this failure: with nobody connected the PC shows digits and
times out, which is `pair-declined`. `pair-unavailable` in a join comes
from `accountJoin` refusing (`server/relay/session.ts:394-403`: the PC's
mailbox has not admitted the key yet, the 5-joins-a-minute cap), the
pairing pause, or a serve-only PC. The copy now names those. Its last
sentence no longer sends the user to "Add this PC to my account", a
button a PC already in an account does not show.
- The brief's label "Ask to join · …" named a button the dashboard does
not have (the row's button is "Join"; "Ask to join" is inside the
sheet). It reads "Join · …".

## Review
- Medium, conflicts with #3520 and no `new-devices-refused` test:
resolved. #3520's head is merged in; this PR's side of the failed case
is kept, #3520's "Add window closed" assertion is dropped, and a test
pins that `new-devices-refused` equals the flowless text for flow "new"
and "join" and that the sheet shows its title with Try again.
- Low, the Overview reason ignored `pc.join`: resolved. The condition
moved into `askToJoinReason`; a listed row without a route reads "Needs
approval" in all three places. New Overview test for a listed row
without `join`.
- Low, join + `pair-unavailable` copy names a cause that cannot occur:
resolved with new wording (above), checked against
`server/relay/session.ts`. The new + `pair-unavailable` copy gained one
sentence for the pause. The "open it on a device that uses it" advice
stays for `pair-declined`, where it is true. The wording is a maintainer
call; say so if you want other words.
- Low, the reason said "Ask to join" beside a "Join" button: resolved,
the line starts with "Join".

## Validation
- `bun run check fast` (TMPDIR under `~/.cache/ovis-tmp`, through the
queue) at 01e015c: every step ok (workflow syntax, generated types and
themes fresh, typecheck, build, unit tests, conventions).
- `bun test src/components/AddPcSheet.test.tsx
src/components/RelayOverview.test.tsx
src/components/RelayPcTable.test.tsx
src/components/RelayPcDetails.test.tsx`: 58 pass.
- `bun run check run bun scripts/relay-shell-browser-qa.ts` on this host
(not in the CI runner image): the shell part passed, including the
account add and the account join past the window; the dashboard matrix
it runs last ended 58 PASS, 5 FAIL: `keyboard-sheet` and the four
`details-forget-confirm-*` (focus not given back after a sheet or a
confirm closes). The same two checks
(`ONLY='^(keyboard-sheet|details-forget-confirm-1440-dark)'` with
`scripts/relay-dashboard-browser-qa.ts`) fail identically on the base
branch `fix/shell-empty-dashboard` without this PR's commits, so they
are not from this diff; this diff changes no focus code.
- No script in `scripts/*-regression.ts` or `scripts/*-qa.ts` names the
changed components or asserts the changed strings.
- NOT run: the browser QA inside the CI runner image, GitHub's jobs
(Integration and browser, Native Windows install), a real device, and a
real two-device join against a real PC.

Needs a real review: the merged-in #3520 changes a relay contract (close
code 4403 → `new-devices-refused`) and gets its review there; this PR's
own commits are wording, a retry flag and a label condition in the
hosted shell, and change no pairing, admission or wire code.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5.2 <[email protected]>
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