Skip to content

fix(account): a PC reads its mailbox when a device of its account it does not know yet signs in - #3537

Merged
devswha merged 4 commits into
mainfrom
fix/account-pull-unknown-device
Nov 10, 2026
Merged

devswha merged 4 commits into
mainfrom
fix/account-pull-unknown-device

Conversation

@devswha

@devswha devswha commented Nov 10, 2026

Copy link
Copy Markdown
Owner

What

When a member approves a new device on one PC, the approver leaves a signed add in the mailbox of the account's other PCs, and the new device learns those PCs right away. But a PC read its mailbox only at start and every five minutes, so the device's sign-in there ended in auth_failed ("{name} has not added this device yet … Try again in a moment.") for up to five minutes.

Now a PC in an account reads its mailbox when a sign-in fails, applies what it finds as in any other pull, and checks the sign-in once more. A device whose add is waiting is let in on its first sign-in. A sign-in that still fails gets the same auth_failed as before, with no new field or code.

Limits a user can meet: such sign-ins start at most one pull a minute. A device that signs in before its add reached the mailbox, or just after another failed sign-in spent that pull, is still told to try again and gets in up to a minute later (before: up to five).

How

  • server/account/mailbox.ts: pullForRefusedSignIn(waitMs, now). Returns at once on a PC in no account, joins a pull under way, otherwise starts one on a count of its own (SIGN_IN_PULL_MS, 60 s, apart from the admitted() count joins use) and waits at most SIGN_IN_WAIT_MS (5 s). A pull that ended with an error gives the minute back: the next may start SIGN_IN_PULL_RETRY_MS (10 s) after it began, also when it failed after the sign-in stopped waiting.
  • server/relay/session.ts: before the AUTH check, on a PC in an account, the sign-in is verified; if it does not hold, the setup deadline is extended (as accountJoin does), the pull is awaited, and the normal check runs. A sign-in that holds calls nothing. PAIR and PAIR_REQUEST are untouched, as are records.ts, the join path and the client.
  • docs/account.md and a changelog.d/ fragment.

Differences from the plan's brief:

Release: this changes server/, so the release must consider REMOTE_BUNDLE_VERSION (not bumped here).

Review

An independent reviewer read the first commit (verdict: fix, then ship).

  1. Medium, a failed or late pull spent the minute, locking a waiting device out for 60 s: fixed. A pull that ends with an error lets the next start 10 s after it began; two tests fail without it.
  2. Low, the first sign-in can come before the add is in the mailbox, and that empty pull spends the minute: real, kept as a limit. The one-a-minute count is the security guard's number (each pull is two calls against the account service's per-address limit), so it was not widened to a burst here; the changelog and docs no longer say "at once" and state the up-to-a-minute wait. A small burst is a follow-up for the maintainer to decide.
  3. Low, the delay told known ids from unknown ones: fixed by taking the same way for every failed sign-in (above), with a test. What remains: the delay still tells a PC in an account (the refusal may wait for the pull) from one in none, once a minute; documented in docs/account.md.
  4. Low, process, feat(relay): a PC names a new device to the relay when its pass allows no new sessions #3516 still open and the branch behind main: origin/main (0.5.2) is merged in. feat(relay): a PC names a new device to the relay when its pass allows no new sessions #3516 was not waited for, since this run opens the PR; instead its head (ad89f36) was merged into this branch in a throwaway worktree: the merge is clean, and there server/account/account.contract.test.ts (95 pass), every server/relay/*.test.ts file (run one by one, all pass, new-session.contract.test.ts included) and bun run typecheck pass. Whichever of the two merges second should rerun those files on the result.

Validation

