fix(partition-keys): prevent incomplete slot setup from losing history
Severity
Medium-high — silent message-history loss for a partitioned consumer.
Problem
subscribe_slot(queue, consumer, slot, n) creates only one engine subscription per call. If a producer sends/ticks events before all 0..n-1 slots are registered, a late slot subscription starts at the current tick and permanently skips earlier events in its hash class.
The status view makes this especially dangerous: a missing slot is synthesized with last_tick = NULL but pending_events = 0, which looks caught up rather than incomplete.
Reproduction
- Create a queue and subscribe only slot 0 with
n=2. - Send/tick an event whose key hashes to slot 1.
- Observe slot 1 in
partition_slot_status:last_tick=NULL,pending_events=0. - Subscribe and claim slot 1.
receive_partitionedreturns zero rows; the historical event is unreachable by that partitioned consumer.
Affected implementation:
subscribe_slotindevel/sql/pgque-api/partition_keys.sqlpgque.partition_slot_statusin the same file
Expected resolution
Make incomplete setup impossible or unmistakable. Preferred direction: an atomic whole-consumer registration API that creates all N slot subscriptions in one transaction and is the public setup path. At minimum, expose an explicit subscribed state, return unknown lag rather than zero for missing subscriptions, and hard-document that registration must finish atomically before producing.
Add regressions for partial setup, late registration, status semantics, and preservation of all slot histories. This needs an explicit API decision before final 0.3.0.
Shipped in v0.3.0-rc.2 (merged to main via #395 at f4c7457): https://github.com/NikolayS/PgQue/releases/tag/v0.3.0-rc.2