Claude Opus 5.5 · Balanced

sms-workflow-reminder-retry-count-tracking-cal-com

cal.com · TypeScript · S · 30–99 lines · 3 files

The normal review, with one generalist agent. Judge: Claude Haiku 5.5.

Gold bugs found
3 of 5
Comments published
4
Comments matching a bug
3
Comments not matching
1
Cost of this PR
$0.586

Published comments (4)

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

Locked SMS accounts count as retries, so their reminders get deleted — When `isLockedForSMSSending` makes `twilio.scheduleSMS` return undefined, this branch still increments `retryCount`, so the reminder is permanently deleted after two cron runs even if the account is later unlocked. Increment `retryCount` only for real delivery failures, not intentional locks.

highbugpackages/features/ee/workflows/api/scheduleSMSReminders.ts:189-198

Temporary SMS scheduling errors count toward reminder deletion — A `checkSMSRateLimit` rejection or brief Twilio/network outage still increments `retryCount`, so two such failures delete a valid reminder that would have succeeded later. Increment only for permanent failures, such as Twilio invalid-number error codes, and let temporary errors retry.

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

Unguarded retryCount update in catch block aborts remaining reminders on failure — If `prisma.workflowReminder.update` throws here (e.g., P2025 when the record was deleted concurrently), the handler rejects and every remaining reminder in this run is skipped. Wrap the update in its own try/catch, or use `updateMany`, which doesn't throw when no row matches.

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

Unindexed `retryCount` OR branch forces a full WorkflowReminder table scan — No index in `schema.prisma` covers `retryCount`, so every cron run scans the whole `WorkflowReminder` table. Add the `WorkflowMethods.SMS` `method` filter to this branch so the existing method/scheduled/scheduledDate index applies, or add an index on `retryCount`.

Gold bugs found (3)

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.
criticalClaims transient errors increment retryCount, so two runs during an outage delete the whole pending SMS reminder queue.
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)

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.
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.