Ran:

  • bun run check fast on this branch with origin/main merged in: every line ok.
  • bun test server/account/account.contract.test.ts: 95 pass (5 new or changed tests: the added device signs in on its first try; one pull a minute and the same auth_failed with and without it; a member's own sign-in reads nothing and a bad signature for a known id takes the unknown id's way; a PC in no account never calls the service; a tombstoned key stays out after the pull; the wait is bounded and joins a pull under way; a failed pull gives the minute back, also when it fails late).
  • The same file, each server/relay/*.test.ts file and bun run typecheck on a local trial merge with feat(relay): a PC names a new device to the relay when its pass allows no new sessions #3516's head.

Not run:

  • bun run check full, the integration suite as a whole and the browser regressions (no rendered component changes).
  • A real account service, a real relay or a real second device: the tests use shared/account-service-fake.ts, mkdtempSync state dirs and port: 0.
  • GitHub's Windows and macOS jobs.

Needs a real review: this changes relay sign-in (authentication). An unauthenticated peer that knows a PC's server_id can now make that PC call the account service, at most once a minute (once every 10 s while the service fails).

🤖 Generated with Claude Code

devswha and others added 4 commits November 10, 2026 14:10
…does not know yet signs in

A member who approves a new device on one PC leaves a signed add in the mailbox of the
account's other PCs, but a PC read its mailbox only at start and every five minutes, so the
device's sign-in there ended in auth_failed until the next pull.

A sign-in naming a device the PC has no row for now makes a PC in an account read its mailbox
first: it joins a pull under way or starts one, at most once a minute on a count of its own
(apart from the one account joins use), and waits at most five seconds. The sign-in is then
checked as before, so a device still unknown gets the same auth_failed, and records are
verified and applied as in any other pull. A PC in no account, and a sign-in for a device the
PC already knows, call nothing.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…refused sign-in takes the same way

Review follow-ups to the pull a refused sign-in asks for.

A pull that could not read the mailbox (the account service was down or did not answer) spent the
one-a-minute count, so a device whose add was waiting stayed out for the whole minute. Such a pull
found nothing out: the next may now start 10 seconds after it began, also when it failed after the
sign-in stopped waiting for it.

Whether the pull ran depended on the claimed id having a row here, so the refusal's delay told an
unauthenticated peer which ids a PC knows. The sign-in is now checked first, and any failed one on
a PC in an account, an unknown id or a signature that does not hold, asks for the same pull and is
checked once more; a sign-in that holds calls nothing.

The docs and the changelog entry no longer say "at once": a device that asks before its add is in
the mailbox may wait up to a minute.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The refused sign-in's pull is decided in one line ahead of the sign-in's own check, which stays as
it was, so the open change to that check (#3516) merges without a conflict. A sign-in that holds
on a PC in an account is verified there and again by the check.

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

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • When sign-in fails on a PC linked to an account, the system can check for updated device approvals and retry automatically.
    • If approval arrives after the check begins, the device may need to try signing in again later. Checks are limited to once per minute, with a shorter retry interval after a failed check.
  • Documentation
    • Updated account sign-in documentation to describe the mailbox check, retry behavior, and timing limits.

For account-backed PCs, refused AUTH attempts can trigger or join a mailbox pull before device matching. Pulls use cooldown and retry timing, and sign-in waits are bounded. The change adds contract tests and updates account documentation and the changelog.

Changes: Account sign-in mailbox pulls

Layer / File(s) Summary
Mailbox pull policy
server/account/mailbox.ts, server/account/account.contract.test.ts
AccountMailbox adds sign-in pull cooldowns, retry timing after errors, and a default wait timeout. Tests cover active-pull joining, failed reads, retry timing, and pull timing state.
AUTH admission and behavior
server/relay/session.ts, server/account/account.contract.test.ts, docs/account.md, changelog.d/account-pull-unknown-device.md
RelaySession checks account devices before AUTH admission and pulls the mailbox when the device match fails. Tests cover sign-in outcomes, including unknown devices, invalid signatures, and mailbox-delivered changes. Documentation describes the retry path and its timing.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Merge Risk: Minimal · up to 7852b

The sign-in change is mergeable after normal checks. Account-backed PCs may take longer to refuse a sign-in, as documented.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title clearly summarizes the main change: an account PC reads its mailbox when an unknown device signs in. It is specific and related to the changeset.
Description check Passed The description explains the problem, resulting behavior, implementation, risks, and validation. It includes a Validation section with checks run and skipped. The change is described under “What” rath…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
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: Description check

Explanation

The description explains the problem, resulting behavior, implementation, risks, and validation. It includes a Validation section with checks run and skipped. The change is described under “What” rather than the template’s “Change” heading, and it does not link an issue where a maintainer agreed to the feature.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. 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 0 functions across 3 files. (2 skipped: 2 unsupported.)

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 1bc8fa6 and 7852b58.

Files selected for processing: 5

  • changelog.d/account-pull-unknown-device.md
  • docs/account.md
  • server/account/account.contract.test.ts
  • server/account/mailbox.ts
  • server/relay/session.ts

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

@devswha
devswha merged commit 695af54 into main Nov 10, 2026
21 checks passed
@devswha

devswha commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head 7852b5878f79 as 695af54a72be 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), both CLEAR at 7852b58. Opus checked that pulls stay bounded (one a minute per PC, one every 10 s after a failed pull), that a removed key is not admitted by the pull's timing, and that the refusal text is unchanged.
  • LOW, reproduced, not fixed: a 429 from the account service also gives the minute back, so refused sign-ins keep the PC asking every 10 s against the service's Retry-After (mailbox.ts:212). Give it back only for a network error or 5xx.
  • LOW, reproduced: the refusal's delay shows an unauthenticated peer that another pull is under way; docs/account.md should say so.

@devswha
devswha deleted the fix/account-pull-unknown-device branch November 10, 2026 07:06
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