GLM-5.3 · Heavy

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

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

The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Haiku 5.5.

Gold bugs found
6 of 9
Comments published
18
Comments matching a bug
6
Comments not matching
12
Cost of this PR
$3.933

Published comments (18)

highbugpackages/app-store/googlecalendar/lib/CalendarService.ts:147-154

Null credentialId destinations fall back to "primary" instead of configured externalId — Matching the destination by `cal.credentialId === credentialId` never matches `DestinationCalendar` rows with a null credentialId (nullable in schema.prisma:159, and EventManager.createAllCalendarEvents:375-381 explicitly handles such destinations by passing every matching credential). Those bookings now fall back to `"primary"` instead of the configured `destination.externalId`, creating the event on the wrong calendar — previously the code used `destinationCalendar.externalId` directly.

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

Inverted condition writes slug on billing instances and omits it on non-billing ones — The ternary rewrite inverted the condition. The old `...(!IS_TEAM_BILLING_ENABLED && { slug })` included `slug` only when team billing is DISABLED; the new `...(IS_TEAM_BILLING_ENABLED ? { slug } : {})` includes it only when billing is ENABLED — the exact opposite.

highbugpackages/core/EventManager.ts:118-121

Unguarded access to mainHostDestinationCalendar.integration crashes bookings without destination… — `mainHostDestinationCalendar.integration` is dereferenced without a null guard, but `destinationCalendar` is explicitly `null` (handleNewBooking.ts:1063-1067) or `[]` (confirm/webhook/paypal handlers) when no destination calendar exists, so `mainHostDestinationCalendar` is undefined. Any booking with Google Meet as location and no destination calendar — the exact case this fallback exists for — now throws `TypeError: Cannot read properties of undefined (reading 'integration')` and the booking fails with a 500.

highbugpackages/core/EventManager.ts:118-119

Unguarded dereference of possibly-undefined destinationCalendar element throws TypeError — Unguarded dereference of a possibly-undefined element: `const [mainHostDestinationCalendar] = evt.destinationCalendar ?? []` yields `undefined` when destinationCalendar is null or an empty array — both now produced by callers (handleNewBooking passes `null` when neither event type nor organizer has a destination calendar; webhook.ts, paypal-webhook.ts and confirm.handler pass `[]`). Line 119 then reads `mainHostDestinationCalendar.integration` without optional chaining, throwing a TypeError whenever the location is Google Meet, whereas the replaced code (`evt.destinationCalendar?.integration !== "google_calendar"`) evaluated safely and fell back to Cal Video.

highbugpackages/trpc/server/routers/viewer/organizations/create.handler.ts:148-156

Inverted IS_TEAM_BILLING_ENABLED condition sets slug on wrong path — The rewrite of `...(!IS_TEAM_BILLING_ENABLED && { slug })` into `...(IS_TEAM_BILLING_ENABLED ? { slug } : {})` inverts the condition: when team billing is disabled organizations are now created with a null slug (Team.slug is nullable, so no crash, but the org has no usable slug for routing/lookup), and when it is enabled the real slug is written immediately, bypassing the requestedSlug approval metadata flow. Restore the original negated condition.

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

Inverted condition sets org slug only when team billing is enabled — At line 151 the condition was inverted from `!IS_TEAM_BILLING_ENABLED && { slug }` to `IS_TEAM_BILLING_ENABLED ? { slug } : {}`, which is inconsistent with the unchanged `requestedSlug` metadata line at 153. This logic inversion affects when the org slug (identity) is set directly vs. deferred for verification.

highbugpackages/app-store/googlecalendar/lib/CalendarService.ts:147-154

createEvent ignores destination calendars with null credentialId and falls back to "primary" — createEvent now resolves the target calendar only via `destinationCalendar.find((cal) => cal.credentialId === credentialId)`. DestinationCalendar rows with a null credentialId — a case this PR explicitly still supports in EventManager by filtering credentials by integration type and calling createEvent for each — never match, so the event is silently created on `"primary"` instead of the configured destination calendar's externalId, which the old code used whenever it was set.

highbugpackages/app-store/office365calendar/lib/CalendarService.ts:73-77

createEvent posts to first destination calendar regardless of credential match — Office365CalendarService (and likewise LarkCalendarService:128-129/164-165 and BaseCalendarService in packages/lib/CalendarService.ts:156-164) only ever consult `destinationCalendar[0]`, but with the new multi-destination collective flow a secondary host's credential is paired with the first host's `externalId` (often a Google calendar id), so the POST targets `/me/calendars/<wrong-id>/events` and fails — the event is never created on that host's calendar (CalDAV variants filter out all calendars and create nothing). Match the destination whose credentialId equals the current credential, as GoogleCalendarService.createEvent attempts to do.

highbugpackages/core/CalendarManager.ts:218-224

Per-destination externalId is never used to steer event creation — The new `externalId` parameter is declared and passed per-destination from EventManager.createAllCalendarEvents (`createEvent(credential, event, destination.externalId)`), but it is only echoed back in the return object — it is never forwarded to the calendar service. GoogleCalendarService re-derives the target calendar from credentialId, but the other services updated in this PR (office365, lark, BaseCalendarService) still select only the FIRST element of `event.destinationCalendar`.

highbugpackages/lib/CalendarService.ts:156-165

