GLM-5.3 · Heavy
sms-workflow-reminder-retry-count-tracking-cal-com
cal.com · TypeScript · S · 30–99 lines · 3 files
The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Haiku 5.5.
- Gold bugs found
- 3 of 5
- Comments published
- 6
- Comments matching a bug
- 3
- Comments not matching
- 3
- Cost of this PR
- $1.206
Published comments (6)
SMS lock treated as permanent failure, deleting valid pending reminders — A transient SMS lock makes `twilio.scheduleSMS` return `undefined` (see `twilioProvider.ts`, `checkRateLimitAndThrowError.ts`), so two locked cron runs push `retryCount` past 1 and the `deleteMany` permanently drops valid pending reminders. Increment only on permanent failures like invalid phone numbers, not quota-lock states.
Unprotected reminder update in catch block can abort scheduling of remaining reminders — If this `prisma.workflowReminder.update` rejects — e.g. `P2025` when an overlapping run's `deleteMany` already removed the row — the exception escapes and aborts scheduling for every remaining reminder. Wrap it in its own try/catch, or use `prisma.workflowReminder.updateMany`, which doesn't throw on zero matches.
Unindexed OR in deleteMany forces full table scan on every cron run — The unindexed `retryCount > 1` OR branch — no schema index covers it — defeats the existing `[method, scheduled, scheduledDate]` index, forcing a full `WorkflowReminder` scan on every cron run. Delete the row in the scheduling loop once the increment reaches 2, or add a partial index.
retryCount delete branch lacks SMS method filter, can delete non-SMS reminders — EMAIL reminders and future-dated rows can be deleted, since the new `retryCount > 1` branch has no `method: WorkflowMethods.SMS` filter or `scheduledDate` bound, contradicting the comment's stated contract. Restore the method filter in this branch or update the comment.
Retry give-up threshold is off by one, deleting reminders after 2 attempts — Because `retryCount` is incremented on every failed attempt including the first, `gt: 1` gives up after only two attempts — one initial send plus one retry — and deletes the reminder. Use `gt: 2` to allow three total attempts, or stop counting the first failure.
Retry counter uses read-modify-write instead of atomic increment, allowing lost updates — Overlapping cron runs both read the same `findMany` snapshot and write the same `retryCount: reminder.retryCount + 1`, a lost update that undercounts failures and lets a permanently failing reminder retry indefinitely — the exact behavior this change was written to eliminate. Use the atomic `retryCount: { increment: 1 }` at both sites.