wacrm/src/lib
Arnas Donauskas 635b5c1df6
fix(automations): atomic execution_count via SQL function (migration 007)
The engine did a client-side read-modify-write on
automations.execution_count, so two concurrent dispatches of the
same automation (e.g. fired for two different contacts within the
same second) could both read N and both write N+1, permanently
losing one count.

- Migration 007 adds increment_automation_execution_count(p_automation_id)
  as a SECURITY DEFINER sql function. Only service_role can EXECUTE
  it — an authenticated user can't juice someone else's counter by
  calling the RPC directly.
- Engine now calls this RPC instead of reading automation.execution_count
  and adding 1. Atomic in one statement; concurrent dispatches both
  land correctly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-17 21:45:27 +03:00
..
automations fix(automations): atomic execution_count via SQL function (migration 007) 2026-04-17 21:45:27 +03:00
supabase fix: make Supabase browser client a singleton 2026-04-16 19:39:24 +03:00
whatsapp fix(broadcasts): senior-review hardening pass 2026-04-17 17:38:52 +03:00
broadcast-status.ts fix(broadcasts): per-recipient variables, webhook status sync, rate limit 2026-04-17 11:22:38 +03:00
utils.ts feat: initial commit 2026-04-16 17:53:27 +03:00