Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions packages/features/ee/workflows/api/scheduleSMSReminders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,19 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
//delete all scheduled sms reminders where scheduled date is past current date
await prisma.workflowReminder.deleteMany({
where: {
method: WorkflowMethods.SMS,
scheduledDate: {
lte: dayjs().toISOString(),
},
OR: [
{

@cubic-dev-ai cubic-dev-ai Bot Feb 13, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Bug: The retryCount > 1 deletion condition is missing the method: WorkflowMethods.SMS filter. As written, this will delete all workflow reminders (EMAIL, WHATSAPP, etc.) that have retryCount > 1, not just SMS ones. The first OR branch correctly scopes to SMS, but the second branch applies globally.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/features/ee/workflows/api/scheduleSMSReminders.ts, line 32:

<comment>Bug: The `retryCount > 1` deletion condition is missing the `method: WorkflowMethods.SMS` filter. As written, this will delete **all** workflow reminders (EMAIL, WHATSAPP, etc.) that have `retryCount > 1`, not just SMS ones. The first OR branch correctly scopes to SMS, but the second branch applies globally.</comment>

<file context>
@@ -28,10 +28,19 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
-        lte: dayjs().toISOString(),
-      },
+      OR: [
+        {
+          method: WorkflowMethods.SMS,
+          scheduledDate: {
</file context>
Fix with Cubic

method: WorkflowMethods.SMS,
scheduledDate: {
lte: dayjs().toISOString(),
},
},
{
retryCount: {
gt: 1,
},
},
],
},
});

Expand All @@ -44,8 +53,11 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
lte: dayjs().add(7, "day").toISOString(),
},
},
select,
})) as PartialWorkflowReminder[];
select: {
...select,
retryCount: true,
},
})) as (PartialWorkflowReminder & { retryCount: number })[];

if (!unscheduledReminders.length) {
res.json({ ok: true });
Expand Down Expand Up @@ -163,9 +175,26 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
referenceId: scheduledSMS.sid,
},
});
} else {
await prisma.workflowReminder.update({

@cubic-dev-ai cubic-dev-ai Bot Feb 13, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The prisma.workflowReminder.update() in the catch block is not wrapped in its own try/catch. If this DB call fails, the error will propagate uncaught, crashing the handler and skipping all remaining unprocessed reminders. Consider wrapping it in a try/catch or using .catch() to ensure the loop continues.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/features/ee/workflows/api/scheduleSMSReminders.ts, line 179:

<comment>The `prisma.workflowReminder.update()` in the `catch` block is not wrapped in its own try/catch. If this DB call fails, the error will propagate uncaught, crashing the handler and skipping all remaining unprocessed reminders. Consider wrapping it in a try/catch or using `.catch()` to ensure the loop continues.</comment>

<file context>
@@ -163,9 +175,26 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
             },
           });
+        } else {
+          await prisma.workflowReminder.update({
+            where: {
+              id: reminder.id,
</file context>
Fix with Cubic

where: {
id: reminder.id,
},
data: {
retryCount: reminder.retryCount + 1,
},
});
}
}
} catch (error) {
await prisma.workflowReminder.update({
where: {
id: reminder.id,
},
data: {
retryCount: reminder.retryCount + 1,
},
});
console.log(`Error scheduling SMS with error ${error}`);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "WorkflowReminder" ADD COLUMN "retryCount" INTEGER NOT NULL DEFAULT 0;
1 change: 1 addition & 0 deletions packages/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,7 @@ model WorkflowReminder {
cancelled Boolean?
seatReferenceId String?
isMandatoryReminder Boolean? @default(false)
retryCount Int @default(0)

@@index([bookingUid])
@@index([workflowStepId])
Expand Down