Repository navigation
feat: implement reliable notification delivery with stream reclaimer - #823
Conversation
- Introduced a stream reclaimer to handle unacknowledged entries in Redis streams, ensuring at-least-once delivery semantics. - Enhanced PluginEventConsumer to support retry logic for failed plugin deliveries, allowing targeted retries for specific plugins. - Added StreamInspector to monitor the health of notification streams, reporting pending and dead-letter entries. - Created a new database migration for notification delivery outbox, web push subscriptions, and user notification settings. - Implemented tests for PluginEventConsumer, StreamReclaimer, and StreamInspector to ensure reliability and correctness of notification delivery.
There was a problem hiding this comment.
Important
One must-fix before merge: the push dispatcher performs outbound HTTPS inside the ClaimDue transaction, which that method's own contract forbids — details inline. The rest of the review is minor.
Approach: sound in the main — the DB outbox, XAUTOCLAIM reclaimer, per-plugin retries and client refetch catch-up are the right at-least-once pieces; only the push channel's wiring misuses the claim path.
Reviewed changes
- Delivery outbox & dispatchers —
notification_deliveriesis written with the notification, the fast path marks realtime sent, and the dispatcher retries with backoff, an attempt cap, max age, pruning and periodic summary logs; thepushchannel reuses the same claim path. - Stream reclaimer & dead letters —
XAUTOCLAIMevery 30s over 60s idle with a 5-delivery cap, poisons copied to<stream>.dead, wired into the assignment, plugin-event and question consumers, plus a health inspector. - Plugin event retries — host-observed SMTP send outcomes, retryable/permanent classification, a per-entry retry set and a targeted
DeliverEvent. - Web Push — subscription management, per-type preferences, VAPID generation/encryption, SSRF-guarded sends, 404/410 cleanup, the service worker, and Do Not Disturb enforced at send time.
- In-app mention rows — document-content and task-description mentions now create notification rows (membership re-checked, agents skipped), with
createWithRetryfor transient insert failures. - Client catch-up & bell — reconnect/visibility/60s refetch hook, day-grouped bell with an unread filter and quick mark-read, push prompt, profile push/DND cards, DND-aware chime.
- Admin health — gated
/admin/notifications/healthwith channel and stream stats, status reasons and a settings page. - Migration, tests, i18n —
000097tables, repository/dispatcher/reclaimer/consumer/push/handler tests, strings in all nine locales.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
… claiming - Renamed ClaimDue to LeaseDue in NotificationRepository to better reflect its functionality of leasing deliveries. - Updated the logic to lease pending deliveries, allowing for longer processing times without holding database locks. - Introduced RecordOutcomes method to store outcomes of leased deliveries in a single transaction. - Modified NotificationDeliveryDispatcher to handle leased deliveries and introduced concurrency for push notifications. - Enhanced tests to validate the new leasing mechanism and ensure proper handling of delivery outcomes. - Improved error handling in PluginEventConsumer and QuestionNotificationConsumer to maintain message integrity during failures.
There was a problem hiding this comment.
ℹ️ No critical issues — the leasing refactor addresses every prior thread cleanly; one minor follow-up inline.
Approach: sound — the outbox now leases rows in a short transaction and does the slow work outside it, so a slow push service no longer pins a connection or a row lock, and a sender that dies only delays its rows until the lease runs out.
Reviewed changes
- Replaced the in-transaction
ClaimDuewithLeaseDue+RecordOutcomes, sending leased deliveries outside any transaction from a bounded pool, and made shutdown cancel in-flight sends without spending an attempt. - Hardened the plugin-event consumer: a dead-letter write that fails keeps the entry pending, and the retry set is deleted only after the ack succeeded.
- Stopped acking a question notification whose
NotifyQuestionfailed, so the reclaimer repairs it. - Made
StreamHealthsurface Valkey failures instead of reading them as an empty stream. - Handled VAPID key rotation on both sides: the client resubscribes when the stored key differs, and the server forgets a subscription the push service rejects with 403.
- Added tests for the lease semantics (no pinned transaction, expired lease re-leased), pooled push sends, shutdown abandonment, dead-letter/ack failure paths and the question consumer, and fixed the
webpush-go// indirectdrift.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
… dropped by the server
There was a problem hiding this comment.
ℹ️ No critical issues — the re-registration fix works for the single-browser case; one minor gap remains inline.
Reviewed changes — reviewed the delta since the prior review (88f0844..aa1949d), a web-only change to the push preferences card.
- Held-subscription re-registration — the auto-subscribe effect now also fires when the browser holds a subscription and the server reports
subscription_count === 0, so a 403 key-mismatch delete self-heals on the next preferences visit; added a test for the dropped-subscription case and setsubscription_count: 1in the already-subscribed test.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
…improve handling of stale endpoints
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — reviewed the delta since the prior review (aa1949d..2deefcc), a web-only change to how the push preferences card re-registers a browser's subscription.
- Re-registration no longer depends on the account-wide count — the
subscription_count === 0gate is gone, so a browser that already holds a subscription callsenablePushon each Preferences visit; the endpoint-unique server upsert restores a row the server dropped after a 403 key mismatch or a VAPID rotation, even while the user's other browsers stay registered. - Stale endpoint forgotten on key mismatch —
enablePushnow also posts/users/me/push/subscriptions/deletefor the endpoint it replaces (best effort, scoped to the caller's account), sosubscription_countstops counting a row that can never be signed again. - Tests updated to the new behaviour — the re-registration case now runs with
subscription_count: 2, a new case pins that an opted-out browser is not re-registered, and the push-api test asserts the delete call alongside the fresh subscription.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
… and error handling improvements
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — reviewed the delta since the prior pullfrog review (2deefcc..79de131): five files in the push service, the delivery dispatcher, the stream reclaimer, and the plan doc.
- Per-account subscription cap —
Subscribenow evicts the account's oldest rows when it already holdsmaxSubscriptionsPerAccount(20) endpoints; refreshing an endpoint that is already registered evicts nothing, and the eviction arithmetic leaves exactly room for the incoming row. - Concurrent push fan-out —
Sendposts to a notification's subscriptions four at a time, collects per-index outcomes, and aggregates them afterWait, so one slow endpoint no longer serialises the rest; the loop variable is per-iteration on Go 1.26, and each goroutine gets its ownwebpush.Options. - Placeholder VAPID contact —
Newrecords that themailto:[email protected]placeholder is in use, and a 403 under it is logged rather than deleting the subscription, since the push service may be rejecting the placeholder rather than a stale key. - VAPID key load failures surface — a stored raw 32-byte base64url key is used as-is; anything else must decrypt, so a rotated or missing
ENCRYPTION_KEYnow returns an error instead of signing with ciphertext. The heuristic cannot misclassify an encryptor output (StdEncoding, ≥40 chars). - Reclaimer local delivery count — when
XPENDINGerrors or returns no row, a per-entry local claim count keeps the dead-letter cap effective instead of resetting to zero; the count is cleared on a successful read and before a dead-letter copy. - Idempotent dispatcher shutdown —
Stopcloses its channel through async.Once, so a second call no longer panics. - Tests and plan doc — added coverage for the cap, the placeholder 403, and the undecryptable key, and recorded the decisions in the plan doc's "Review follow-ups".
Verified locally at 79de131: go vet and go test -race pass for ./internal/service/push and ./internal/worker, and gofmt -l is clean on both.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

Summary
Makes sure a user always receives a notification. Notifications were stored reliably but delivered on a best-effort basis: the realtime announcement is fire-and-forget Pub/Sub, email was sent at most once, errors were swallowed, and a client that missed an announcement had no way to catch up. This PR closes those gaps end to end, adds Web Push and Do Not Disturb, and adds the observability to tell when delivery is not working.
A plan with the reasoning behind each decision is in docs/notification-reliability-plan.md.
Type of Change
Other: feature (backend, web, one migration).
What changed
1. The client always catches up (web)
["notifications"](useNotificationCatchUp). Pub/Sub keeps nothing for a client that was away, so the database is the source of truth.2. Stream consumers no longer lose or stall entries (
worker)XAUTOCLAIM) redelivers entries left unacknowledged, including ones owned by a dead pod's consumer name, and dead-letters an entry after 5 deliveries to<stream>.deadwith a reason. It runs on the assignment, plugin-event and question consumers. Delivery is now at-least-once.3. Delivery outbox (
notification_deliveries)FOR UPDATE SKIP LOCKED, exponential backoff, 8 attempts, expiry after 15 minutes) retries what did not go out. Safe on several replicas.4. Email is retried (
platform/plugin,worker)paca.send_email, so it records the outcome of each send made while a plugin handles an event, with no change to the plugin ABI. A retryable failure (connection refused, timeout, SMTP 4xx) leaves the stream entry unacknowledged and the reclaimer redelivers it, running only the plugins that failed. A permanent failure (SMTP 5xx, invalid address) is parked on the dead-letter stream with its reason.5. Coverage gaps
6. Web Push and preferences
ENCRYPTION_KEYis set). Apushdelivery is queued with the notification only when the recipient has a subscription and has not switched the type off. Subscriptions the push service reports gone are deleted; sends go through the SSRF-guarded client and only tohttpsendpoints.github.com/SherClockHolmes/webpush-go.7. Do Not Disturb
8. Notification popover UX (web)
9. Observability
GET /api/v1/admin/notifications/health(gated onsettings:write) reports per-channel backlog, failures, delivery latency (p50/p95) and top failure reasons, plus unacknowledged and dead-letter entries per stream, and folds them intook/degraded/failingwith plain-language reasons. An admin page (Admin → Settings → Notification delivery) shows it.Migration
One migration,
000097_notification_reliability.sql, in three labelled parts: the delivery outbox, Web Push (subscriptions, per-type preferences, VAPID keys) and Do Not Disturb. Every statement is idempotent.Not in this PR
Chat, calls and the meeting assistant are not on
master, so pushes for direct messages, chat mentions, incoming calls and assistant proposals are not included. They were built againstrelease/v1.0.0and need porting once those features land.Known limits
Testing
go vetand the unit tests pass for the whole API module. New Postgres-backed tests (outbox claim andSKIP LOCKED, push repository, preferences, Do Not Disturb, delivery stats) pass against a real Postgres.apps/e2e/tests/realtime/notification-delivery.spec.ts, Chromium, against a stack rebuilt from this branch): a notification assigned while the browser is offline, while the announcement is lost with the socket still up (found by the 1-minute re-read), and while the realtime service is down. The last one stops the stack's realtime service, so it only runs withE2E_ALLOW_STACK_RESTART=1.