1. Multi-file race condition audit
amazon/ergo-1.0 · reasoningEffort: high · maxTokens: 2048 · ~1,400 tokens (~15–25 credits)
Prompt
Audit this TypeScript webhook handler + credit ledger update for double-crediting race conditions under concurrent retries, and return a minimal atomic patch.
Ergo-1.0 Output
1. Root cause: non-atomic read-then-write on order.status allows two concurrent Stripe retries to both pass the 'created' check. 2. Fix: wrap the order status update and credit insert inside atomic() with a precondition guard requiring status = 'created', plus a unique transactionNo constraint. 3. Verification: send two parallel webhook payloads with the same event ID and assert exactly one credit row is written.