Dispatch snapshots and delivery policies
Status: proposed design; not implemented. The names and example structures here are conceptual and are not usable Ruby or HTTP APIs. This document proposes an amendment to ADR-0003, whose original unconditional one-delivery-per-destination rule does not cover all intended product use cases. That ADR remains proposed pending review.
Goal and ownership
Section titled “Goal and ownership”A product makes an authorized request with explicit resources and policy. Core owns the resulting dispatch, snapshot, policy application and logical delivery records. The channel owns destination validation/normalization and provider transport, behind a contract that has not yet been designed. Visitor owns the incident workflow. A delivered provider status never means that a person has read, understood, or is safe.
Snapshot at dispatch creation
Section titled “Snapshot at dispatch creation”A preview is a nonbinding read of the current selection. Once a user confirms, Core reselects current active links and freezes them when creating the dispatch; people may have checked in or out between preview and confirmation. The product must make that behavior clear when the dispatch UI is designed.
The snapshot should retain each selected recipient-resource relationship and the contact values used for the dispatch. Later edits, checkout, or link changes must not rewrite this historical representation. A snapshot is not the same as a delivery list: the links explain why an entry was selected even when several entries map to one delivery. Exact snapshot fields, channel-specific contact representation and whether resource display names are frozen are open. The current selection API exposes a resource-link ID so separate links to the same recipient and resource can be individually traced.
Snapshot immutability means no silent historical rewriting during its retention period, not indefinite retention. Retention, deletion, audit requirements, access controls and handling of sensitive content require a separate decision.
For a detailed proposal using the new destination model and open questions about multiple addresses, see snapshot and grouping contract. Both documents describe proposed behavior; neither is implemented.
Explicit policy per dispatch
Section titled “Explicit policy per dispatch”Proposed policy names, to be stored and versioned with the dispatch:
per_destination: group matching normalized destination and channel into one logical delivery. Keep links from that delivery to every snapshot entry that contributed to it.per_recipient_destination: one delivery per distinct recipient, channel and normalized destination. Different recipients with the same destination may consequently receive more than one message. A recipient with multiple selected distinct destinations receives one delivery per destination. Preserve all contributing snapshot links for each delivery.
These policies apply to logical deliveries, not the snapshot. Policy is an
explicit required command input in this proposal; there is no global Core
default. The product chooses an appropriate policy. Visitor may choose
per_destination to avoid duplicate SMS, but that product decision is not
implemented. The duplicate-message consequence of per_recipient_destination must be
understood by the requesting product.
These are proposed dispatch policies. The existing read-only
Core::RecipientPreview still implements its own :per_recipient policy;
this documentation decision does not change that API or its behavior.
Example: recipient A is linked to two selected resources; recipient B shares
A’s normalized SMS destination. The snapshot retains A’s two links and B’s
link. For one SMS channel, per_destination produces one delivery linked to
all three snapshot entries; per_recipient_destination produces two deliveries, one for A
and one for B, retaining their respective contributing links.
Normalization and rejected destinations
Section titled “Normalization and rejected destinations”The SMS channel can normalize numbers for check-in and the read-only preview. Phone numbers are not verified. The dispatch-time channel contract, country assumptions for historical data, invalid or ambiguous inputs and versioning of normalization for frozen deliveries remain open. Store the destination actually used and enough version information to explain the grouping; do not silently re-normalize historical deliveries.
Core should support an explicit invalid-destination policy per dispatch,
separate from delivery deduplication: block rejects creation if any selected
destination is invalid; continue_with_valid allows creation with valid
destinations and retains each excluded snapshot entry with its reason. These
policy names are proposed, not implemented. A dispatch with no valid
destination must not be created.
For Visitor, the agreed direction is to show invalid numbers in the preview and let the operator correct them or explicitly confirm continuing without those recipients. The snapshot and outcome retain excluded recipients and reasons; exclusion must never be shown as successful delivery. When the operator edits a number or exclusion decision during preparation, show an updated preview. The treatment of newly invalid destinations at confirmation remains open below. A preview count of valid destinations is only the number eligible for delivery, not proof of provider acceptance or actual delivery. The exact normalizer, validation reasons and correction workflow still require design.
Atomicity and retries
Section titled “Atomicity and retries”Proposed command behavior:
- Authenticate the actor and start a tenant-scoped PostgreSQL
REPEATABLE READtransaction at the correct isolation level before any query. Establish tenant context and check authorization inside that transaction. - Validate the request and idempotency key, resolve the product selection and Core destinations against the same database snapshot, persist the policy, snapshot and logical deliveries with their associations.
- Commit before reporting dispatch creation or scheduling provider work. No provider call runs inside this database transaction. A durable handoff, such as an outbox written in the transaction, needs a separate design so a crash after commit cannot silently lose work; a simple after-commit enqueue alone does not establish that guarantee.
- A repeated key for the same tenant and same canonical command returns the original committed result. Reusing the key with materially different inputs is a conflict, not a second dispatch or silent reuse. Concurrent attempts need database-enforced uniqueness and tests; exact key scope, fingerprint fields and response types remain to be designed.
Presence changes during confirmation
Section titled “Presence changes during confirmation”The agreed direction is to prioritize sending promptly during an incident. A preview is informative, not a reservation. When the operator confirms, the system selects the current recipients and freezes the dispatch snapshot; it does not interrupt confirmation merely because someone checked in or out or a contact changed since preview. Compare and report the resulting selection and any exclusions truthfully rather than presenting the previous preview as the final recipient list.
A check-in after snapshot creation does not silently alter that dispatch. Showing new arrivals and providing an explicit follow-up is a proposed product feature; automatic sending of old incident messages is not decided.
The agreed REPEATABLE READ snapshot can be established before selection and
does not include changes committed afterwards. It does not by itself resolve
concurrent authorization revocation. See the transaction details.
Test concurrent check-in/out and preserve idempotency. An idempotent retry of
an already committed command returns its original result; reusing the key for
different command inputs is a conflict. The handling of invalid destinations
that appear after the operator has already reviewed and explicitly chosen how
to handle invalid numbers is still an open product decision: it must not be
silently presented as a successful delivery, and must be reconciled with the
need for a fast incident flow. No dispatch implementation exists yet.
Before implementation
Section titled “Before implementation”- Define the generic selection interface, channel normalization contract and how newly invalid destinations are handled without unnecessary delay. Visitor may proceed with valid destinations after explicit confirmation; excluded entries and reasons must be preserved. Reject creation for an empty selection or when no destinations are valid. Presence changes alone do not force a second confirmation.
- Define resource authorization, snapshot access, retention and deletion.
- Define idempotency key scope and concurrency, snapshot rows and delivery associations, database constraints, tenant RLS and transaction boundary.
- Test duplicate identities and destinations, multiple channels, repeated and concurrent commands, rollback, concurrent presence changes and tenant isolation.
- Design asynchronous transport, provider uncertainty and ledger separately; ADR-0004 is proposed, not implemented.