GLM-5.3 · 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 Haiku 5.5.
- Gold bugs found
- 7 of 9
- Comments published
- 12
- Comments matching a bug
- 7
- Comments not matching
- 5
- Cost of this PR
- $1.668
Published comments (12)
Dereference of possibly undefined mainHostDestinationCalendar crashes EventManager.create — Whenever `evt.destinationCalendar` is null or empty — as callers like `handleNewBooking.ts` produce — dereferencing `mainHostDestinationCalendar.integration` throws a TypeError that crashes the booking/payment flow instead of falling back to Cal Video. Use `mainHostDestinationCalendar?.integration`.
References created by updateLocation lose externalCalendarId and credentialId — `CalendarManager.updateEvent` returns neither `externalId` nor `credentialId`, so every reference `updateLocation` creates stores undefined, and later reschedule/cancel operations can't resolve the right calendar. Return those fields or fall back to `evt.destinationCalendar` values.
Inverted IS_TEAM_BILLING_ENABLED condition drops slug or bypasses requestedSlug flow — The ternary is inverted: with billing disabled, self-hosted orgs get no slug even though `vercelCreateDomain(slug)` registered their subdomain, making them unreachable via `getSlugOrRequestedSlug`; with billing enabled it bypasses the `requestedSlug` approval flow. Restore the `!IS_TEAM_BILLING_ENABLED` condition.
createEvent posts to first destination calendar regardless of which host credential was invoked — Each host's credential is now invoked per destination, yet `createEvent` still posts to `destinationCalendar[0].externalId`, so a member's token 404s on another host's calendar id; `LarkCalendarService` makes the same mistake. Match the destination whose `credentialId` equals the invoked one, as `GoogleCalendarService` does.
destinationCalendar initialized to null drops member calendars for collective events — When no event-type or organizer destination exists, `evt.destinationCalendar` is null, so `evt.destinationCalendar?.push(...teamDestinationCalendars)` silently no-ops and `createAllCalendarEvents` falls back to organizer credentials only. Initialize the field to `[]` like the other handlers.
updateEvent fallback never matches, leaving calendarId undefined — The fallback `find((cal) => cal.externalId === externalCalendarId)` only runs when `externalCalendarId` is falsy, so it never matches and `calendar.events.update` receives `calendarId: undefined`, silently failing reschedules for bookings whose reference lacks that field. Use `event.destinationCalendar?.[0]?.externalId` instead. **Also found in:** - `packages/app-store/googlecalendar/lib/CalendarService.ts:315-317`
Video meeting references lose credentialId, preventing meeting deletion on cancellation — `handleCancelBooking.ts` only calls `deleteMeeting` when `credentialId` is set, so canceled Zoom/Teams/Daily rooms are left orphaned. Use `result.credentialId` for the video branch — `createMeeting` in `videoClient.ts` returns it.
Destination calendar without credentialId never matched; event created on "primary" — `DestinationCalendar.credentialId` is nullable (see `schema.prisma`), so destinations without one never match and events are silently created on `"primary"`, breaking the follow-up `hangoutLink` patch. Fall back to the first destination calendar's `externalId` when no match is found.
Duplicate events when destinations share integration without credentialId — For collective events with several destinations of the same credential-less integration, the no-credentialId branch in `createAllCalendarEvents` re-runs the same credentials per destination, creating duplicate events on one calendar. Deduplicate credentials across destinations, e.g. with a Set of used credential ids.
Sequential createEvent awaits make booking latency scale with host count — Resolve the per-destination creations with `Promise.all`, as the no-credentialId branch already does.
Recurring-event deletion sweep re-runs for every calendar reference, duplicating delete calls — The recurring-event sweep never reads `reference`, yet it re-runs per calendar reference, multiplying delete API calls and re-deleting already-removed events. Hoist this block out of the per-reference loop since its inputs don't depend on it.
Reschedule merge path deletes only first old calendar reference, orphaning others — On reschedules with `newBookingId`, the merge path still deletes only the first old calendar reference via `booking.references.find(...)`, leaving other hosts' events orphaned with stale times. Iterate all old `_calendar` references for deletion, mirroring the per-reference loop added here.