Skip to content

fix(account): relay the account's signed removals to a PC a client brings into the account - #3007

Merged
devswha merged 2 commits into
mainfrom
fix/account-relay-signed-removes
Nov 5, 2026
Merged

devswha merged 2 commits into
mainfrom
fix/account-relay-signed-removes

Conversation

@devswha

@devswha devswha commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

Part of #2956

What

A PC that a client links into the account for the first time now also tombstones devices that another member removed, when the client has seen that removal on another PC. The client never signs anything for these removals: it passes them on verbatim.

  • PC keeps the signed record with its tombstone. removeAccountKey stores each verified remove with the tombstone in account-tombstones.json, as received. It keeps one per signer, at most 8, so a PC where only a later signer is a member can still apply one. A Revoke on the PC stores none. When two state dirs share a device list, their tombstones merge with every signer's record.
  • GET /api/account/status lists them as removals, parsed again on read. A damaged record is dropped.
  • The client keeps only removals it can check. On each connection to a PC of its account, keepRemovals keeps, verbatim, each listed removal that verifies, is for its account, and is signed by its own key or by a device it approved itself (an add it signed). At most 256 are kept. A tampered PC cannot make it keep a removal signed by a key the PC made up, and it never signs one.
  • enrollPc relays them. It sends the client's own removes plus the kept ones through /api/account/records and reads every outcome, as before.
  • A relayed removal can wait for its signer. When the signer is not yet a member of the new PC (signer_not_member), the PC puts the removal in its existing account-pending.json queue, which retries it on every mailbox pull. Only an account member's session can do this. Once the signer joins, for example by a remote approval, the key is tombstoned. A pairing made on that PC after the removal was signed is left alone (existing issued_at rule).

What this does not do: adds stay disabled

This PR does not do the issue's "then enroll the client's own adds" step, so it says "Part of", not "Fixes". A Codex (Terra, xhigh) design review found that no read of the PCs a client can reach proves it holds every removal of the account. A removal can wait in the unread mailbox of a PC that is off, or exist only on PCs the client has no pairing with. An add the client signed earlier could then let a removed device into the new PC.

I reproduced this. Turning adds on in enrollPc makes the existing test "does not let back on the new PC a device another member removed" fail: Y admits the removed Mac. A known gap in device admission is not acceptable, so the new PC keeps admitting the account's devices by approval. Each device asks once and compares digits. docs/account.md explains why.

Tests (real servers)

  • server/account/account.contract.test.ts
    • A removal's signed record stays with its tombstone and is listed in the status, verbatim, after a restart too. A second signer's record is kept beside it, and a damaged one is dropped.
    • Merging two state dirs keeps both signers' records.
  • src/lib/account/join.test.ts
    • Another member's removal is relayed to the new PC as signed. It waits there for its signer, then tombstones the key, and Y lists the very record (same signature and issued_at).
    • A pairing made on the new PC after that removal was signed is left as it is.
    • No removal the client cannot check is kept or relayed: unsigned, forged, another account's, or signed by a key it never approved.
    • The existing fix(account): keep out the devices a client removed on a PC it brings into the account #2947 tests still pass, including "does not let back on the new PC a device another member removed".

Failing-first: each new test fails with its part of the change reverted. Without the PC-side wait, the relay test fails at isTombstoned. Without the signer check, the "cannot check" test fails. With server/devices.ts from main, the status test fails because removals is undefined.

Validation

  • bun test server/account src/lib/account server/device-access.contract.test.ts: 152 pass, 0 fail (head a99de96)
  • bun run check fast (old-desktop heavy runner, head a99de96): pass (workflow syntax, generated types/themes, typecheck, build, unit tests)
  • Review round (omo + Codex Terra xhigh) and how each finding was resolved: see the PR comment.

…ings into the account

A PC now keeps the signed remove records with each account tombstone (one per
signer, at most 8) and lists them in GET /api/account/status. A client keeps,
verbatim, the ones that verify, are for its account and are signed by its own
key or by a device it approved, and enrollPc relays them to a PC it links into
the account. A relayed remove whose signer is not a member there yet waits in
the PC's account-pending queue and applies once that signer joins.

Adds stay out of the enrollment: no client can know it holds every removal of
the account, so an add it signed could let a device another member removed into
the new PC. Devices of the account join such a PC by approval.

Part of #2956
@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 21 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 b01e5e1 and a99de96.

Files selected for processing: 11

  • changelog.d/account-relay-removals.md
  • docs/account.md
  • server/account/account.contract.test.ts
  • server/account/mailbox.ts
  • server/account/records.ts
  • server/account/routes.ts
  • server/devices.ts
  • src/lib/account/join.test.ts
  • src/lib/account/join.ts
  • src/lib/account/store.ts
  • src/lib/relay/shell.tsx
  • 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

…t, in signed order

Review round (Codex, omo):
- A relayed removal never evicts a record that already waits: the PC takes no
  more once 1000 wait, and drops exact duplicates.
