DeepSeek V4 Pro · 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 Opus 5.5.

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

Published comments (5)

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

Locked SMS account wrongly increments retryCount in else branch — When SMS sending is locked, `twilio.scheduleSMS` returns `undefined` instead of throwing, so this `else` branch counts a lock as a send failure and increments retryCount. Pending reminders for a locked account are deleted after two cron runs without any send attempt, so they are permanently lost if the lock is later removed.

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

Second OR branch lacks SMS method filter, deleting non-SMS reminders — The second OR branch `{ retryCount: { gt: 1 } }` is missing the SMS method filter. This endpoint is meant to clean up SMS workflow reminders only, but this branch will delete any WorkflowReminder of any method (email, etc.) once its retryCount exceeds 1.

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

Off-by-one retry threshold deletes SMS reminders after one retry — The retry limit is off by one relative to the value being measured. `retryCount` is incremented on every failed attempt including the initial one (lines 184 and 195), but this deletion condition removes reminders when `retryCount > 1`.

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

Wrap retryCount update in its own try/catch to preserve best-effort catch behavior — The new awaited prisma.workflowReminder.update inside the catch block changes the error contract: previously a scheduling error was swallowed and logged, and the loop continued to the next reminder. Now, if this retryCount update throws (e.g. transient DB failure or the reminder was deleted), the error escapes the catch and aborts the whole cron run, causing remaining reminders to be skipped and the request to fail.

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

Non-atomic retryCount increment permits indefinite SMS retries — `retryCount` is updated with a non-atomic read-modify-write (`reminder.retryCount + 1`) using the value read at findMany time. Two overlapping cron invocations both read the same stale value and write the same incremented result, so retryCount never reaches 2 and the reminder is retried indefinitely, defeating the new retry cap. **Also found in:** - `packages/features/ee/workflows/api/scheduleSMSReminders.ts:178-186`

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 (2)

criticalClaims transient errors increment retryCount, so two runs during an outage delete the whole pending SMS reminder queue.
mediumscheduleWhatsappReminders never increments retryCount on Twilio failure, so failing WhatsApp reminders are retried on every cron run and never reach the retryCount > 1 cleanup added for SMS.