Skip to content

fix(account): keep out the devices a client removed on a PC it brings into the account - #2947

Merged
devswha merged 10 commits into
mainfrom
fix/account-enroll
Nov 5, 2026
Merged

devswha merged 10 commits into
mainfrom
fix/account-enroll

Conversation

@devswha

@devswha devswha commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

Fixes #2855 (the add half continues in #2956)

What

When a client links a PC that has no account yet, it now sends that PC the removes it signed itself, verbatim, so the devices it removed from the account stay out there.

  • The client keeps, per device key, the latest record it signed (devices in the ovis-account store): the add for a device it approved, or the remove for one it removed. An older record never overwrites a later one, and a removal wins a tie. Recording an approval and queueing its mailbox delivery happen in one store transaction.
  • After the link, on a session signed in with the account key, and once the PC is in the account's directory, enrollPc posts the client's own removes to /api/account/records. It reads each record's outcome. A record with no answer, or with account_unavailable, is sent again on the next connection, and so is any removal signed while the enrollment ran (checked in the transaction that ends the plan).
  • The client signs nothing for an enrollment, and it takes nothing from a PC: no key from another PC's GET /api/devices (rule 6), and nothing from a PC's status.
  • No add is enrolled yet. An add the client signed may be for a device another member has removed since, and that member's remove does not reach a PC new to the account. Review reproduced this, and no check against a PC's device list was fresh enough to stop it. Adds come together with relaying the account's signed removals in Account: relay the account's signed removals to a PC a client enrolls #2956.

Tests (real servers, src/lib/account/join.test.ts)

  • The new PC tombstones the devices this client removed. It gets no add, not even for a device the client approved, and no key that another PC lists.
  • A device another member removed on X, which this client approved earlier, is not admitted on Y. This test fails against the add-sending code.
  • A PC whose status claims removals gets the client to sign, keep and mail nothing. This test failed against an earlier head, which re-signed those removals.
  • A later signed record is kept over an older one.
  • A removal signed while the enrollment runs keeps the plan open, and the next call tombstones that device.
  • A lost answer, or an account_unavailable outcome, is retried until every outcome is known.

Validation

  • bun test src/lib/account server/account: 106 pass, 0 fail.
  • bun run check fast (old-desktop heavy runner): pass (typecheck, build, unit tests ok).

…tself

A client that links a PC with no account yet now hands it, over a session
signed in with the account key, first the removes it signed and then the
adds it signed for devices it approved itself, with their role. It never
takes a key from another PC's device list. Each record's outcome is read,
and the ones the PC did not answer are sent again on the next connection.
/api/account/status lists the account's removals, so a key another member
removed leaves the client's approved list too.

Fixes #2855
@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 8 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 09a5939 and 0441544.

Files selected for processing: 7

  • changelog.d/account-enroll.md
  • docs/account.md
  • src/lib/account/join.test.ts
  • src/lib/account/join.ts
  • src/lib/account/leave.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

…, finish only what was sent

Review round: an approval and a removal at once could leave neither; a removal
signed while an enrollment ran was dropped; a removal of a device another member
approved was never tombstoned on the new PC; a re-signed removal took the current
time and could undo a later pairing there. /api/account/status now says when
each removal was applied.
A PC this client enrolled before it heard another member removed a device
kept that device. The remove it signs on learning of the removal now goes to
every PC of the account through the mailbox, kept and sent again like an add.
Lead decision after the re-review: the client no longer signs removals from
a PC's unsigned status, so a PC never gains authority over the account. The
status field and the PC side of it are dropped. A new PC gets this client's
own adds and removes verbatim. Approvals and their queue, and the end of an
enrollment with its final check, are each one store transaction; a later
signed record of a device is never overwritten by an older one. The PC is
listed in the directory before it is enrolled, so a later removal reaches it
by mailbox.
…s its key

A device another member removed could come back on the new PC: this client
still held its own older add, and the other member's remove never reaches a
PC that was not in the account yet. An add now goes only while a PC of the
account this client is linked on lists that key as a member; the PC can only
hold an add back.
@devswha

devswha commented Nov 5, 2026

Copy link
Copy Markdown
Owner Author

