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)

highbugpackages/features/ee/workflows/api/scheduleSMSReminders.ts:178-186

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.

highbugpackages/features/ee/workflows/api/scheduleSMSReminders.ts:190-197

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.

mediumperformancepackages/features/ee/workflows/api/scheduleSMSReminders.ts:31-43

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.

mediumbugpackages/features/ee/workflows/api/scheduleSMSReminders.ts:28-43

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.

mediumbugpackages/features/ee/workflows/api/scheduleSMSReminders.ts:38-43

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.

mediumbugpackages/features/ee/workflows/api/scheduleSMSReminders.ts:179-186

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.

Gold bugs found (3)

mediumretryCount is set to reminder.retryCount + 1 from a value read at the start of the run instead of an atomic increment, so overlapping runs can lose increments.
mediumThe retry-count update inside the catch block is not guarded, so if it throws (for example the reminder was deleted concurrently) the error escapes the loop and the cron run fails, skipping the remaining reminders.
highSMS-sending locks are counted as failed scheduling attempts: scheduleSMS returns undefined for locked users/teams, retryCount is incremented, and after two cron runs the retryCount > 1 cleanup deletes future reminders even if sending is later unlocked.

Gold bugs missed (2)

highThe deleteMany OR clause applies retryCount > 1 without the SMS method filter, so the SMS cron deletes any workflow reminder (email, WhatsApp) with retryCount above 1.
criticalClaims transient errors increment retryCount, so two runs during an outage delete the whole pending SMS reminder queue.