fix(outbox): persist a delivery outcome on its own token, not the shutdown token (NTF-1, WP4 task 4.5)

This commit is contained in:
Joseph Doherty
2026-12-03 09:54:37 -05:00
parent f02fe9d696
commit 5f7b850af2
3 changed files with 85 additions and 5 deletions
@@ -111,6 +111,8 @@ The site→central handoff is **at-least-once**. Central ingests an inbound noti
Delivery has no row-level claim or lease: dispatchers read due rows and persist delivery status after sending. An interrupted delivery can therefore be sent again after failover. During a dual-active partition permitted by the auto-down policy, both central singletons can repeatedly select overlapping batches and deliver duplicate notifications across multiple sweeps; exposure is not limited to one notification or one handover. The `NotificationId` deduplication above protects ingestion, not external Email/SMS delivery. This remains an accepted at-least-once delivery limitation; there is no dispatcher fencing or exactly-once guarantee.
A **graceful** handover no longer widens that window (NTF-1, 2026-12): the actor's shutdown token is passed to the channel adapter (so CoordinatedShutdown cuts an in-flight send short) but **not** to the write that records the adapter's outcome. Once the adapter has returned — for a success, after the relay accepted the message — the status write runs on its own token bounded by a 30 s timeout, and the audit rows are emitted the same way. Previously that write was cancelled with the shutdown token, the row stayed `Pending`/`Retrying` with no record of the send, and the new active node's first sweep sent the email or SMS again.
## Dispatcher
The dispatcher loop runs on a fixed interval. On each tick the `NotificationOutboxActor`: