Serverless Function Terminations: In the initial execute-plan phase, WhatsApp replies were dispatched using "fire and forget" promises without await. In local testing environments this works fine, but upon simulated deployment in Vercel, the background execution is suspended immediately once the HTTP 200 is returned, leading to reliably dropped outbound messages.
Misunderstanding of the Vercel/Next.js serverless execution context where background async tasks are halted when the main thread resolves.
Every async API call (especially external network boundaries like Meta/Twilio) executed inside a Next.js API route or cron job MUST be explicitly awaited or resolved before returning the HTTP response.
Update architecture guidelines to explicitly mention "No fire-and-forget Promises in Serverless routes." Add a specific Code Review Agent check to detect unawaited fetch or SDK calls in API routes.
N+1 Query Architectures in Crons: The Weekly Summary cron iterated through users, firing sequential database queries and sequential API calls for each user.
Defaulting to single-user CRUD operations inside loops instead of designing for bulk/batch processing early on.
Cron jobs fetching data for multiple entities MUST use batching (e.g., Supabase .in('user_id', userIds)) and concurrent Promise resolution (Promise.allSettled) rather than looping explicit awaits.
Add a "Cron Architecture Standard" to the Coding Standards doc mandating batch-fetching patterns.
UX Failure on Zero-Spend and Non-Text Inputs: The initial webhook implementation expected a number, causing zero ("0") to be evaluated as falsy (invoking an error state), and failing to catch non-text messages (like receipts).
Narrow "Happy Path" testing during execute-plan. The development focused only on the standard "spent > 0" scenario and assumed text formats.
Every webhook handling unstructured user input (like WhatsApp) must explicitly handle:
- Valid edge cases (like explicitly testing
0vsnull). - Invalid object types (handling media/audio cleanly).
Require the Peer Review Agent to generate an explicitly "Adversarial Edge Case List" testing all non-standard input formats for user-facing inputs.
- engineering-lessons.md: Add Serverless Promise rule and Cron N+1 Batching rule.
- product-lessons.md: Add Unstructured Input (Zero and Media) fallback rule.
- prompt-library.md: Enhance Peer Review Prompt to aggressively hunt UX edge cases.