toga-ai 1.0.384 → 1.0.385

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,76 @@
1
+ ---
2
+ type: session
3
+ slug: bdr-vapi-golive
4
+ title: BDR VAPI call loop — self-heal fix, dialer diagnosis, go-live prep
5
+ author: tcox
6
+ repos: [bdr, ai-bdr, worker2, api2, dbchanges2]
7
+ framework: "2.0"
8
+ client: shared
9
+ status: active
10
+ created: 2026-07-20
11
+ updated: 2026-07-20
12
+ ---
13
+
14
+ # Session: bdr-vapi-golive
15
+ **Date:** 2026-07-20
16
+ **Project/Repo:** bdr + worker2 + api2 + dbchanges2 (2.0)
17
+ **Task:** Get VAPI phone calls working end-to-end on the new BDR Next.js site (fix the primary-phone stranding bug, unblock the dialer, prove the call loop) and prepare same-day go-live for a real campaign.
18
+
19
+ ---
20
+
21
+ ## What WORKED
22
+ - **BDR primary-phone self-heal shipped** — `src/server/toga.ts` + `test/togaPrimaryPhone.test.ts` (10 regression tests written FIRST, all failed on old code; 114/114 suite green after; tsc + eslint clean). Detects a write response echoing `primaryContactPhoneNumber` null OR digit-mismatched, finds the orphaned phone-row uuid (echo → GET /contacts/{uuid} → POST /contact-phone-numbers), re-links via identifier-only `PUT {primaryContactPhoneNumber:{uuid}}` (single-key identifier objects hit api2's forced-MATCH path). `requestCall` throws on failure (route → 500); upsert absorbs + warns. Commit `4ac579e` on `BDR-Phase-2`, merged into deploy branch `_dev-sandbox`.
23
+ - **api2 root cause located precisely** — `Component/Api/V2/V2.php` UPDATE path lines **4985–4996** inject a reverse `contactId` back-reference into nested child objects (commit `91d803f`), defeating the single-uuid forced-MATCH fast-path (L6952) and diverting `getForeignKeyValue()`'s return before the FK assignment (L5047). CREATE path (L4601-4616/4647) has no injection. Verified by an Explore subagent read; documented in knowledge (`api2 nested-relationship-writes.md`).
24
+ - **Dialer blockage root-caused from worker2 source + prod reads** — campaign 2 ('26.05 Ryan Nitti') blocked SOLELY by `dateEnd=2026-06-09` (thrown by `validateCampaignReady` L784-786); its assistant (CampaignAssistants id 3 'Alex') is valid; the dialer cron (Core.CronJobs id 12 'AI BDR', `* * * * *`) is ACTIVE and has errored every minute since June 9. Contact 248 (tcox) is fully eligible: primary phone linked (row 132), `dtNextContactRequested` set, 0 prior attempts.
25
+ - **Test-campaign migration written, reviewed, pushed** — `Client_True/2026-07-20a - AiBdrTcoxTestCampaign.sql` on `feature/ai-bdr-test-campaign` (`e99a367`, pushed). Fences campaign 2, creates '26.07 - AI BDR - TCOX TEST' (copy of campaign 2 config, NO CampaignCallWindows rows → only requested calls possible), links ONLY contact 248. sql-reviewer verdict SHIP (idempotent guards match real UNIQUE constraints).
26
+ - **Accidental `_main` push recovered cleanly** — revert commit `56055a0` pushed (never force-push); verified via read-only DB queries the executor had NOT applied the migration first; feature branch rebuilt by cherry-pick on reverted `_main`.
27
+ - **Read-only diagnosis tooling** — BDR's api2 client creds (from `BDR/.env.local`) work for REST probes; the "TOGa Database Integration" MCP connector (`toga_query`, prod + sandbox envs, read-only) works for SQL. ClickUp MCP works for ticket lookups.
28
+ - **/capture published** 4 knowledge docs incl. new workflow `2.0/apps/ai-bdr/workflows/safe-call-loop-testing.md`.
29
+
30
+ ## What did NOT work — DO NOT RETRY THESE
31
+ - **Treating `Campaigns_Contacts.status = PENDING` as the blocker** — PENDING is a NORMAL dialable state; the eligibility SQL checks status only when `dtNextContactRequested IS NULL` (Vapi.php L237), and the webhook resets links to PENDING for retries.
32
+ - **Assuming the campaign date window is checked in `getActiveCampaignsForDialing`** — it is NOT (that query filters only `isActive=1` + assistant INNER JOIN); the date gate lives in `validateCampaignReady`. Half-wrong first theory cost a probe cycle.
33
+ - **Using the dialer's `dryRun` as a "safe" production preflight** — `createContactAttempt` (sets `dtStarted`, leaves `dtEnded` NULL) runs BEFORE the dryRun early-return (Vapi.php L438-466): a prod dry-run writes real attempt rows (counts toward maxAttempts) and WEDGES contacts as "in progress" until `dtEnded` is set. Unwedge: `UPDATE ContactAttempts SET dtEnded=NOW() WHERE contactId=? AND dtEnded IS NULL`.
34
+ - **Beta end-to-end call test** — impossible as wired: Vapi is one production account whose assistants' serverUrl targets production `webhook.togahub.com`, so a beta-placed call's end-of-call report can never find its `contactAttemptUuid` (it lives in the beta DB). Also `worker2/Config/beta.ini` still points `aws_worker_queue_url` at WorkerProductionQueue. Beta is for SQL/eligibility rehearsal via a LOCAL worker2 run only.
35
+ - **Reviving campaign 2 by extending its dateEnd** — rejected: 125 PENDING links, up to 86 contact-level-dialable real prospects, and the every-minute cron starts dialing within 60s of eligibility.
36
+ - **`isOkayToCall=0` mass-flip plan** — verified it WOULD work (hard-required at Vapi.php L231) but rejected: two mass writes to real prospect rows + restore risk (5 contacts already have `isOkayToCall=0` — genuine DNC — and must never be blanket-restored).
37
+ - **Assuming the BDR site was deployed** — no Amplify app exists; ClickUp `868kdf4tj` "BDR - create amplify and sandbox route" is still 'to do' (ClickUp says Alex Peterson; team says Jeff took it — ClickUp stale).
38
+
39
+ ## Not tried yet (candidates for next session)
40
+ - **The actual test call** — blocked on the dbchanges2 PR merge (branch pushed, PR not confirmed opened/merged).
41
+ - **UI test A:** Call Now with a DIFFERENT number → proves the self-heal live (pointer re-links to new number; dialer calls the new number).
42
+ - **UI test B:** one scheduled call ~10 min out → the call-later path and `formatCstDateTime` CST conversion have NEVER been runtime-tested.
43
+ - **Purest bug repro:** phone-less HubSpot test contact through the funnel (needs someone with HubSpot access to create it).
44
+ - **api2 engine fix PR** — gate the V2.php 4985-4996 injection to true reverse/has-many relations; confirm `RecordFields.childPolicy` for `Contacts.primaryContactPhoneNumberId` during verification.
45
+ - **worker2 dry-run fix** — move `createContactAttempt` below the dryRun return.
46
+ - **Fix CampaignAssistants id 1 'Mark'** — corrupt 37-char `assistantIdentifier` (Alex's uuid + extra trailing '4'); would 400 at Vapi if assigned.
47
+ - **Real-campaign migration** — awaiting business params (name, dates, timezone, attempt caps; recommended: web-funnel-only = NO CampaignCallWindows rows). Entry links need `hsCampaignId=<new campaign uuid>` for attribution.
48
+ - **Cleanup migration** deactivating the test campaign — must NOT merge in the same window as the create file (executor runs folder files alphabetically in one pass).
49
+ - **Stranded-contact backfill** — 40 of campaign 2's 132 linked contacts lack a primary phone pointer (only matters if that list is revived).
50
+
51
+ ## Current file state
52
+ | File | Status | Notes |
53
+ |------|--------|-------|
54
+ | BDR/src/server/toga.ts | committed `4ac579e`, on `BDR-Phase-2` + `_dev-sandbox` | self-heal (TogaPhoneRow, ensurePrimaryPhone, strict requestCall) |
55
+ | BDR/test/togaPrimaryPhone.test.ts | committed `4ac579e`, same branches | 10 regression tests, fake api2 at fetch boundary |
56
+ | dbchanges2/Client_True/2026-07-20a - AiBdrTcoxTestCampaign.sql | on `feature/ai-bdr-test-campaign` `e99a367`, pushed; PR pending | fences campaign 2, creates test campaign, links contact 248 only |
57
+ | dbchanges2 `_main` | revert `56055a0` pushed | accidental direct push recovered; DB was untouched |
58
+ | knowledge (team repo) | 4 docs published via /capture | web-funnel-app, vapi-webhook-handler, nested-relationship-writes, safe-call-loop-testing |
59
+
60
+ ## Decisions made
61
+ - **BDR-side self-heal now, api2 engine fix later** — funnel unblocked without a platform-wide risky change; engine fix deferred to its own reviewed PR. Rejected: waiting on api2.
62
+ - **requestCall strict-throws / upsert absorbs** — a "successful" submit whose call can't happen must not report success; but lead priming must never break page render.
63
+ - **One-contact test campaign over `isOkayToCall` flip** — zero writes to prospect data; test campaign has no call windows so only requested calls can ever fire. Rejected: mass flip (restore risk), reviving campaign 2 (mass dialing).
64
+ - **Migration via dbchanges2 PR, not direct SQL** — review + normal per-env process; test call fires ~60s after the executor applies it (timing note is in the file header + PR body).
65
+ - **Skipped the elevated dbchanges2 architecture-doc edit** about missing `_main` branch protection (developer: repo owner already aware).
66
+
67
+ ## Blockers
68
+ - **dbchanges2 PR** from `feature/ai-bdr-test-campaign` not yet opened/merged (tcox) → blocks the call test.
69
+ - **Amplify app doesn't exist** (ClickUp `868kdf4tj`, urgent, Sprint 82; Jeff has it per team word) → blocks URL-live. `_dev-sandbox` already contains the fix; needs SSR hosting + the 5 env vars (values' location: `info/.env.local`).
70
+ - **Real-campaign business params** not yet provided (tcox/team).
71
+
72
+ ## Exact next step
73
+ > Open + merge the dbchanges2 PR from `feature/ai-bdr-test-campaign` (`e99a367`). When the executor applies it, answer the call from +1 (216) 616-0067 (contact 248's primary phone rings within ~60s), then verify write-back with read-only queries: `ContactAttempts` for `contactId=248` has `dtEnded` + `c_callOutcome` + `c_vapiCallIdentifier` set, and `Contacts.dtNextContactRequested` is cleared. If the call happens but nothing writes back, suspect the webhook (`VAPI_SERVER_SECRET` signature or `end-of-call-report` type guard) in `worker2/Worker/Vapi.php`.
74
+
75
+ ---
76
+ _Saved by /session-save on 2026-07-20_
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toga-ai",
3
- "version": "1.0.384",
3
+ "version": "1.0.385",
4
4
  "description": "TOGA Technology Team Claude Knowledge System — shared AI coding harness with skills, knowledge base CLI, and project installer for Claude Code.",
5
5
  "keywords": [
6
6
  "claude",