~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

Any number of accounts, each with a did:plc and its own storage

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/monolith:accounts

The server holds any number of accounts. Each has a did:plc registered at a PLC directory, its own signing key, and its own repository log. There are sessions by handle, email or DID; writes across accounts are refused; and one firehose sequence covers every account.

Spec.

  • spec/ACCOUNTS.md (new):
    • the environment;
    • createAccount's checks in the reference's order: lexicon, password length (in UTF-16 units), email (required, then its form), the handle rules, handle taken, email taken, did, then inviteCode;
    • the PLC genesis operation;
    • sessions;
    • writes to another account (401 AuthenticationRequired; a repo no one has stays 403 AccountNotFound);
    • accounts without a password, which keep no email.
  • PDS.md, COMMANDS.md: multi-account wording. An omitted required repo/did means the token's account.
  • Vendored:
    • the createAccount lexicon;
    • atproto/did-plc.md, from did-method-plc (MIT or Apache-2.0);
    • data/reserved-handles.txt, 1,029 names from @atproto/pds (MIT).

Every rule was probed on the reference. Gaps found while building went back into the spec as rules, again probed: an empty password counts as none, createSession's answer, the password-less email rule, the email grammar, the password units, and that a repo handle is matched exactly as given.

Harness.

  • Setup: neither side starts with an account. Both register DIDs with dev-env's PLC directory, our server with the reference's recovery key.
  • State: kept per account. Each repository is verified against the signing key in its PLC document. DIDs are normalised to <did:n> by creation order.
  • New steps:
    • createAccount: every new account's didDoc and genesis operation are checked on both sides, the reference included;
    • refusals, with one to three faults at once, which tests the check order;
    • the same-handle race;
    • createSession by every identifier;
    • writes across accounts;
    • with --commands, calls with repo left out.
  • Updated for many accounts: the firehose checks (one sequence; each new account's four events) and the crash checks (accounts, sessions and every repository survive).

Server.

  • Storage:
    • accounts.log, service-wide: accounts and sessions, with scrypt password hashes;
    • repos/<did>/repo.log, one per account: its commits with their events.
  • Concurrency: writes take only their own account's lock, with group commit and the fsync outside the lock. Events reach the firehose only once they and every earlier event are on disk.
  • Recovery: accounts are replayed, then every repository in parallel, each checked against its head. Event order comes from a recorded ord.
  • New module: plc.rs builds and signs the genesis operation and derives the DID, as did-plc.md says.

The checks bite. Two bugs planted in the server, each caught:

  • no cross-account check: seed 1 fails at step 23, a write with another account's token answered 200 where the reference says 401;
  • rotationKeys reversed: seed 1 fails at step 0, on the first account's genesis operation.

The first harness run also caught 5 real differences between our server and the reference, all now fixed: 4 emails the reference accepts (a@b.c, a@b.c1, ü@x.io, a@ü.io), and a 129-emoji password, which the reference counts as 258 units.

The gates caught one more difference. With did given, a handle outside the server's domains is an external one that must resolve to that DID, so the reference answers 400 InvalidRequest, not UnsupportedDomain. I probed it on the reference, made it a spec rule, and fixed the server.

Checked: just gates: all 15 harness runs, conformance, and every crate's tests pass. One crash run reaches about 50 accounts.

🤖 Generated with Claude Code

Asked for changes

This pull lets the server hold any number of accounts. Each gets a did:plc registered with the PLC directory, its own signing key and its own repo.log. Sessions work by handle, email or DID, and cross-account writes are refused. One firehose sequence covers every account.

Spec. ACCOUNTS.md is thorough, and PDS.md and COMMANDS.md are updated to match. One behaviour change is not in the spec. spec/DURABILITY.md was not touched and still lists only "records and commits, firehose events, and the sessions it gave out" as surviving a restart. Now the accounts themselves, each with its handle, email, password hash and signing key, must survive a kill and a restart, and so must every repository, each checked against its head. The crash checks verify this. The service-wide event order surviving a restart (the recorded ord) is also not stated. Please add both to DURABILITY.md, and mention accounts in its list of what survives. Per review.md, behaviour belongs in the spec as well as the code.

What I checked and found fine.

  • Dependencies: the new crates (bs58, scrypt, reqwest) are not atproto or MCP crates, and they are declared in the workspace Cargo.toml.
  • README.md: the Known gaps list says what is built and what is not, with no history in it.
  • plc.rs and createAccount: the genesis operation matches ACCOUNTS.md. The check order in createAccount matches it as well.
  • Harness and conformance: I did not read the harness changes in detail. conformance.yaml is not in the diff, so no excuse was added.

Not read. I did not read the diffs of log.rs, repo.rs, events.rs, lib.rs, sync.rs or the harness files, so I have no finding on locking, group commit or recovery.

Done in efadaf1: DURABILITY.md now says what survives a restart.

  • What survives: the accounts, each with its DID, handle, email, password and signing key; every account's records and commits; every account's firehose events; and the sessions.
  • Answered: an account createAccount has answered survives a kill, like an answered write.
  • Killed mid-create: an account the server is killed while creating either exists whole when it serves again, with its first commit and that commit's events, or doesn't exist at all.
  • Event order: an event the firehose has sent keeps its seq and its place among every account's events. After a restart, any cursor replays the same events in the same order, and new events are numbered after them.

The --crash-every paragraph now lists what the crash runs check: accounts and sessions, the write in flight, every account's repository, and the stream from the last event with --firehose.

Spec text only; no code changed.

Approved

My earlier review asked for spec/DURABILITY.md to say that accounts and the service-wide event order survive a restart. The change since then does that:

  • The list of what survives now names accounts with their DID, handle, email, password and signing key, every account's commits, and every account's events.
  • A createAccount that was answered must survive a kill. An account being created when the server is killed exists whole afterwards, or not at all.
  • An event keeps its seq and its place among all accounts' events, and new events are numbered after it.
  • The crash-check description now covers accounts and each repository.

I still did not read the diffs of the Rust storage code or the harness, as I said before. So I have no finding on locking, group commit or recovery, and none on the harness changes.

The merge queue ejected this because one CI run failed: plain seed 4, step 286. A plain createAccount got 500 from our server where the reference made the account. A 500 here means the PLC request failed, and CI doesn't keep the server's stderr, so I don't know which error it was. Eight parallel runs of seed 4 pass locally.

The likely cause is a keep-alive race:

  • dev-env's PLC is a Node HTTP server, which closes idle connections after 5s;
  • reqwest reuses idle pooled connections for up to 90s;
  • a create more than 5s after the last one can reuse a connection the PLC is closing, and fail in transit.

A new test with a stub that closes reused connections shows the failure mode. The exact race didn't reproduce, so this is not proven to be what failed in CI.

Fix (0922543, plc.rs):

  • No idle connections are kept for the PLC.
  • Timeouts: 5s to connect, 15s per request.
  • Lost POST: the server first reads the DID. The DID is the hash of that exact operation, so a document there means it landed. Only if none is there is the operation reposted, once.
  • The DID-document GET is retried once on a transport error.
  • Logging: a failed POST names its cause on stderr.

Two new tests cover a POST lost before the stub took the operation, and one lost after.

Checked: cargo test (25 in pds-server), and plain seeds 1–5 plus --commands seeds 31–32 against the fixed server.

Approved

My approval at efadaf1 stands. Since then the change touches only how the server talks to the PLC directory in plc.rs, plus a one-line use of it in log.rs.

  • Client: it keeps no idle connection and has connect and request timeouts. This fixes a request failing on a connection the directory had just closed.
  • Registration: a post that fails on its way is settled by asking the directory for the DID document. A document means the operation was taken. None means it was not, so posting again is still the first genesis, because the DID is the hash of this operation. The reasoning holds.
  • Tests: the stub directory covers both lost-request and lost-answer cases, and checks that a client with a pool does fail where this one does not.

This adds no observable behaviour that needs a spec page, adds no new crates, and touches no harness or conformance file. I did not run the tests.

Merged as b203b62