createEvent uses first host's destination calendar, skipping other hosts' calendars — BaseCalendarService.createEvent assumes destinationCalendar[0] (mainHostDestinationCalendar) is the calendar relevant to the current call, but with the new array model EventManager.createAllCalendarEvents creates one event per destination using each host's own credential. For any non-first host (collective events push team members' destinationCalendars after the organizer's), filtering that host's calendars by the first host's externalId matches nothing, so the event is never created on that host's calendar.

highbugpackages/app-store/office365calendar/lib/CalendarService.ts:72-77

createEvent uses first destination calendar instead of matching credentialId — office365calendar's createEvent still has signature (event: CalendarEvent) and picks the target calendar from destinationCalendar[0] (mainHostDestinationCalendar?.externalId). It does not hold up what the other changed hunks now assume: packages/types/Calendar.d.ts:221 makes credentialId a required part of the createEvent contract precisely so each service selects the destination entry matching its own credential (Google's implementation does this), and handleNewBooking.ts now pushes every COLLECTIVE host's destinationCalendar into the array, with EventManager.createAllCalendarEvents invoking createEvent once per host's credential.

highbugpackages/app-store/larkcalendar/lib/CalendarService.ts:125-129

Lark createEvent ignores credentialId and always writes to first host's destination calendar — larkcalendar's createEvent has the same disagreement with the rest of the PR: it takes only (event: CalendarEvent) and derives calendarId from destinationCalendar[0] (mainHostDestinationCalendar?.externalId), ignoring the credentialId that CalendarManager now passes per the new Calendar interface contract (packages/types/Calendar.d.ts:221). Since handleNewBooking.ts now produces arrays containing every COLLECTIVE host's destinationCalendar, Lark will write each host's event to the first host's calendar (or throw "no calendar id" when the first entry is absent even though a destination matching this credential exists), instead of the calendar belonging to the credential being used.

highbugpackages/core/EventManager.ts:511-542

Undefined or stale credential passed to updateEvent for calendar references — `credential` is declared outside the new per-reference loop (line 479-480) and is only assigned when a reference's credentialId resolves; `this.calendarCredentials` contains only the organizer's personal and team credentials (getAllCredentials), so secondary hosts' references rely on the DB fetch, and when that fetch returns null or a credential without `app.slug` the loop silently reuses the previous reference's credential — updating the wrong account/calendar — or stays `undefined`, causing a TypeError at `credential.appName` in CalendarManager.updateEvent. Reset `credential` to undefined at the top of each iteration and skip (or fail) the reference when resolution fails.

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

Recurring cancellation reuses organizer credentials and duplicates delete calls — The recurring-event deletion block was moved inside the new per-reference loop but ignores the current `reference` and its resolved `calendarCredential`, instead re-iterating all of `bookingToDelete.user.credentials` (the organizer's credentials only). For multi-reference bookings introduced by this PR the block runs once per calendar reference — duplicating every delete call (subsequent passes hit 404/410) — and secondary hosts' calendar events are never deleted because their credentials are not in the organizer's user credentials, leaving stale events on their calendars.

mediumbugpackages/core/EventManager.ts:169-171

Video references persisted without credentialId, leaking video rooms on cancellation — New bookings' video references are persisted without a credentialId because the video branch now writes `undefined` instead of `result.credentialId`, which `createMeeting` populates (packages/core/videoClient.ts:78); handleCancelBooking.ts:491-503 only calls `deleteMeeting` when `bookingVideoReference.credentialId` is set, so every booking created after this change leaks its video room (e.g., Daily) on cancellation. Restore `result.credentialId` as the value for non-calendar results.

mediumbugpackages/core/EventManager.ts:208-210

updateLocation stores calendar references with null routing data from updateEvent — updateLocation now builds calendar references from `result.externalId` and `result.credentialId`, but `CalendarManager.updateEvent` (packages/core/CalendarManager.ts:313-322) returns neither field — only `createEvent` was updated to return them — and the old fallbacks to `evt.destinationCalendar` were removed, so the references persisted by editLocation.handler.ts:120 are stored with null credentialId and null externalCalendarId. Have `updateEvent` return `credential.id` and the `externalCalendarId` parameter, mirroring the `createEvent` changes, so updateLocation's references keep their routing data.

mediumperformancepackages/core/EventManager.ts:339-374

Sequential per-destination awaits make collective booking latency scale with host count — The new per-destination loop awaits each `prisma.credential.findUnique` and each `createEvent` sequentially, so a collective booking performs one full Google/Office365 network round trip per host in series, making booking-creation latency grow linearly with host count. Build the per-destination promises and settle them with `Promise.all`, as the adjacent other_calendar loop (lines 399-405) already does.

mediumsecuritypackages/app-store/googlecalendar/lib/CalendarService.ts:256

updateEvent fallback compares externalId against falsy externalCalendarId, always undefined — This is a dead/ineffective fallback that regresses the previous `destinationCalendar?.externalId` behavior. **Also found in:** - `packages/app-store/googlecalendar/lib/CalendarService.ts:314-317` - `packages/app-store/googlecalendar/lib/CalendarService.ts:315-317` - `packages/app-store/googlecalendar/lib/CalendarService.ts:317-317` - `packages/core/EventManager.ts:379-381` - `packages/core/EventManager.ts:376-381`

Gold bugs found (6)

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

Gold bugs missed (3)

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