DeepSeek V4.1 Flash · 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.077

Published comments (4)

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

Do not increment retryCount when SMS sending is locked — `twilio.scheduleSMS` returns `undefined` when sending is locked, and `checkSMSRateLimit` sets that state automatically once the monthly limit is hit, so a temporarily locked user permanently loses all reminders after two cron runs. Only increment `retryCount` for genuine provider errors and skip when sending is locked.

highbugpackages/features/ee/workflows/api/scheduleSMSReminders.ts:38-42

SMS cleanup deletes EMAIL and WHATSAPP reminders with retryCount > 1 — Without a `method` filter this SMS cron hard-deletes EMAIL and WHATSAPP `WorkflowReminder` rows whose `retryCount` exceeds 1. Scope the branch with `method: WorkflowMethods.SMS` so only SMS reminders can be deleted, matching `scheduleWhatsappReminders.ts`.

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

Unguarded retryCount update in catch can abort reminder batch — If `prisma.workflowReminder.update` throws — say P2025 after the new `deleteMany` removed the row — the exception escapes the loop and skips every remaining reminder in the batch. Wrap the increment in its own try/catch or use `updateMany` so error handling cannot abort the batch.

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

Missing index on WorkflowReminder retryCount causes cron full scan — No index supports `retryCount`, per `schema.prisma`, so this `deleteMany` full-scans the multi-million-row `WorkflowReminder` table on every cron run. Add an index on `retryCount` or on `(method, retryCount)` in the migration.

Gold bugs found (3)

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

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