- Records a pull is retrying stay on disk when a client relays one meanwhile.
- A client relays removals in the order they were signed, so a member's
  removal comes after the removals that member signed.
- keepRemovals reads past its cap, so records that do not check cannot crowd
  out ones that do.
- A relayed removal is written to disk before it counts as waiting.
- A client still keeps removals a device signed before this client removed it.
- A tombstone file whose records are not a list is refused like any damaged one.
- docs/account.md names what relaying does not cover.
@devswha

devswha commented Nov 5, 2026

Copy link
Copy Markdown
Owner Author

Review round (omo + Codex Terra xhigh) and how each finding was resolved

CodeRabbit did not review this PR: it hit its review limit.

Fixed in a99de96

  • HIGH (omo, reproduced; Codex): wait() during a pull overwrote account-pending.json without the records the pull had taken out to retry. The queue a pull holds is now a field, and wait() writes both lists. Test: "a relayed removal waiting on its signer is kept beside the mailbox's, never in place of one, and on disk while a pull retries them" (fails on the previous head).
  • HIGH (Codex): a member could push real waiting removals out of the queue with junk ones. A relayed record never evicts one any more: none is taken once 1000 wait, and exact duplicates are dropped. Same test.
  • HIGH (Codex): removal order. A client's own removal of member M could be applied before M's earlier removal of D. Removals are now relayed in the order they were signed. Test: "relays removals in the order they were signed..." (fails on the previous head).
  • MEDIUM (omo): once the client removed signer B, B's earlier valid removals were no longer kept. A removal signed by a device this client removed is kept if it was signed before that removal. Test: "still keeps the removals a device signed before this phone removed it, and none it signed after" (fails on the previous head).
  • MEDIUM (omo): wait() updated memory before the disk write. It now writes first.
  • LOW/MEDIUM (omo, Codex): entries that fail the check could crowd out valid ones before the 256 cap. keepRemovals now reads up to 4x the cap.
  • LOW (omo): a hand-edited records that is not an array now makes the tombstone file unreadable, like any damaged one (fail-closed), instead of throwing later.

Not changed, written in docs/account.md ("Relayed removals are best effort")

  • MEDIUM (Codex): a PC from before this PR drops a relayed removal whose signer is not its member yet. Not a regression: before this PR nothing was relayed.
  • MEDIUM (Codex): removals a client learns after it enrolled a PC are not relayed to that PC.
  • MEDIUM (Codex): the caps (8 signers per tombstone, 1000 waiting records, 256 kept per client).
  • HIGH (Codex): an old removal replayed into a new PC also takes a row a remote approval made there. This is the existing documented rule ("A row an add or a remote approval made goes, however late the remove arrives"), the same as for mailbox records; this PR does not change it. The removal is genuine and signed by a member.

None of these admits a device: adds stay out of the enrollment (#2956).

@devswha

devswha commented Nov 5, 2026

Copy link
Copy Markdown
Owner Author

Re-review at a99de96: CLEAR (omo + Codex Terra xhigh)

No HIGH. The remaining findings are unreproduced. None of them is a regression: on main, no other member's removal reaches a new PC at all. They stay open as gaps in a best-effort feature, and no device is admitted by any of them because adds stay out of the enrollment:

  • MEDIUM: sending removals in signed order does not make them apply in that order. If B removed C and this client later removed B, then on the new PC B's removal of C waits for B, and B is tombstoned right away.
  • MEDIUM: with 1000 records already waiting on a PC, wait() drops a relayed removal, while the client still counts signer_not_member as final.
  • MEDIUM: one record per signer keeps the first removal by that signer, not the latest.
  • LOW: a member session can fill the waiting queue with removals signed by keys it made up. The mailbox's own records are kept ahead of them, and a member can already remove devices outright.
  • LOW: /api/account/status lists the public keys of removed devices and their signers to drive callers.
  • LOW: the client keeps no new removal past 256.

The caps and best-effort scope are documented in docs/account.md ("Relayed removals are best effort").

@devswha

devswha commented Nov 5, 2026

Copy link
Copy Markdown
Owner Author

Local merge gate (owner-approved): required checks green (Fast, Integration, Native Windows); bun run check fast passed; omo re-review CLEAR at this head after one fix round (omo's reproduced HIGH wait() race and Codex HIGHs fixed with failing-first tests); threads resolved. Device admission change: Codex Terra xhigh design review before code; CodeRabbit was rate-limited, so the omo + Codex reviews stand in. Fail-closed by decision: PCs keep signed removes and clients relay them verbatim to a newly linked PC; automatic add enrollment stays disabled (docs say why). The red ui-regression job (tab-menu-regression.ts:49) fails identically on main. Part of #2956.

@devswha
devswha merged commit 81cdd28 into main Nov 5, 2026
22 of 26 checks passed
@devswha
devswha deleted the fix/account-relay-signed-removes branch November 5, 2026 14:48
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