wacrm/src
Arnas Donauskas faf0f740a4
fix: stop inbound chats fragmenting into duplicate conversations (#363)
An inbound message could create a second conversation for a contact
under a race (Meta retries a delivery, or a batch fans out to concurrent
after() runs). There was no UNIQUE index and no unique-violation
backstop on conversations, unlike contacts (migration 022). Worse, once
two conversations existed the `.single()` lookup errored on every later
message and the webhook created yet another conversation each time,
snowballing into a wall of duplicate chats.

- findOrCreateConversation now resolves oldest-first with .limit(1)
  instead of .single(), so pre-existing duplicates converge, and catches
  23505 on insert to re-resolve the winning row.
- Same hardening applied to the public-API resolver (resolve-conversation).
- Migration 036 merges existing duplicate conversations into the oldest
  thread (re-pointing messages, reactions, deals, flow_runs,
  notifications, ai_usage_log — no data loss) then adds a
  UNIQUE (account_id, contact_id) index as the authoritative guarantee.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-10 12:27:46 +03:00
..
app fix: stop inbound chats fragmenting into duplicate conversations (#363) 2026-07-10 12:27:46 +03:00
components feat: WhatsApp interactive messages (reply buttons + lists) 2026-07-08 19:03:15 +03:00
hooks Merge pull request #322 from RiadDeveloper/main 2026-07-01 11:27:20 +03:00
i18n feat: add fallback logic for missing locale dictionaries and update NextIntlClientProvider configuration 2026-07-02 08:42:37 -04:00
lib fix: stop inbound chats fragmenting into duplicate conversations (#363) 2026-07-10 12:27:46 +03:00
types feat: WhatsApp interactive messages (reply buttons + lists) 2026-07-08 19:03:15 +03:00
middleware.test.ts fix(auth): preserve refreshed Supabase cookies across middleware redirects 2026-06-23 10:08:05 +03:00
middleware.ts fix(auth): preserve refreshed Supabase cookies across middleware redirects 2026-06-23 10:08:05 +03:00