Amazon Ergo 1.0 · 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 Opus 5.5.

Gold bugs found
11 of 20
Comments published
12
Comments matching a bug
11
Comments not matching
1
Cost of this PR
$4.833

Published comments (12)

mediumbugpackages/features/bookings/lib/handleCancelBooking.ts:449-460

Recurring cancellation ignores `reference` and uses organizer credentials — Recurring collective cancellations leave other hosts' calendar events behind. Delete through each current `reference`, using its `credentialId`, `uid`, and `externalCalendarId` and the DB-fetched credential when needed, rather than scanning only `bookingToDelete.user.credentials`.

mediumbugpackages/core/EventManager.ts:169-170

Video booking references lose the credential that owns the meeting — Without `credentialId`, cancellation and rescheduling can fail to select the credential that owns the meeting, especially for collective hosts. Persist `result.credentialId` on video references so `bookingVideoReference.credentialId` retains the ID returned by `createVideoEvent`.

mediumbugpackages/core/EventManager.ts:511-542

`credential` leaks across `calendarReference` iterations — A missing credential can reuse the previous iteration's value, updating or deleting the wrong calendar event, or call `updateEvent` with `undefined` on the first pass. Reset `credential` inside the loop and skip or fail that reference when neither `this.calendarCredentials` nor the Prisma lookup provides one with `app.slug`.

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

Collective host destination calendars are dropped when defaults are null — With both default calendars null, the optional push silently drops collective hosts' destination calendars, leaving only the organizer's credentials in `createAllCalendarEvents`. Initialize `evt.destinationCalendar` from `evt.destinationCalendar ?? []` before appending `teamDestinationCalendars`.

mediumsecuritypackages/features/bookings/lib/handleNewBooking.ts:757-761

Prisma error details are exposed to booking API callers — Copying `error.message` from a `Prisma.PrismaClientKnownRequestError` can expose query, schema, and database internals to booking API callers. Log the original error server-side and return `Unable to load users`, while rethrowing existing `HttpError` instances unchanged.

mediumbugpackages/core/EventManager.ts:118-119

Google Meet fallback throws when no destination calendar exists — When `evt.destinationCalendar` is null or empty, dereferencing `mainHostDestinationCalendar.integration` throws instead of falling back to Cal Video. Use optional chaining on `mainHostDestinationCalendar?.integration` so the Google Meet condition remains true.

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

Delete fallback never resolves the destination calendar — Without an `externalCalendarId`, comparing it with `cal.externalId` cannot resolve the destination calendar, leaving `calendarId` undefined and failing the delete; `updateEvent` repeats the bug. Use `event.destinationCalendar?.[0]?.externalId` in both fallbacks. **Also found in:** - `packages/app-store/googlecalendar/lib/CalendarService.ts:254-256`

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

Destination calendars without `credentialId` silently use `primary` — Destination calendars stored without `credentialId` never match, so the `selectedCalendar` fallback inserts the event into `primary` instead of the configured calendar. Fall back to the first destination calendar's `externalId`, preserving the legacy shape handled by `EventManager.createAllCalendarEvents`.

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

createEvent now selects the target calendar only via `cal.credentialId === credentialId` — For destination calendars with null `credentialId`, `EventManager.createAllCalendarEvents` calls `createEvent` for every integration credential, but none can match, so events land in `primary`. Fall back to `mainHostDestinationCalendar?.externalId` when `cal.credentialId === credentialId` finds nothing.

mediumbugpackages/core/EventManager.ts:376-380

This fallback branch calls `createEvent(c, event)` without `destination.externalId` — For destination calendars without `credentialId`, the resulting booking reference persists a null `externalCalendarId`, so later updates and deletes cannot find the calendar. Pass `destination.externalId` through this `createEvent(c, event)` fallback so it is returned and stored on the reference.

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

Slug condition polarity is inverted — With billing enabled, both `slug` and `requestedSlug` are written; with it disabled, neither slug is written, breaking organization creation in both modes. Restore `!IS_TEAM_BILLING_ENABLED` so `slug` is included only when team billing is disabled.

mediumbugpackages/app-store/larkcalendar/lib/CalendarService.ts:128-129

createEvent uses the first destination calendar for every credential — A collective host whose Lark destination is not first can have its event created with another host's calendar ID, causing an API failure or wrong-calendar placement. Select the `event.destinationCalendar` entry whose `credentialId` matches the active credential instead of always using `event.destinationCalendar[0]`. **Also found in:** - `packages/lib/CalendarService.ts:156-164`

Gold bugs found (11)

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.
mediumClaims updateAllCalendarEvents passes an undefined credential to updateEvent when reference.credentialId points to a credential that cannot be found.
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.
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.
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.
mediumloadUsers forwards raw Prisma error messages to the client in a 400 response, exposing internal model and query details.

Gold bugs missed (9)

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