Review notes (Codex Terra xhigh at decab348, no HIGH). Five MEDIUM findings, kept here rather than as issues: only the third was reproduced, and only with the in-memory store and a PC reset between an enrollment's request and its answer.

  1. An approval in flight can miss the PC just enrolled. An approval that read the account's directory before the new PC was listed, and signs its add after that PC's enrollment ended, sends the add to neither. The device can still be approved on that PC directly.
  2. A carrier reconnect does not retry an unfinished enrollment. The plan stays, but it is retried only on the next shell-level connection to that PC, not when the relay transport reconnects behind the open app.
  3. An old enrollment answer can end a replacement plan. If the PC's account is reset and linked again while an earlier enrollment's answer is still on its way, that answer ends the new plan for the same PC and account.
  4. Switching accounts overwrites another account's record. The client's devices record is keyed by device key only. A client that signs for the same device in two accounts keeps only the later record.
  5. Approvals made before this change are not enrolled. Only records signed from this change on are kept. They cannot be rebuilt from a PC without breaking rule 6.

The account's signed removals reaching a new PC is follow-up #2956. Since 1979bb6d, an add is held back unless another PC of the account still lists its key as a member.

Lead decision after the guard's re-review: an add this client signed may be
for a device another member removed since, and no check against a PC's list
is fresh enough. A PC new to the account now gets only this client's signed
removes, which can only take devices away; adds wait for the account's signed
removals to be relayed too (#2956). The PC-list guard is gone, so no add is
held and no plan stays open.
@devswha devswha changed the title fix(account): enroll a new PC with the devices this client approved itself fix(account): keep out the devices a client removed on a PC it brings into the account Nov 5, 2026
@devswha

devswha commented Nov 5, 2026

Copy link
Copy Markdown
Owner Author

Review at ecb43751 (omo + Codex Terra xhigh): CLEAR, no HIGH. Notes for later, none blocking:

  • MEDIUM: if a device is approved again while its old remove is still on its way to a new PC, that remove can tombstone the device there. This needs a re-approval within one request round-trip.
  • MEDIUM (reproduced in a unit test): the client's devices record is keyed by device key only. A device in two accounts keeps only the later account's record. This is not a regression: main enrolls nothing.
  • Removals made before this change are not kept, so they are not enrolled. Account: relay the account's signed removals to a PC a client enrolls #2956 covers them.
  • LOW: a failed or account_unavailable enrollment is retried on the next shell connection, not on a transport reconnect.
  • LOW: records are ordered by issued_at, so a clock that goes backwards can reorder them.

No follow-up issue was filed: the only reproduced item needs one device key in two accounts, and it leaves things as on main.

@devswha

devswha commented Nov 5, 2026

Copy link
Copy Markdown
Owner Author

Local merge gate (owner-approved): bun run check fast passed at this head, omo CLEAR at this head (Codex Terra xhigh: no HIGH), threads resolved, merges cleanly. Scope narrowed on purpose: a newly linked PC gets only this client's own signed removes, verbatim; adds wait for #2956. Merged without waiting for GitHub CI.

@devswha
devswha merged commit e871149 into main Nov 5, 2026
11 checks passed
@devswha
devswha deleted the fix/account-enroll branch November 5, 2026 11:10
devswha added a commit that referenced this pull request Nov 5, 2026
…ings into the account (#3007)

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 #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.
devswha added a commit that referenced this pull request Nov 6, 2026
…movals are in (#3087)

Part of #2956 (the add half)

## What

A PC that a client brings into the account now gets the account's
devices in one go, instead of
every device asking that PC again. This is the "approve a new PC once"
half of linking by account;
the screens come in a follow-up PR.

**Server (PC)**

- **Enrollment barrier.** The link that gives a PC its first member
writes
`account-enrolling.json` first. Until that member's `POST
/api/account/enroll` succeeds, no
account `add` applies there, from `/api/account/records` or the mailbox
(`refused`, `enrolling`;
mailbox adds wait in `account-pending.json` and are tried again after
the enrollment). A refused link leaves the barrier; the first link that
succeeds keeps it. No timeout: a client that never enrolls leaves the
adds held.
- **Ordered enrollment.** `/api/account/enroll` now takes removes and
adds (at most 512) plus
`held` keys (at most 4096). The PC keeps `held` on disk
(`account-held.json`), applies every
remove first in signing order, then the adds in rounds (an add whose
signer another add lets in
applies in the next round), retrying waiting removes after each round,
then lifts the barrier.
- **Add gates on every path.** An add is refused `removal_pending` while
a waiting remove names its
key (whatever its signer), an enrollment held it, or the waiting queue
is full or cannot be read.
Past 1000 waiting records adds are dropped first; if a remove has to go,
every add is refused from
then on. An unreadable `account-pending.json` is no longer an empty
queue.
- **Status.** `GET /api/account/status` adds `adds` (the signed add
behind each row, kept as
received, including the approver's own add for a row its remote approval
made), `blocked` (every
tombstone key, signed or not, every key a waiting remove names, every
held key) and `enrolling`.
`?fresh=1` pulls the mailbox first (a pull that starts after the
request; requests that come while one runs share the next).
- **Introductions** persist in `account-introductions.json` for 30 days
and merge by PC.

**Client**

- `enrollPc` first reads every other PC of the account it is linked on
(`?fresh=1`, 8 s each). It
then sends one enrollment: its own and kept removes, its own adds and
the adds those PCs list,
minus every key a PC keeps out or a verified removal names (any signer:
fail closed), and those
keys as `held`. It signs nothing for collected records. If no other PC
answers, it sends nothing
  and tries on the next connection.
- Each PC that answered then introduces the new PC to the devices let
in, so they sign in there; an introduction a PC could not take stays in
the plan and is sent again on the next connection.

Design and two rounds of Codex (Terra, xhigh) adversarial design review
are summarised in the
first PR comment. Known, documented limit: a removal held only by PCs
the client cannot reach, and
hidden by the account service, is missed; the device then comes back on
the new PC, announced.

## Tests

`server/account/account.contract.test.ts` (real servers):
- the first link holds every account add (direct and mailbox) until the
member enrolls, across a
  restart, then lets the waiting ones in;
- an enrollment applies removes before adds whatever the order sent, and
adds in rounds;
- a remove waiting for its signer keeps that key's adds out on every
path, and once an enrollment
  lets the signer in the key is removed;
- held keys stay out of every later path, while a device already there
keeps its row;
- the status lists signed adds (incl. an approver's own) and every
blocked key;
- an unreadable pending file, or removes pushed out of a full queue,
hold every add back;
- introductions merge by PC, outlast a restart and expire.

`src/lib/account/join.test.ts`:
- the #2947 Mac repro, "does not let back on the new PC a device another
member removed": with adds
enabled and no other PC read, it fails (Y admits the Mac); with the
client reading X first it
passes, and a copy of the Mac's add arriving later is refused
`removal_pending`;
- devices another PC lists come into the new PC and are introduced to it
there, and sign in;
- with no other PC answering nothing is sent and the PC stays in its
barrier.

Failing-first: each new server test fails with its part reverted (the
`held` gate, the barrier
start on link, the remove-first ordering, keeping the approver's add,
the overflow latch).

Review fixes already in (Codex Terra xhigh on the branch before
opening): a remove waiting on its
signer is kept before the next record of its batch; only the linking
member ends the barrier, with
the last part of its enrollment and every remove decided; `?fresh=1`
reports `fresh` only after a
whole, error-free mailbox read and the client counts only such PCs;
`held_full` latches every add
off; the overflow latch is written before any waiting remove is dropped;
a full queue of waiting
adds no longer holds every add back; the approver hands its add to the
PC that let the device in.

## Validation

- `bun test server/account src/lib/account src/lib/relay
server/state-merge server/relay/pair-sas.contract.test.ts`: 399 pass, 0
fail (head 0c6807d, main merged)
- `bun run check fast` at 0c6807d: pass (workflow syntax, generated
types and themes, typecheck,
  build, unit tests)
- Not run: `bun run check full`, browser regressions (no UI in this PR;
the stacked UI PR #3088 ran
  the relay shell browser QA)
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.

Enroll a new PC with the account devices this client approved itself

1 participant