Repository navigation
Description
Summary
Per-agent delivery sequence allocation derives the next value only from retained deliveries rows, while the cumulative ACK cursor is persisted independently on agents. After retention removes an agent's settled delivery history, the allocator restarts at 1 even though agents.delivery_ack_seq may remain much higher.
A delivery created while that agent's node is offline is then silently excluded from every reconnect replay because replay requires delivery.seq > agents.delivery_ack_seq. This violates the durable-mailbox monotonic sequence contract and can strand post-retention channel, DM, group-DM, and thread deliveries.
Evidence on main
nextSeqSqlisCOALESCE(MAX(d.seq), 0) + 1over retained delivery rows only.agents.deliveryAckSeqis a separate persistent cursor.- Delivery retention deletes every old settled delivery and preserves no per-agent delivery high-water mark.
- Message retention can also cascade-delete delivery rows.
- Reconnect replay selects only deliveries with
seq > delivery_ack_seq. - Cumulative ACK handling treats an ACK at or below the persisted cursor as a no-op.
- The analogous workspace-event retention already preserves the highest-sequence row; delivery mailboxes have no equivalent protection.
The unique (workspace_id, agent_id, seq) index does not prevent reuse after the old row has been deleted.
Reproduction
- Register a node-bound agent and deliver and ACK messages through sequence N, so
agents.delivery_ack_seq = N. - Disconnect the node.
- Age the settled delivery rows past
delivery_ttl_days(90 days by default), then runpruneExpired. Confirm the rows are gone while the agent cursor remains N. - Send another message to the offline agent.
- Observe that the new delivery is assigned
seq = 1because the agent has no retained delivery rows. - Reconnect or register the node, which invokes pending-delivery replay.
Actual Result
- No
deliverframe is emitted because1 > Nis false. - The delivery remains
queuedand invisible to node replay. A cumulative ACK for sequence 1 would also be ignored because1 <= N. - Subsequent deliveries reuse
2..Nand are subject to the same exclusion.
Expected Result
- Delivery sequence numbers never decrease or reuse a previously issued value for an agent, regardless of retention or message cascades.
- The first post-retention delivery receives a sequence strictly above the durable per-agent high-water mark and replays normally after reconnect.
Impact
This activates through the default settled-delivery retention policy after an agent has been quiet long enough for all retained delivery rows to disappear. It is silent at send time: the durable row exists, but the participant node cannot receive it through the replay protocol. The issue affects every message shape using the shared allocator and can strand many messages for long-lived agents with high ACK cursors.
Environment
- Relaycast
mainate905f3acfb790279ee2eb964cf711f29de87f718 - Default settled-delivery retention: 90 days
Acceptance Criteria
- Persist a per-agent delivery sequence high-water mark independent of prunable message and delivery rows, or otherwise guarantee every newly allocated sequence is strictly greater than every sequence previously issued for that agent.
- Sequence allocation remains atomic under concurrent fanout and inserts.
- Retention of settled deliveries cannot reset or lower the per-agent sequence high-water mark.
- Message-retention cascades cannot reset or lower it either.
- Existing agents are migrated or backfilled from at least
MAX(agents.delivery_ack_seq, retained deliveries.seq). - Any already-hidden active rows with
seq <= delivery_ack_seqhave an explicit repair path. - Add a regression test that ACKs through N, prunes all settled rows, enqueues while offline, reconnects, and verifies the new delivery has
seq > N, is emitted, and can be cumulatively ACKed. - Add regression coverage for both settled-delivery pruning and message-cascade deletion.
Activity
fix(engine): preserve delivery sequences across retention (#252)
fix(engine): preserve delivery sequences across retention (#252)
fix(engine): preserve delivery sequences across retention (#252) (#253)
fix(engine): negotiate broker delivery cursors (#254)