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