Skip to content

fix(booking): give post-booking side effects separate budgets - #181

Merged
shockalotti merged 1 commit into
Calnode:mainfrom
MohammadHadi2031:fix/booking-dispatch-budget
Oct 29, 2026
Merged

shockalotti merged 1 commit into
Calnode:mainfrom
MohammadHadi2031:fix/booking-dispatch-budget

Conversation

@MohammadHadi2031

@MohammadHadi2031 MohammadHadi2031 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #180

  • Reminders are queued first (DB-only, durable).
  • Calendar phase: the primary first (it may mint the Meet/Teams link), then the other hosts concurrently.
  • Webhook enqueued after the calendar phase, so it carries the minted link.
  • Emails run last under their own deadline (dispatchMailBudget). confirm_failed is written on an uncancelled context, so a spent deadline cannot hide the failure.
  • createHostEventsAndNotify is split into createHostEvents and notifyHosts. Behaviour is otherwise unchanged.

Tests: TestDispatch_stalledMailDoesNotStarveCalendarOrReminders uses a mailer that hangs until cancelled and a provider that honours its context. Both hosts' events, the reminder job and confirm_failed must all land. Full internal/handler suite passes.

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>
Copilot AI balanced review requested due to automatic review settings October 28, 2026 19:22

Copilot AI 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.

🟡 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,

@pullfrog pullfrog Bot left a comment

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.

ℹ️ 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 — dispatchBookingConfirmation now enqueues reminders before any external call, runs the calendar phase under dispatchCalendarBudget, enqueues the webhook on a non-cancelled context, then sends mail under a separate dispatchMailBudget.
  • Host side effects split — createHostEventsAndNotify became createHostEvents (primary first, then remaining hosts concurrently) plus notifyHosts (sequential host emails).
  • Webhook payload — booking.created now uses bData.LocationValue, so it carries a minted Meet/Teams link, and the confirm_failed flag is written on context.WithoutCancel(mailCtx).
  • Regression test — TestDispatch_stalledMailDoesNotStarveCalendarOrReminders asserts two host events, reminder jobs, and confirm_failed while 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."

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using 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) {

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.

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.

@shockalotti
shockalotti merged commit 605d71a into Calnode:main Oct 29, 2026
9 checks passed
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.

A slow SMTP server silently drops other hosts' calendar events, reminders and the booking.created webhook

3 participants