@davoodmehraban89 / VELYQOR / commits / 8e80786
Fork 0

Intelligence, Advanced Charting & Trading Platform

fix(outbox): skip bounded revoked-recipient backlog to avoid starving valid pending notifications

davoodmehraban89 committed Oct 22, 2026 at 23:52 UTC 8e80786de5ca3af96803031b1863c1c67660a9f1
1 file changed +9 -1
db/migrations/0006_alert_runtime_atomic.sql
+9 -1
@@ -216,6 +216,7 @@ AS $alert_claim$
216 DECLARE
217 v_claim RECORD;
218 v_authorized BOOLEAN;
219 + v_scan INTEGER;
220 BEGIN
221 IF p_now IS NULL OR p_lease_seconds IS NULL
222 OR p_lease_seconds NOT BETWEEN 1 AND 300 THEN
@@ -223,6 +224,10 @@ BEGIN
224 USING ERRCODE = '22023';
225 END IF;
226
227 + -- Skip a bounded revoked-recipient backlog within the same claim,
228 + -- otherwise a revoked queue head could starve valid users.
229 + FOR v_scan IN 1..16 LOOP
230 + v_authorized := false;
231 SELECT * INTO v_claim
232 FROM public.notification_outbox_claim(p_now, p_lease_seconds);
233 IF NOT FOUND THEN RETURN; END IF;
@@ -256,7 +261,7 @@ BEGIN
261 WHERE o.id = v_claim.outbox_id
262 AND o.status = 'LEASED'
263 AND o.lease_token = v_claim.claim_token;
259 - RETURN;
264 + CONTINUE;
265 END IF;
266
267 outbox_id := v_claim.outbox_id;
@@ -266,6 +271,9 @@ BEGIN
271 claim_token := v_claim.claim_token;
272 attempt_number := v_claim.attempt_number;
273 RETURN NEXT;
274 + RETURN;
275 + END LOOP;
276 + RETURN;
277 END;
278 $alert_claim$;
279