Amazon Ergo 1.0 · Balanced

fix-handle-collective-multiple-host-on-destinationcalendar-cal-com

cal.com · TypeScript · S · 30–99 lines · 6 files

The normal review, with one generalist agent. Judge: Claude Opus 5.5.

Gold bugs found
7 of 20
Comments published
7
Comments matching a bug
7
Comments not matching
0
Cost of this PR
$2.901

Published comments (7)

highbugpackages/core/EventManager.ts:117-120

Missing destination calendar crashes the Google Meet fallback — Events without a destination calendar now throw a `TypeError` in `EventManager.create` instead of falling back to Daily. Guard `mainHostDestinationCalendar?.integration` so the `MeetLocationType` check handles empty or `null` calendars.

highbugpackages/app-store/googlecalendar/lib/CalendarService.ts:315-317

deleteEvent fallback matches externalId against undefined — Cancellations without `externalCalendarId` can call Google's delete with an `undefined` calendar ID, leaving the event behind. Make the `deleteEvent` fallback select the first destination with a truthy `cal.externalId` instead of matching against `undefined`.

highbugpackages/trpc/server/routers/viewer/organizations/create.handler.ts:151-153

Organization slug condition is inverted — Organization creation and verification now behave incorrectly in both billing modes: enabling team billing writes `slug` directly, while disabling it omits the slug entirely. Restore the negated `IS_TEAM_BILLING_ENABLED` condition for `slug` and keep `requestedSlug` unchanged.

highbugpackages/lib/CalendarService.ts:156-164

Collective event creation only matches the first destination calendar — Additional collective hosts can end up with no calendar event because `createEvent` compares every credential against only `mainHostDestinationCalendar.externalId`. Build `destinationCalendarExternalIds` from all `event.destinationCalendar` entries and use `includes(c.externalId)`, keeping the match-all fallback when empty.

highbugpackages/features/bookings/lib/handleNewBooking.ts:1077-1079

Collective host calendars are dropped without a primary destination — When `evt.destinationCalendar` is `null`, the optional `push` silently discards every collected host calendar, so `EventManager` falls back to the organizer's credentials. Initialize `evt.destinationCalendar` from `teamDestinationCalendars` even when the main destination is absent.

highbugpackages/core/EventManager.ts:502-550

Only the first old calendar event is deleted when merging bookings — Rescheduling or merging a collective booking leaves stale events on other hosts' calendars because the `newBookingId` cleanup handles only the first `_calendar` reference. Process the remaining `booking.references` calendar entries and delete each event with its own `credentialId` and `externalCalendarId`.

highbugpackages/features/bookings/lib/handleCancelBooking.ts:444-461

Recurring cancellation deletes organizer events instead of host events — Host calendars keep stale recurring events after cancellation, and the organizer's event may be deleted repeatedly. Iterate `updatedBookings` and select the calendar reference matching the current `credentialId`, instead of scanning `bookingToDelete.user.credentials` and using the first calendar reference.

Gold bugs found (7)

highWhen externalCalendarId is absent, updateEvent/deleteEvent look for a destination calendar whose externalId equals that absent value, so the lookup never matches and the configured destination calendar is no longer used.
highThe organization slug is now set only when team billing is enabled (inverted condition), so with billing both slug and requestedSlug are set and without billing neither is.
highThe Google Meet fallback reads mainHostDestinationCalendar.integration without optional chaining, so a Meet booking with a null or empty destinationCalendar throws instead of falling back to Cal Video.
highFor collective events whose organizer has no destination calendar, destinationCalendar is null and the optional push drops all other hosts' destination calendars, so those hosts never get calendar events.
highCancelling all remaining occurrences of a recurring collective booking deletes only the first calendar reference of each booking, repeated once per host, so the other hosts' events stay on their calendars.
highFor collective bookings, CalDAV/Apple createEvent matches calendars only against the main host's destination externalId, so other hosts' calendars are filtered out and they silently get no calendar event.
highWhen rescheduling merges into a new booking, only the first old `_calendar` reference is deleted via `.find()`, leaving stale events on other hosts' calendars for collective bookings; iterate all old calendar references.

Gold bugs missed (13)

highOffice365 (and Lark) createEvent ignore the new credentialId argument and always use the first destination calendar, so in collective bookings other hosts' credentials target the organizer's calendar instead of their own.
mediumClaims updateAllCalendarEvents passes an undefined credential to updateEvent when reference.credentialId points to a credential that cannot be found.
highVideo booking references are now saved without their credentialId, so cancelling the booking can no longer find the video credential and the meeting is not deleted.
highGoogle createEvent picks the target calendar only by matching credentialId, so destination calendars without a credentialId are ignored and events are created on the primary calendar instead.
mediumFor destination calendars without a credentialId, createEvent is called without the externalId, so the booking reference is stored with an undefined externalCalendarId.
highCalendarEvent.destinationCalendar became an array and evt is spread into webhook payloads, so payload.destinationCalendar changes from an object/null to an array and subscribers reading .externalId or .integration break.
mediumIn Google createEvent, when no destination calendar matches the credentialId, the hangout-link events.patch is called with an undefined calendarId and fails, so the Meet link is not added to the event description.
mediumWhen cancelling a recurring booking with multiple calendar references, the recurring-event deletion over all remaining bookings and credentials runs once per reference, causing duplicate delete calls and errors.
mediumloadUsers forwards raw Prisma error messages to the client in a 400 response, exposing internal model and query details.
mediumcreateAllCalendarEvents awaits the credential lookup and createEvent for each destination calendar in sequence, so collective booking latency grows linearly with host count.
highThe Stripe and PayPal payment-success handlers build destinationCalendar as a one-element array (booking or organizer calendar) before EventManager.create, so paid collective bookings create the calendar event only for the organizer and not for the other hosts.
mediumGoogle createEvent selects the target calendar by credentialId only while the booking reference stores the destination's externalId; when two destination calendars share a credential the event is inserted into the first match but the reference records the other calendar, breaking later updates/deletes.
mediumIn createAllCalendarEvents the no-credentialId branch runs per destination and reuses the organizer's credentials filtered by integration, so several same-integration destinations without credentialId create duplicate events on the organizer's calendar.