@davoodmehraban89 / VELYQOR / commits / f3cb199
Fork 0

Intelligence, Advanced Charting & Trading Platform

fix(outbox): grant a fresh single-send permit only for a new lease after confirmed provider rejection

davoodmehraban89 committed Oct 23, 2026 at 14:46 UTC f3cb199f48834e6afb6612e4cfdbf45dbcc6c242
1 file changed +31
db/migrations/0006_alert_runtime_atomic.sql
+31
@@ -284,6 +284,37 @@ $alert_claim$;
284 ALTER TABLE public.notification_outbox
285 ADD COLUMN send_started_at TIMESTAMPTZ;
286
287 +
288 +-- PR #34 explicitly permits bounded retry ONLY after a provider-confirmed
289 +-- REJECTED outcome. Such a delivery attempt may already have consumed its
290 +-- one-send permit. A *new* legitimate lease must obtain a *new* permit;
291 +-- otherwise the old send_started_at marker deadlocks all authorized retries.
292 +-- Expired/ambiguous/UNKNOWN sends NEVER become retry-eligible.
293 +CREATE FUNCTION public.alert_notification_reset_permit_for_verified_retry()
294 +RETURNS trigger
295 +LANGUAGE plpgsql
296 +SECURITY INVOKER
297 +SET search_path = pg_catalog, public
298 +AS $retry_permit$
299 +BEGIN
300 + IF OLD.status = 'FAILED' AND NEW.status = 'LEASED'
301 + AND OLD.lease_token IS DISTINCT FROM NEW.lease_token
302 + AND NEW.attempts > OLD.attempts
303 + THEN
304 + NEW.send_started_at := NULL;
305 + END IF;
306 + RETURN NEW;
307 +END;
308 +$retry_permit$;
309 +
310 +CREATE TRIGGER notification_outbox_verified_retry_permit
311 +BEFORE UPDATE ON public.notification_outbox
312 +FOR EACH ROW
313 +EXECUTE FUNCTION public.alert_notification_reset_permit_for_verified_retry();
314 +
315 +REVOKE ALL ON FUNCTION public.alert_notification_reset_permit_for_verified_retry()
316 + FROM PUBLIC;
317 +
318 CREATE FUNCTION public.alert_notification_begin_egress(
319 p_outbox_id UUID,
320 p_claim_token UUID,