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