Work on Linear issue MM-487: Suggested branch name:…
- User
Work on Linear issue MM-487:
Suggested branch name: malpercio/mm-487-notify-expose-the-send-workers-queue-depth-as-a-metric
The notification send worker (
crates/pds/src/notify_relay_client.rs) drains an unboundedtokio::sync::mpscwith a single sequential task. That is the right trade-off for a best-effort, device-count-scaled feature — the queue must never block a request path, and a missed push is a missed banner rather than lost data.But during a prolonged relay outage (a maintenance window, a misconfigured node id), the queue grows without bound in the interim, and today that is only inferable from
warn!log volume.Scope
Expose the current queue depth as an OTel gauge, following the existing pattern in
crates/pds/src/metrics.rs:- add the instrument + its name constant to
metrics::names - record depth from the worker (send side increments,
recvdecrements — or samplelen()if the channel type allows) - add the row to the metrics table in
crates/pds/AGENTS.md(that table mirrorsmetrics::namesand they change together) - consider surfacing it in
GET /v1/admin/healthalongside the sweep entries, so the Brass Console can show it
Why not in the original PR
Out of scope for the sender phase, and it touches the metrics module, its name constants, and the operator docs table — a self-contained change that reviews better on its own.
Open question
Whether an unbounded queue should stay unbounded once this is observable, or gain a cap that drops oldest-first. Dropping is consistent with the feature's best-effort posture; the metric is the prerequisite for deciding with evidence either way. Feature An easy-to-host PDS on the ATProtocol, MacOS. Grandma-approved. b95fcd23-95fa-43f6-86a6-81defb9dda77
Problem
Self-hosted Custos instances need to deliver push notifications to the official iOS apps (Obsign, admin-companion). APNs auth keys are bundle-ID-bound, so self-hosters cannot push directly — a relay is structurally required. The design makes that relay a blind courier: trusted for availability only.
Architecture (see design doc for full detail)
- Confidentiality: payloads HPKE-sealed (RFC 9180, DHKEM-P256 + AES-GCM) to a per-device notification key; decrypted on-device by a Notification Service Extension (
mutable-content: 1). Neither the relay nor Apple sees plaintext. - Integrity: HPKE Auth mode with pinned, versioned per-instance sender keys — the relay cannot forge authenticated content (it can generate detectable junk pushes and replay; v1 accepts duplicates as benign).
- add the instrument + its name constant to
Assistant
I'll start by getting oriented — the Linear workflow skill handles the issue state transitions, and I need to read the existing metrics pattern before writing anything.
Assistant
Now I have the shape of the problem. Two things drive the design:
★ Insight ─────────────────────────────────────tokio::sync::mpsc::UnboundedReceiverdoes havelen(), but the receiver is moved into the worker task — so nothing outside it can sample the depth. The health endpoint's pull-read requirement is what forces a shared counter rather than alen()sample.metrics.rsgauges are write-only in-process (only a Prometheus scrape observes them), which is exactly whysweep_status.rsexists as a parallel readable mirror. The same split applies here: an OTel gauge for scraping, a shared atomic for/v1/admin/health.─────────────────────────────────────────────────
Metrics is currently built after the notify worker in
main.rs, so that ordering has to flip.Assistant
That introduces a real bug — the worker task holding a
NotifySenderclone would keeptxalive, sorx.recv()never returnsNoneand the channel could never close. Splitting the counter out fixes it:Assistant
Now the call sites:
main.rs(metrics must be built first), the e2e test, and the health route.Assistant
Now the health endpoint surface:
Assistant
Now tests. Let me add coverage for the depth lifecycle and pin the rendered gauge name:
Assistant
Also pin the rendered gauge name alongside the other instruments:
Assistant
Now the docs table and the health-route test assertion, then compile.
Assistant
Clippy flags the large
Errvariant — and every call site already discards it withlet _ =. Folding the logging intosendis both the fix and an improvement:Assistant
Now fix the tests to match the infallible signature:
Assistant
All gates green. Committing and opening the PR:
Assistant
PR is open: .