Skip to content

Comprehensive workflow reminder management for booking lifecycle events#6

Open
akshayutture-augment wants to merge 1 commit into
workflow-queue-basefrom
workflow-queue-enhanced
Open

Comprehensive workflow reminder management for booking lifecycle events#6
akshayutture-augment wants to merge 1 commit into
workflow-queue-basefrom
workflow-queue-enhanced

Conversation

@akshayutture-augment

@akshayutture-augment akshayutture-augment commented Nov 14, 2025

Copy link
Copy Markdown

Test 6


Replicated from ai-code-review-evaluation/cal.com-cursor#6


Note

Adds cancellable workflow reminders with schema support and updates booking/workflow flows to cancel, clean up, and schedule reminders reliably (email/SMS).

  • Workflows/Reminders:
    • Add cancelled flag to WorkflowReminder (schema + migration).
    • Refactor reminder cancellation APIs:
      • deleteScheduledEmailReminder(reminderId, referenceId, immediateDelete?) to cancel via SendGrid or mark cancelled.
      • deleteScheduledSMSReminder(reminderId, referenceId) to cancel via Twilio and delete DB record.
  • Booking lifecycle:
    • On cancel (handleCancelBooking): cancel all associated workflow reminders (email/SMS) and scheduled jobs.
    • On reschedule (handleNewBooking, viewer/bookings requestReschedule): cancel reminders from the previous booking before proceeding.
  • Workflows router:
    • On workflow delete / event type deactivation / step delete or edit: cancel affected reminders instead of bulk deleting, with immediate SendGrid cancellation where needed.
  • Email reminders cron (scheduleEmailReminders):
    • Purge past-due scheduled email reminders; cancel and remove reminders flagged cancelled within the next hour; continue scheduling unscheduled reminders.
  • UI (WorkflowStepContainer):
    • Show phone verification inputs only when a phone number is needed; separate Sender ID vs Sender Name inputs.

Written by Cursor Bugbot for commit 2ebfcf4. Configure here.

…re still sent (#7232)

* small UI fix

* fix cancelling scheduled emails

* improve comments

* delete reminders for rescheduled bookings

* add migration file

* cancel rescheduled bookings immediately

* remove immediate delete for request reschedule

---------

Co-authored-by: CarinaWolli <wollencarina@gmail.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

},
data: {
cancelled: true,
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Incomplete Reminder Deletion Leaves Database Orphans

When immediateDelete is true, deleteScheduledEmailReminder cancels the SendGrid scheduled send but returns without deleting the database record. This causes orphaned workflow reminder records to accumulate in the database indefinitely. The function should delete the database entry after canceling the external send.

Fix in Cursor Fix in Web

if (reminder.method === WorkflowMethods.EMAIL) {
deleteScheduledEmailReminder(reminder.id, reminder.referenceId);
} else if (reminder.method === WorkflowMethods.SMS) {
deleteScheduledSMSReminder(reminder.id, reminder.referenceId);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Unawaited Promises Cause Race Conditions

The forEach callback is declared async but its promises are not awaited. The deleteScheduledEmailReminder and deleteScheduledSMSReminder calls execute without waiting for completion, potentially causing race conditions where workflow steps are deleted before reminders are properly canceled. Use await Promise.all(remindersToUpdate.map(...)) instead.

Fix in Cursor Fix in Web

await Promise.all(workflowRemindersToDelete);
} catch (error) {
console.log(`Error cancelling scheduled Emails: ${error}`);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Unfiltered Reminders Generate Cancellation Errors

The query for remindersToCancel doesn't filter for non-null referenceId. Reminders created for dates beyond 72 hours have referenceId: null. When these reminders are later marked as cancelled and the CRON job processes them, it attempts SendGrid API calls with batch_id: null, which fail and generate unnecessary error logs. The query should exclude reminders where referenceId is null.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants