Repository navigation
fix(booking): give post-booking side effects separate budgets - #181
Conversation
dispatchBookingConfirmation ran every side effect under one 30s deadline, in the order: host 1 calendar event, host 1 email, host 2 calendar event, host 2 email, ..., attendee email, webhook, reminders. The SMTP dial timeout alone is 30s, so one stalled mail server spent the whole budget on the first host's email; the remaining hosts' calendar events, the booking.created webhook and the reminder jobs were then silently dropped (the reconciler only heals calendar events). - Queue reminders first (DB-only, durable). - Calendar phase: the primary first (it may mint the Meet/Teams link), then the other hosts concurrently. - Enqueue the webhook after the calendar phase, so it now carries a minted Meet/Teams link (it previously sent the pre-mint location). - Emails run last under their own deadline; the confirm_failed flag is written on an uncancelled context so a spent deadline cannot hide it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
Reminders scheduled inside their reminder window can run before conferencing setup persists the join URL, causing them to be sent without the meeting link.
2 open issues
What changed in this PR
This PR addresses #180 by separating post-booking calendar and email budgets so stalled SMTP cannot prevent calendar creation, webhook enqueueing, or reminder scheduling.
Changes:
- Queues reminders first, then creates the primary calendar event before processing other hosts concurrently.
- Enqueues webhooks with generated meeting links and preserves confirmation-failure flags after email timeouts.
- Adds a stalled-mail regression test covering host events, reminders, and failure reporting.
| File | Description |
|---|---|
internal/handler/dispatch_budget_internal_test.go |
Tests that stalled mail does not block calendar events, reminders, or failure flags. |
internal/handler/booking_handler.go |
Separates dispatch phases and budgets, parallelizes secondary host events, and updates webhook payloads. |
Review effort: Balanced
| defer cancel() | ||
| // Reminder jobs are durable and need nothing from the calendar phase; queue them | ||
| // before anything that can stall. | ||
| if err := h.enqueueBookingReminders(ctx, b.EventTypeID, b.ID, b.StartAt); err != nil { |
| EndAt: b.EndAt.UTC().Format(time.RFC3339), | ||
| Status: b.Status, | ||
| LocationValue: b.LocationValue, | ||
| LocationValue: bData.LocationValue, |
There was a problem hiding this comment.
ℹ️ No critical issues — one documentation follow-up and a small test-coverage note.
Reviewed changes
This run reviewed the full diff of #181 (one commit, two files).
- Durable-first dispatch order —
dispatchBookingConfirmationnow enqueues reminders before any external call, runs the calendar phase underdispatchCalendarBudget, enqueues the webhook on a non-cancelled context, then sends mail under a separatedispatchMailBudget. - Host side effects split —
createHostEventsAndNotifybecamecreateHostEvents(primary first, then remaining hosts concurrently) plusnotifyHosts(sequential host emails). - Webhook payload —
booking.creatednow usesbData.LocationValue, so it carries a minted Meet/Teams link, and theconfirm_failedflag is written oncontext.WithoutCancel(mailCtx). - Regression test —
TestDispatch_stalledMailDoesNotStarveCalendarOrRemindersasserts two host events, reminder jobs, andconfirm_failedwhile the mailer hangs.
ℹ️ docs/ARCHITECTURE.md §9 still documents the old side-effect order
§9 (lines 423–425) lists the create side effects as calendar event → host emails → attendee confirmation → webhook → reminders, which is the exact order this PR changes. §24 of the same file asks for the matching section to be updated in the same PR as the behaviour change.
Technical details
# ARCHITECTURE §9 stale side-effect order
## Affected sites
- docs/ARCHITECTURE.md:423-425 — bullet lists "per-host calendar event creation … per-host confirmation emails … attendee confirmation, webhook, reminders."
## Required outcome
- Update the §9 bullet to the new order: reminders first, then the primary/secondary calendar phase, then the `booking.created` webhook, then host + attendee emails, noting the two separate budgets.
## Why
- docs/ARCHITECTURE.md:1311 (§24): "when you change behaviour in an area above, update the matching section in the same PR."deepseek-v4.1-flash | 𝕏
| // email, so the next host's calendar event, the reminders and the webhook - all queued | ||
| // after it - were silently dropped. Every host's event and the reminder must now land | ||
| // while mail is still hanging, and the lost confirmation is flagged on the booking. | ||
| func TestDispatch_stalledMailDoesNotStarveCalendarOrReminders(t *testing.T) { |
There was a problem hiding this comment.
The test comment says the webhook was also dropped, but the fixture leaves h.webhookSvc nil and inviteProvider.CreateEvent returns no join URL, so neither the booking.created enqueue nor the new minted-link payload is exercised. Consider wiring a webhook service and asserting the enqueued payload, or trimming the webhook claim from the comment.



Fixes #180
dispatchMailBudget).confirm_failedis written on an uncancelled context, so a spent deadline cannot hide the failure.createHostEventsAndNotifyis split intocreateHostEventsandnotifyHosts. Behaviour is otherwise unchanged.Tests:
TestDispatch_stalledMailDoesNotStarveCalendarOrRemindersuses a mailer that hangs until cancelled and a provider that honours its context. Both hosts' events, the reminder job andconfirm_failedmust all land. Fullinternal/handlersuite passes.