Kimi K3.1 Pro · 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
4 of 5
Comments published
6
Comments matching a bug
4
Comments not matching
2
Cost of this PR
$0.659

Published comments (6)

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

Retry cleanup can delete scheduled and non-SMS reminders — The `retryCount > 1` OR branch matches every delivery method and scheduled rows, so overlapping runs can delete valid reminders and discard their Twilio references. Restrict that branch to `method: SMS` and `scheduled: false`, leaving the past-date cleanup unchanged.

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

Non-atomic retry updates lose increments in overlapping cron runs — Both updates write `retryCount` from the original `findMany` snapshot, so overlapping cron runs can lose an increment and allow more than two attempts. Use Prisma's atomic `retryCount: { increment: 1 }` in both paths.

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

Deleted reminders make the catch-block retry update abort the loop — A reminder deleted after `findMany` makes the catch-block `update` throw `P2025`, stopping the loop and masking the original scheduling error. Use `updateMany` for the retry write or handle its failure separately.

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

SMS-locked reminders consume retries without a Twilio scheduling attempt — When the user or team is SMS-locked, `twilio.scheduleSMS` returns `undefined` without contacting Twilio, so two cron passes can delete a valid future reminder that would otherwise send after unlocking. Leave `retryCount` unchanged for this no-attempt result and increment it only for actual scheduling failures.

mediumperformancepackages/features/ee/workflows/api/scheduleSMSReminders.ts:38-41

Unindexed retryCount cleanup predicate can force full table scans — The new `retryCount > 1` OR term is unindexed, so cleanup may scan the entire `WorkflowReminder` table on every cron run as it grows. Add a selective partial index for retry-exhausted reminders, or rewrite the cleanup around indexed predicates.

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

Post-scheduling update failures cause duplicate SMS retries — If `twilio.scheduleSMS` succeeds but storing `scheduled` and `referenceId` fails, this catch increments `retryCount`, so the next run sends a duplicate and later cleanup can delete the reminder while both Twilio messages remain scheduled. Increment retries only for `scheduleSMS` failures and handle post-scheduling database errors separately.

Gold bugs found (4)

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

criticalClaims transient errors increment retryCount, so two runs during an outage delete the whole pending SMS reminder queue.