Work on Linear issue MM-418: Suggested branch name:…
- User
Work on Linear issue MM-418:
Suggested branch name: malpercio/mm-418-notify-49-custos-sender-config-sender-keys-registration
Scope
- Config:
[notifications]incommon::Config—relay: Option<String>(node id, default None → off, the[iroh]posture),enrollment_code: Option<String>; envEZPDS_NOTIFICATIONS_RELAY/EZPDS_NOTIFICATIONS_ENROLLMENT_CODE; validation requires[iroh] enabled. - Migrations (V052+):
notification_sender_keys(kid autoincrement, secret encrypted under master key per theiroh_identityscheme, retired_at/revoked_at),notification_registrationskeyed (did, device_uuid) — NOT FK'd to the transientdevicestable (deleted at DID promotion) — andadmin_notification_registrationskeyed byadmin_devices.id. Sender keys joinSecretFamilyindb/kek.rsforrewrap-master-key. - Routes (+ bruno, seq 124+):
POST /v1/notifications/register+DELETE /v1/notifications/register/{deviceUuid}+GET /v1/notifications/sender-keysviaauthenticate_access(DPoP — auth-seam-check applies);POST /v1/admin/notifications/register+GET /v1/admin/notifications/sender-keysviarequire_adminsigned envelope. Sender-keys responses are the re-pin surface with versioned kids; rotation = publish new alongside old, retire after overlap; revocation = immediate removal from the set. - Relay client: the PDS's first outbound iroh leg —
notify_relay_clientmodule reusing the existingIrohStateendpoint to dial the configured node id, one stream per RPC, lazy reconnect with backoff. Sends flow through an in-process mpsc worker (fire-and-forget; in-memory queue only — a missed push is a missed banner, the app reconciles from Custos). Enroll-on-first-contact consumes the config claim code. - Sending:
notifications.rsownsnotify_device(did, payload)/notify_admin_devices(payload): pad to bucket, HPKE-seal per registration (fan-out, one seal per device), push, delete the registration onunregistered. - Cleanup:
purge_accountgains the registrations delete (+ best-effort ); path cleans the admin row.
- Config:
Assistant
I'll start by orienting: the Linear workflow skill, then the design doc and the code this builds on.
Assistant
Issue is already In Progress and assigned. Now let me read the implementation design doc — it's the spec of record.
Assistant
Good picture. Let me start with config.
Assistant
Now validation and the build step:
Assistant
Now config tests, then the migration.
Assistant
Config layer is green (194 tests). Now the schema.
★ Insight ─────────────────────────────────────- The
[notifications] relay = Nonedefault isn't laziness — it's the same "structurally inert" posture as[iroh]. A feature that can leak metadata should require an affirmative act to exist at all, not merely to behave. - Validation rejecting
relaywithoutiroh.enabledconverts a silent failure mode (pushes that simply never arrive, with no error anywhere) into a startup crash. Configuration errors that manifest as absence are the expensive kind. enrollment_codeis wrapped inSensitivebecauseConfigderivesDebug— a bearer grant printed in one panic backtrace is a permanently burned credential.─────────────────────────────────────────────────
- The
Assistant
Now the KEK inventory:
Assistant
Now the db query module. This is where the rotation semantics live in SQL.
Assistant
The known worktree-path trap — most edits landed in the main checkout. Moving them across and restoring main.
Assistant
Worktree is now correct; the main checkout cleanup needs the sandbox off.
Assistant
Main checkout is clean again. Re-running against the worktree:
Assistant
The schema-walking FK tripwire caught the new table exactly as designed — that's the guard doing its job.
★ Insight ─────────────────────────────────────account_delete.rshas a test that walks the live schema for every FK pointing ataccountsand asserts the purge list covers it. Adding a table that referencesaccountswithout a matchingDELETEfails CI automatically — a structural guard against the recurring "orphaned rows survive account deletion" bug class in this repo.- The
admin_notification_registrationstable doesn't trip it: it FKs toadmin_devices, notaccounts, so its cleanup rides the device-revoke path instead.─────────────────────────────────────────────────
Assistant
Now the outbound relay client — the PDS's first dialing iroh leg. First, let me make the wire protocol single-sourced rather than duplicated.
Assistant
Now the relay client itself:
Assistant
Let me single-source the APNs envelope shape so the sender's padding arithmetic and the relay's serialization can't drift:
Assistant
Now the send module. There's one decision here I want your call on before I fix the contract:
Assistant
Now tests for the decoder, then the send module:
Assistant
The 0x02-repeated x-coordinate happened to be a real curve point. Using an x beyond the field modulus instead:
Assistant
Green, and the relay crate still builds with the lib split. Now the send module:
Assistant
Now the routes. First the account surface:
Assistant
Now the admin surface — it needs the signed-envelope pattern:
Assistant
The "routes never import routes" rule applies — extracting the shared pieces into a non-handler support file, the sanctioned pattern here (
admin_subject_defs.rs,oauth_templates.rs):Assistant
The regex approach hung. Let me do this with targeted edits instead.
Assistant
The file is intact. Deleting lines 38–98 and 219–272, then patching the references:
Assistant
Now fix the admin route's cross-route imports and wire everything up:
Assistant
Now the wiring:
AppState,app.rsroutes,main.rsstartup, and the cleanup paths.Assistant
Now register the five routes in
app.rs:Assistant
Let me compile now and fix what shakes out:
Assistant
Compiles. The dead-code warnings are the un-wired trigger — let me connect it, plus the two cleanup paths.
Assistant
Now the two cleanup paths — purge and admin-device revoke:
Assistant
Caught a real ordering bug: I read the handle after revoking, but the active-registrations query filters on
revoked_at IS NULL, so it would always find nothing. Adding a status-independent lookup:Assistant
Now the purge path's best-effort
dropHandle:Assistant
The unused rotation functions point at a real gap: nothing can trigger a rotation. Let me check the CLI structure and add the operator commands.
Assistant
Now the remaining warnings — the unused row fields and the phase-7 admin API:
Assistant
Clippy is clean with
-D warnings. Let me run the full test suites:Assistant
Now the headline acceptance criterion: the full loopback e2e. That needs the relay's service reachable from the PDS's tests, so let me restructure the relay as lib + thin bin.
Assistant
Everything I need is available. Refactoring the client to hold a full address (so a loopback test can dial without discovery), then writing the e2e:
Assistant
Both e2e tests pass on the first run — the real wire contract holds end to end.
★ Insight ─────────────────────────────────────- The padding assertion in that test is the one that would catch cross-crate drift: Custos computes
padagainst its model of the APNs body, and the relay serializes its body. Asserting the received length lands on a bucket proves those two models agree — which is exactly whyapns_envelopewas moved into the shared protocol rather than duplicated. - HPKE
mode_authmeans the device's successfulopenis the sender-authenticity check; there's no separate signature to verify. The impostor-key assertion proves the property is real rather than incidental. - The tests poll for conditions instead of sleeping, because the send path is deliberately asynchronous — a fixed sleep would be either flaky or slow, and would encode a timing assumption the design explicitly refuses to make.
─────────────────────────────────────────────────
Now the repo's parity gates — bruno files, changelog, and docs:
- The padding assertion in that test is the one that would catch cross-crate drift: Custos computes
Assistant
Bruno parity green. Now the changelog fragment and generated docs:
Assistant
That regenerated from the main checkout, not the worktree. Let me verify main is untouched and re-run in the right tree:
Assistant
Main is clean (regeneration was a no-op there). Now in the worktree:
Assistant
The generated references picked up the new routes and config. Let me run the remaining CI gates:
Assistant
The
/tmpredirect was sandbox-blocked (docs-check itself passed). Re-running without it:Assistant
Now the full verification pass, plus lock-check and deny:
Assistant
Full workspace green. Let me finish the remaining gates and update the crate docs:
Assistant
Audit and deny both pass. Now updating the crate AGENTS.md docs to match:
Assistant
My "Used by" insertion landed awkwardly mid-sentence. Fixing that, then updating the relay crate docs:
Assistant
Let me verify the doc edits didn't break the ticket-ref gate, then commit:
Assistant
All gates green. Committing and opening the PR:
Assistant
- User
CodeRabbit has left many comments that we should address
Assistant
I'll fetch the whole batch at once rather than working through them piecemeal.
Assistant
Let me verify the claims against the actual code before deciding — particularly the race one, which proposes a change I suspect is wrong.
Assistant
I've verified all 11 against the code. Here's the disposition before I touch anything:
Triage
Assistant
Now applying the fixes. Starting with the two doc/comment corrections and the CLI no-op reporting:
Assistant
Now #5 (CLI silent no-op) and #3 (documenting why the unconditional write is correct):
Assistant
Now #6 (
Zeroizingscalars) and #7 (empty key set):Assistant
Now the caller in
notification_views.rsmust map the new error, and #10, #11, #8, #4:Assistant
All green. The new 503 path is a behavior change, so let me pin it with a test:
Assistant
The 503 is correct; my assertion just read the wrong JSON path (the envelope nests under
error):Assistant
Now the docs need the 503 documented, then the full gate run:
Assistant
All green (2264 pds tests, up 3). Committing and pushing as one batch:
Assistant
Now the follow-up issue for #9, then replying to and resolving the threads:
Assistant
Now replying to the two threads that need a substantive answer, then resolving all eleven:
Assistant
- User
ci / pds gate is failing
Assistant
Everything passed locally, so this is likely something the flat CI checkout runs that my worktree couldn't. Let me get the actual failure.
Assistant
One test flaked:
a_device_registers_itself_for_push— 401 "invalid admin request signature". That smells like signature malleability, not a real regression. Let me confirm by running it in a loop.Assistant
Confirmed — 6/10 failures. That's a coin flip, i.e. signature malleability:
SigningKey::signfor P-256 doesn't normalize S, and the verifier correctly rejects high-S. My test helper's bug, not the feature's. Let me see how existing admin-device tests handle it.Assistant
Root cause confirmed: the existing repo helpers do
sig.normalize_s().unwrap_or(sig)and mine omitted it. The verifier correctly rejects high-S, so ~half of generated signatures failed.Assistant
20/20 green. Let me make sure nothing else I added is nondeterministic — the e2e tests generate fresh keys each run:
Assistant
All 32 notification tests stable across 8 runs. Full gate, then push:
Assistant
PDS gate passes. Pushed as f592f1a5.
What was actually wrong
Not a regression in the feature — a bug in my test's signing helper.
ECDSA signatures are malleable: every signature has a high-S twin that verifies against the same key. The admin guard rejects the high-S form (matching
@atproto/cryptoand plc.directory strict verification, so one signature can't yield two valid requests). P-256'sSigningKey::signdoesn't normalize, so my helper emitted a rejected signature whenever the nonce happened to land high.That's a clean ~50/50 coin flip. Locally it passed the handful of times I ran it before pushing; CI lost the toss. When I ran it in a loop, 6 of 10 failed — which is what turned "mysterious CI failure" into an obvious diagnosis.
- User
coderabbit has one remaining open review, did we address it?
Assistant
Let me check — I resolved all 11 earlier, but CodeRabbit may have posted a new one after the last two commits.
Assistant
Valid, and it's reviewing my own fix — I removed the
is_some()check when unwrapping theif let Some(master_key)wrapper. Let me confirm the current shape:Assistant
Correct, and there's a second path it doesn't mention: if every stored row fails to unwrap,
filter_mapalso yields an empty 200. Rather than patch the generation call specifically, I'll enforce the invariant once at the exit — that covers both paths and any future one.Assistant
Now a test that actually exercises the surviving path — every stored key unusable:
Assistant
Let me verify the new test actually fails without the guard — a test that passes either way proves nothing:
Assistant
Confirmed: without the guard it returns
200(the exact bug), with it503. Restoring and running the full gate:Assistant
The new test needs formatting. Fixing and re-running:
Assistant
All green (2265, +1). Updating the two
.brudocs for the broadened 503, then committing: