fix: handle collective multiple host on destinationCalendar
Tier 2 hard typescript · local · real merged PR from calcom/cal.com #10967
Ground-truth defects
Potential null reference if mainHostDestinationCalendar is undefined if evt.destinationCalendar is null or an empty array
Logic error: when externalCalendarId is provided, you're searching for a calendar where externalId === externalCalendarId, but this will always fail since you're looking for a calendar that matches itself. Should likely find by credentialId or use different logic.
Logic inversion in organization creation: The slug property is now conditionally set when IS_TEAM_BILLING_ENABLED is true, instead of when it's false as originally intended. This change, combined with requestedSlug still being set when IS_TEAM_BILLING_ENABLED is true, results in both properties being set when billing is enabled, and neither when disabled
At handleNewBooking.ts:1063-1067 evt.destinationCalendar is set to null when neither eventType nor organizerUser has a destinationCalendar, so the COLLECTIVE branch's `evt.destinationCalendar?.push(...teamDestinationCalendars)` (line 1078) short-circuits to a no-op, silently discarding all team members' destinationCalendars and producing no calendar events for them.
EventManager.ts:170 now writes credentialId: undefined for video booking references (was result.credentialId from videoClient.ts:78), so handleCancelBooking.ts:491's `if (bookingVideoReference.credentialId)` guard is always false and the external video meeting is never deleted on cancellation.
The interface gains `createEvent(event, credentialId)` and Google selects its calendar by matching that credential, but the Office365 (and Lark) implementation still destructures `const [mainHostDestinationCalendar] = event.destinationCalendar ?? []` and builds the request path from element zero, ignoring the credential. `EventManager.createAllCalendarEvents` now loops once per host credential, so every iteration writes to the organizer's calendar id under a different member's token.
The diff converts the outer cancellation lookup from `find` to `filter` and loops over every calendar reference, but the recurring branch still resolves a single reference with `references.find((ref) => ref.type.includes('_calendar'))` and iterates only the organizer's credentials. For each remaining occurrence only the first reference is deleted and only with the organizer's credentials, so team members' calendar events survive the cancellation.
The change under review
diff (truncated — full diff)
@@ -104,7 +104,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) }); const attendeesList = await Promise.all(attendeesListPromises); - + const selectedDestinationCalendar = booking.destinationCalendar || user.destinationCalendar; const evt: CalendarEvent = { type: booking.title, title: booking.title, @@ -127,7 +127,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) attendees: attendeesList, uid: booking.uid, recurringEvent: parseRecurringEvent(booking.eventType?.recurringEvent), - destinationCalendar: booking.destinationCalendar || user.destinationCalendar, + destinationCalendar: selectedDestinationCalendar ? [selectedDestinationCalendar] : [], }; await sendOrganizerRequestReminderEmail(evt); @@ -246,7 +246,7 @@ test.describe("BOOKING_REJECTED", async () => { }, ], location: "[redacted/dynamic]", - destinationCalendar: null, + destinationCalendar: [], // hideCalendarNotes: false, requiresConfirmation: "[redacted/dynamic]", eventTypeId: "[redacted/dynamic]", @@ -84,7 +84,7 @@ export default class GoogleCalendarService implements Calendar { }; }; - async createEvent(calEventRaw: CalendarEvent): Promise<NewCalendarEventType> { + async createEvent(calEventRaw: CalendarEvent, credentialId: number): Promise<NewCalendarEventType> { const eventAttendees = calEventRaw.attendees.map(({ id: _id, ...rest }) => ({ ...rest, responseStatus: "accepted", @@ -97,6 +97,10 @@ export default class GoogleCalendarService implements Calendar { responseStatus: "accepted", })) || []; return new Promise(async (resolve, reject) => { + const [mainHostDestinationCalendar] = + calEventRaw?.destinationCalendar && calEventRaw?.destinationCalendar.length > 0 + ? calEventRaw.destinationCalendar + : []; const myGoogleAuth = await this.auth.getToken(); const payload: calendar_v3.Schema$Event = { summary: calEventRaw.title, @@ -115,8 +119,8 @@ export default class GoogleCalendarService implements Calendar { id: String(calEventRaw.organizer.id), responseStatus: "accepted", organizer: true, - email: calEventRaw.destinationCalendar?.externalId - ? calEventRaw.destinationCalendar.externalId + email: mainHostDestinationCalendar?.externalId + ? mainHostDestinationCalendar.externalId : calEventRaw.organizer.email, }, ...eventAttendees, @@ -138,13 +142,16 @@ export default class GoogleCalendarService implements Calendar { const calendar = google.calendar({ version: "v3", }); - const selectedCalendar = calEventRaw.destinationCalendar?.externalId - ? calEventRaw.destinationCalendar.externalId - : "primary"; + // Find in calEventRaw.destinationCalendar the one with the same credentialId + + const selectedCalendar = calEventRaw.destinationCalendar?.find( + (cal) => cal.credentialId === credentialId + )?.externalId; + calendar.events.insert( { auth: myGoogleAuth, - calendarId: selectedCalendar, + calendarId: selectedCalendar || "primary", requestBody: payload, conferenceDataVersion: 1, sendUpdates: "none", @@ -188,6 +195,8 @@ export default class GoogleCalendarService implements Calendar { async updateEvent(uid: string, event: CalendarEvent, externalCalendarId: string): Promise<any> { return new Promise(async (resolve, reject) => { + const [mainHostDestinationCalendar] = + event?.destinationCalendar && event?.destinationCalendar.length > 0 ? event.destinationCalendar : []; const myGoogleAuth = await this.auth.getToken(); const eventAttendees = event.attendees.map(({ ...rest }) => ({ ...rest, @@ -216,8 +225,8 @@ export default class GoogleCalendarService implements Calendar { id: String(event.organizer.id), organizer: true, responseStatus: "accepted", - email: event.destinationCalendar?.externalId - ? event.destinationCalendar.externalId + email: mainHostDestinationCalendar?.externalId + ? mainHostDestinationCalendar.externalId : event.organizer.email, }, ...(eventAttendees as any), @@ -244,7 +253,7 @@ export default class GoogleCalendarService implements Calendar { const selectedCalendar = externalCalendarId ? externalCalendarId - : event.destinationCalendar?.externalId; + : event.destinationCalendar?.find((cal) => cal.externalId === externalCalendarId)?.externalId; calendar.events.update( { @@ -303,7 +312,9 @@ export default class GoogleCalendarService implements Calendar { }); const defaultCalendarId = "primary"; - const calendarId = externalCalendarId ? externalCalendarId : event.destinationCalendar?.externalId; + const calendarId = externalCalendarId + ? externalCalendarId + : event.destinationCalendar?.find((cal) => cal.externalId === externalCalendarId)?.externalId; calendar.events.delete( { @@ -125,7 +125,8 @@ export default class LarkCalendarService implements Calendar { async createEvent(event: CalendarEvent): Promise<NewCalendarEventType> { let eventId = ""; let eventRespData; - const calendarId = event.destinationCalendar?.externalId; + const [mainHostDestinationCalendar] = event.destinationCalendar ?? []; + const calendarId = mainHostDestinationCalendar?.externalId; if (!calendarId) { throw new Error("no calendar id"); } @@ -160,7 +161,8 @@ export default class LarkCalendarService implements Calendar { } private createAttendees = async (event: CalendarEvent, eventId: string) => { - const calendarId = event.destinationCalendar?.externalId; + const [mainHostDestinationCalendar] = event.destinationCalendar ?? []; + const calendarId = mainHostDestinationCalendar?.externalId; if (!calendarId) { this.log.error("no calendar id provided in createAttendees"); throw new Error("no calendar id provided in createAttendees"); @@ -187,7 +189,8 @@ export default class LarkCalendarService implements Calendar { async updateEvent(uid: string, event: CalendarEvent, externalCalendarId?: string) { const eventId = uid; let eventRespData; - const calendarId = externalCalendarId || event.destinationCalendar?.externalId; + const [mainHostDestinationCalendar] = event.destinationCalendar ?? []; + const calendarId = externalCalendarId || mainHostDestinationCalendar?.externalId; if (!calendarId) { this.log.error("no calendar id provided in updateEvent"); throw new Error("no calendar id provided in updateEvent"); @@ -231,7 +234,8 @@ export default class LarkCalendarService implements Calendar { * @returns */ async deleteEvent(uid: string, event: CalendarEvent, externalCalendarId?: string) { - const calendarId = externalCalendarId || event.destinationCalendar?.externalId; + const [mainHostDestinationCalendar] = event.destinationCalendar ?? []; + const calendarId = externalCalendarId || mainHostDestinationCalendar?.externalId; if (!calendarId) { this.log.error("no calendar id provided in deleteEvent"); throw new Error("no calendar id provided in deleteEvent"); @@ -70,9 +70,10 @@ export default class Office365CalendarService implements Calendar { } async createEvent(event: CalendarEvent): Promise<NewCalendarEventType> { + const [mainHostDestinationCalendar] = event.destinationCalendar ?? []; try { - const eventsUrl = event.destinationCalendar?.externalId - ? `/me/calendars/${event.destinationCalendar?.externalId}/events` + const eventsUrl = mainHostDestinationCalendar?.externalId + ? `/me/calendars/${mainHostDestinationCalendar?.externalId}/events` : "/me/calendar/events"; const response = await this.fetcher(eventsUrl, { @@ -217,7 +217,8 @@ export const getBusyCalendarTimes = async ( export const createEvent = async ( credential: CredentialWithAppName, - calEvent: CalendarEvent + calEvent: CalendarEvent, + externalId?: string ): Promise<EventResult<NewCalendarEventType>> => { const uid: string = getUid(calEvent); const calendar = await getCalendar(credential); @@ -226,29 +227,31 @@ export const createEvent = async ( // Check if the disabledNotes flag is set to true if (calEvent.hideCalendarNotes) { - calEvent.additionalNotes = "Notes have been hidden by the organiser"; // TODO: i18n this string? + calEvent.additionalNotes = "Notes have been hidden by the organizer"; // TODO: i18n this string? } // TODO: Surface success/error messages coming from apps to improve end user visibility const creationResult = calendar - ? await calendar.createEvent(calEvent).catch(async (error: { code: number; calError: string }) => { - success = false; - /** - * There is a time when selectedCalendar externalId doesn't match witch certain credential - * so google returns 404. - * */ - if (error?.code === 404) { + ? await calendar + .createEvent(calEvent, credential.id) + .catch(async (error: { code: number; calError: string }) => { + success = false; + /** + * There is a time when selectedCalendar externalId doesn't match witch certain credential + * so google returns 404. + * */ + if (error?.code === 404) { + return undefined; + } + if (error?.calError) { + calError = error.calError; + } + log.error("createEvent failed", JSON.stringify(error), calEvent); + // @TODO: This code will be off till we can investigate an error with it + //https://github.com/calcom/cal.com/issues/3949 + // await sendBrokenIntegrationEmail(calEvent, "calendar"); return undefined; - } - if (error?.calError) { - calError = error.calError; - } - log.error("createEvent failed", JSON.stringify(error), calEvent); - // @TODO: This code will be off till we can investigate an error with it - //https://github.com/calcom/cal.com/issues/3949 - // await sendBrokenIntegrationEmail(calEvent, "calendar"); - return undefined; - }) + }) : undefined; return { @@ -261,6 +264,8 @@ export const createEvent = async ( originalEvent: calEvent, calError, calWarnings: creationResult?.additionalInfo?.calWarnings || [], + externalId, + credentialId: credential.id, }; }; @@ -114,7 +114,9 @@ export default class EventManager { } // Fallback to Cal Video if Google Meet is selected w/o a Google Cal - if (evt.location === MeetLocationType && evt.destinationCalendar?.integration !== "google_calendar") { + // @NOTE: destinationCalendar it's an array now so as a fallback we will only check the first one + const [mainHostDestinationCalendar] = evt.destinationCalendar ?? []; + if (evt.location === MeetLocationType && mainHostDestinationCalendar.integration !== "google_calendar") { evt["location"] = "integrations:daily"; } const isDedicated = evt.location ? isDedicatedIntegration(evt.location) : null; @@ -164,8 +166,8 @@ export default class EventManager { meetingId: createdEventObj ? createdEventObj.id : result.createdEvent?.id?.toString(), meetingPassword: createdEventObj ? createdEventObj.password : result.createdEvent?.password, meetingUrl: createdEventObj ? createdEventObj.onlineMeetingUrl : result.createdEvent?.url, - externalCalendarId: isCalendarType ? evt.destinationCalendar?.externalId : undefined, - credentialId: isCalendarType ? evt.destinationCalendar?.credentialId : result.credentialId, + externalCalendarId: isCalendarType ? result.externalId : undefined, + credentialId: isCalendarType ? result.credentialId : undefined, }; }); @@ -203,8 +205,8 @@ export default class EventManager { meetingId: result.createdEvent?.id?.toString(), meetingPassword: result.createdEvent?.password, meetingUrl: result.createdEvent?.url, - externalCalendarId: evt.destinationCalendar?.externalId, - credentialId: result.credentialId ?? evt.destinationCalendar?.credentialId, + externalCalendarId: result.externalId, + credentialId: result.credentialId ?? undefined, }; }); @@ -332,29 +334,52 @@ export default class EventManager { * @private */ private async createAllCalendarEvents(event: CalendarEvent) { - /** Can I use destinationCalendar here? */ - /* How can I link a DC to a cred? */ - let createdEvents: EventResult<NewCalendarEventType>[] = []; - if (event.destinationCalendar) { - if (event.destinationCalendar.credentialId) { - const credential = this.calendarCredentials.find( - (c) => c.id === event.destinationCalendar?.credentialId - ); - - if (credential) { - const createdEvent = await createEvent(credential, event); - if (createdEvent) { - createdEvents.push(createdEvent); + if (event.destinationCalendar && event.destinationCalendar.length > 0) { + for (const destination of event.destinationCalendar) { + if (destination.credentialId) { + let credential = this.calendarCredentials.find((c) => c.id === destination.credentialId); + if (!credential) { + // Fetch credential from DB + const credentialFromDB = await prisma.credential.findUnique({ + include: { + app: { + select: { + slug: true, + }, + }, + }, + where: { + id: destination.credentialId, + }, + }); + if (credentialFromDB && credentialFromDB.app?.slug) { + credential = { + appName: credentialFromDB?.app.slug ?? "", + id: credentialFromDB.id, + type: credentialFromDB.type, + key: credentialFromDB.key, + userId: credentialFromDB.userId, + teamId: credentialFromDB.teamId, + invalid: credentialFromDB.invalid, + appId: credentialFromDB.appId, + }; + } + } + if (credential) { + const createdEvent = await createEvent(credential, event, destination.externalId); + if (createdEvent) { + createdEvents.push(createdEvent); + } } + } else { + const destinationCalendarCredentials = this.calendarCredentials.filter( + (c) => c.type === destination.integration + ); + createdEvents = createdEvents.concat( + await Promise.all(destinationCalendarCredentials.map(async (c) => await createEvent(c, event))) + ); } - } else { - const destinationCalendarCredentials = this.calendarCredentials.filter( - (c) => c.type === event.destinationCalendar?.integration - ); - createdEvents = createdEvents.concat( - await Promise.all(destinationCalendarCredentials.map(async (c) => await createEvent(c, event))) - ); } } else { /** @@ -451,7 +476,7 @@ export default class EventManager { booking: PartialBooking, newBookingId?: number ): Promise<Array<EventResult<NewCalendarEventType>>> { - let calendarReference: PartialReference | undefined = undefined, + let calendarReference: PartialReference[] | undefined = undefined, credential; try { // If a newBookingId is given, update that calendar event @@ -468,33 +493,62 @@ export default class EventManager { } calendarReference = newBooking?.references.length - ? newBooking.references.find((reference) => reference.type.includes("_calendar")) - : booking.references.find((reference) => reference.type.includes("_calendar")); + ? newBooking.references.filter((reference) => reference.type.includes("_calendar")) + : booking.references.filter((reference) => reference.type.includes("_calendar")); - if (!calendarReference) { + if (calendarReference.length === 0) { return []; } - const { uid: bookingRefUid, externalCalendarId: bookingExternalCalendarId } = calendarReference; - let calenderExternalId: string | null = null; - if (bookingExternalCalendarId) { - calenderExternalId = bookingExternalCalendarId; - } - + // process all calendar references let result = []; - if (calendarReference.credentialId) { - credential = this.calendarCredentials.filter( - (credential) => credential.id === calendarReference?.credentialId - )[0]; - result.push(updateEvent(credential, event, bookingRefUid, calenderExternalId)); - } else { - const credentials = this.calendarCredentials.filter( - (credential) => credential.type === calendarReference?.type - ); - for (const credential of credentials) { + for (const reference of calendarReference) { + const { uid: bookingRefUid, externalCalendarId: bookingExternalCalendarId } = reference; + let calenderExternalId: string | null = null; + if (bookingExternalCalendarId) { + calenderExternalId = bookingExternalCalendarId; + } + + if (reference.credentialId) { + credential = this.calendarCredentials.filter( + (credential) => credential.id === reference?.credentialId + )[0]; + if (!credential) { + // Fetch credential from DB + const credentialFromDB = await prisma.credential.findUnique({ + include: { + app: { + select: { + slug: true, + }, + }, + }, + where: { + id: reference.credentialId, + }, + }); + if (credentialFromDB && credentialFromDB.app?.slug) { + credential = { + appName: credentialFromDB?.app.slug ?? "", + id: credentialFromDB.id, + type: credentialFromDB.type, + key: credentialFromDB.key, + userId: credentialFromDB.userId, + teamId: credentialFromDB.teamId, + invalid: credentialFromDB.invalid, + appId: credentialFromDB.appId, + }; + } + } result.push(updateEvent(credential, event, bookingRefUid, calenderExternalId)); + } else { + const credentials = this.calendarCredentials.filter( + (credential) => credential.type === reference?.type + ); + for (const credential of credentials) { + result.push(updateEvent(credential, event, bookingRefUid, calenderExternalId)); + } } } - // If we are merging two calendar events we should delete the old calendar event if (newBookingId) { const oldCalendarEvent = booking.references.find((reference) => reference.type.includes("_calendar")); @@ -516,17 +570,17 @@ export default class EventManager { .filter((cred) => cred.type.includes("other_calendar")) .map(async (cred) => { const calendarReference = booking.references.find((ref) => ref.type === cred.type); - if (!calendarReference) - if (!calendarReference) { - return { - appName: cred.appName, - type: cred.type, - success: false, - uid: "", - originalEvent: event, - credentialId: cred.id, - }; - } + + if (!calendarReference) { + return { + appName: cred.appName, + type: cred.type, + success: false, + uid: "", + originalEvent: event, + credentialId: cred.id, + }; + } const { externalCalendarId: bookingExternalCalendarId, meetingId: bookingRefUid } = calendarReference; return await updateEvent(cred, event, bookingRefUid ?? null, bookingExternalCalendarId ?? null); @@ -539,17 +593,19 @@ export default class EventManager { if (error instanceof Error) { message = message.replace("{thing}", error.message); }
Leaderboard for this case
hard · 2 of 9 bots fully caught it (22% solve rate) · 73% avg coverage.
| # | Bot | Result | Caught | Coverage | Findings | False alarms |
|---|---|---|---|---|---|---|
| 1 | cursor | solved | 7/7 | 100.0% | 7 | 0 |
| 2 | Drape (Deep Review) | solved | 7/7 | 100.0% | 15 | 0 |
| 3 | Drape (Review) | partial | 6/7 | 90.9% | 13 | 0 |
| 4 | Mjolnir (Opus 5.5) | partial | 6/7 | 90.9% | 10 | 0 |
| 5 | Cubic | partial | 6/7 | 81.8% | 15 | 0 |
| 6 | Claude Code (Opus 5.5) | partial | 5/7 | 81.8% | 6 | 1 |
| 7 | Mjolnir (Sonnet 5.5) | partial | 5/7 | 72.7% | 12 | 0 |
| 8 | greptile | partial | 4/7 | 54.5% | 6 | 0 |
| 9 | qodo | miss | 0/7 | 0.0% | 0 | 0 |
Bot results
Claude Code (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
| d3 | medium | ✓ | exact |
| d4 | high | ✓ | exact |
| d5 | high | ✓ | off by one |
| d6 | high | ✓ | off by one |
| d7 | medium | ✗ | — |
| d8 | medium | ✗ | — |
The select was removed, but nothing downstream reads user.organization. handleNewBooking has no `.organization` reads, getUserAvailability never touches organization, and getBookerUrl uses organizationId, which userSelect still selects. So the claimed downstream failure doesn't happen. [invalid: contradiction] [consensus 3/3: invalid=3]
raw comments (6)
`mainHostDestinationCalendar.integration` has no optional chaining. `evt.destinationCalendar` can be null or `[]`: handleNewBooking sets it to null when neither the event type nor the organizer has a destination calendar, and many other callers now pass `[]`. Then `mainHostDestinationCalendar` is undefined, so any booking with a Google Meet location and no destination calendar throws a TypeError in EventManager.create instead of falling back to Cal Video.
The slug logic is inverted. Before, `slug` was set only when team billing was disabled, and `requestedSlug` was stored in metadata when billing was enabled, so the slug was claimed after payment. Now, with billing enabled, the slug is assigned right away without payment or verification; with billing disabled, the organization is created with no slug at all. Self-hosted orgs break, and the billing flow can be bypassed.
`destinationCalendar` is set to `null` (not `[]`) when neither the event type nor the organizer has a destination calendar. So `evt.destinationCalendar?.push(...teamDestinationCalendars)` silently does nothing, and in COLLECTIVE events the other hosts' destination calendars are dropped whenever the organizer has none. This null also triggers the crash in EventManager line 119.
Booking references for non-calendar integrations (video) used to store `result.credentialId`; now they store `undefined`. Video references lose their credentialId, so later updates and deletes of the meeting can't find the right conferencing credential (for example, after a reschedule, or when there are several credentials of one type).
This fallback runs only when `externalCalendarId` is falsy, but it then searches for `cal.externalId === externalCalendarId` (null or undefined), so it never matches and always returns undefined. Before, it fell back to the destination calendar's externalId. Updates (and deletes, line 317) for references without a stored externalCalendarId now get an undefined calendarId and fail or hit the wrong calendar.
The `organization: { select: { slug } }` selection was removed from the dynamic-users query in loadUsers. Dynamic-group users are now missing the organization data that host-based users still carry, so downstream code that reads `user.organization` (org-aware URLs, emails) gets undefined for dynamic bookings.
Cubic · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
| d3 | medium | ✓ | off by one |
| d4 | high | ✓ | exact |
| d5 | high | ✓ | off by one |
| d6 | high | ✗ | — |
| d7 | medium | ✓ | off by one |
| d8 | medium | ✓ | off by one |
Change made update handle all calendar references but left the merge-delete path using find, so only the first old calendar event is deleted; incomplete change. [grounded: tree packages/core/EventManager.ts] [consensus 5/5: valid=5]
externalCalendarId now comes from result.externalId, which is undefined in this branch; previously it was evt.destinationCalendar?.externalId. [grounded: diff] [consensus 5/5: valid=5]
CalendarManager.updateEvent returns neither externalId nor credentialId, so references created in updateLocation lose these fields that were previously taken from evt.destinationCalendar. [grounded: diff] [consensus 5/5: valid=5]
Filter now includes *_other_calendar refs which get updated in the loop and again by the dedicated other_calendar block, causing duplicate updates. [grounded: diff] [consensus 5/5: valid=5]
EventManager calls createEvent per destination with full array; Office365/Lark always use element 0, targeting the organizer's calendar ID with teammates' credentials. [grounded: diff] [consensus 5/5: valid=5]
Lark always uses the first destination's calendar for every credential invocation, so teammates' calendars are not targeted. [grounded: tree packages/app-store/larkcalendar/lib/CalendarService.ts] [consensus 5/5: valid=5]
For a teammate's CalDAV credential, filtering by the organizer's externalId matches nothing, so no event is created yet success is returned. [grounded: tree packages/lib/CalendarService.ts] [consensus 5/5: valid=5]
Previously selectedCalendar always defaulted to "primary"; now it can be undefined and the hangout-link patch is sent with undefined calendarId. [grounded: tree packages/app-store/googlecalendar/lib/CalendarService.ts] [consensus 5/5: valid=5]
The recurring all-bookings deletion over all user credentials is now nested inside the per-reference loop, repeating it once per calendar reference. [grounded: diff] [consensus 5/5: valid=5]
raw comments (16)
<!-- cubic:v=eea2f1fb-de72-4a50-b2a8-7011476c6b6a -->
<!-- cubic:review-run=7fabac28-6d54-5e8a-ab2e-9158eb8aa7c6 -->
<!-- metadata:{"confidence":10} -->
P1: This reverses the billing-mode behavior: billing-enabled organizations receive a live `team.slug` before payment, while billing-disabled organizations receive neither a slug nor `requestedSlug`. The latter cannot be published or create subteams; restore the non-billing `{ slug }` branch and keep billing-enabled organizations slugless until upgrade.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At packages/trpc/server/routers/viewer/organizations/create.handler.ts, line 151:
<comment>This reverses the billing-mode behavior: billing-enabled organizations receive a live `team.slug` before payment, while billing-disabled organizations receive neither a slug nor `requestedSlug`. The latter cannot be published or create subteams; restore the non-billing `{ slug }` branch and keep billing-enabled organizations slugless until upgrade.</comment>
<file context>
@@ -148,9 +148,9 @@ export const createHandler = async ({ input, ctx }: CreateOptions) => {
create: {
name,
- ...(!IS_TEAM_BILLING_ENABLED && { slug }),
+ ...(IS_TEAM_BILLING_ENABLED ? { slug } : {}),
metadata: {
- ...(IS_TEAM_BILLING_ENABLED && { requestedSlug: slug }),
</file context>
```
</details>
```suggestion
...(!IS_TEAM_BILLING_ENABLED ? { slug } : {}),
```
<!-- cubic:v=2282bf1b-8181-4434-aade-fa0cda64d0f3 -->
<!-- cubic:review-run=7fabac28-6d54-5e8a-ab2e-9158eb8aa7c6 -->
<!-- metadata:{"confidence":8} -->
P1: When merging bookings with multiple calendar references, only the first old calendar event is deleted, leaving stale events on the remaining calendars. Delete every old calendar reference that is not reused.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At packages/core/EventManager.ts, line 496:
<comment>When merging bookings with multiple calendar references, only the first old calendar event is deleted, leaving stale events on the remaining calendars. Delete every old calendar reference that is not reused.</comment>
<file context>
@@ -468,33 +493,62 @@ export default class EventManager {
calendarReference = newBooking?.references.length
- ? newBooking.references.find((reference) => reference.type.includes("_calendar"))
- : booking.references.find((reference) => reference.type.includes("_calendar"));
+ ? newBooking.references.filter((reference) => reference.type.includes("_calendar"))
+ : booking.references.filter((reference) => reference.type.includes("_calendar"));
</file context>
```
</details>
<!-- cubic:v=ce5ae6b6-266c-4b23-a4d6-89acf6e8fa2b -->
<!-- cubic:review-run=7fabac28-6d54-5e8a-ab2e-9158eb8aa7c6 -->
<!-- metadata:{"confidence":9} -->
P1: When a destination has no `credentialId`, this branch omits its `externalId`, so the booking reference cannot target that calendar during later updates or cancellations. Pass `destination.externalId` to `createEvent`.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At packages/core/EventManager.ts, line 380:
<comment>When a destination has no `credentialId`, this branch omits its `externalId`, so the booking reference cannot target that calendar during later updates or cancellations. Pass `destination.externalId` to `createEvent`.</comment>
<file context>
@@ -332,29 +334,52 @@ export default class EventManager {
+ (c) => c.type === destination.integration
+ );
+ createdEvents = createdEvents.concat(
+ await Promise.all(destinationCalendarCredentials.map(async (c) => await createEvent(c, event)))
+ );
}
</file context>
```
</details>
```suggestion
await Promise.all(
destinationCalendarCredentials.map(async (c) => await createEvent(c, event, destination.externalId))
)
```
<!-- cubic:v=357f07c3-c45b-4796-a2da-2739293c6e0d -->
<!-- cubic:review-run=7fabac28-6d54-5e8a-ab2e-9158eb8aa7c6 -->
<!-- metadata:{"confidence":10} -->
P1: After a location edit, calendar references lose `externalCalendarId` and `credentialId` because `updateEvent` does not return either field. Preserve the corresponding calendar reference metadata when constructing `referencesToCreate`.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At packages/core/EventManager.ts, line 208:
<comment>After a location edit, calendar references lose `externalCalendarId` and `credentialId` because `updateEvent` does not return either field. Preserve the corresponding calendar reference metadata when constructing `referencesToCreate`.</comment>
<file context>
@@ -203,8 +205,8 @@ export default class EventManager {
meetingUrl: result.createdEvent?.url,
- externalCalendarId: evt.destinationCalendar?.externalId,
- credentialId: result.credentialId ?? evt.destinationCalendar?.credentialId,
+ externalCalendarId: result.externalId,
+ credentialId: result.credentialId ?? undefined,
};
</file context>
```
</details>
<!-- cubic:v=ecf10ac1-0c6e-4220-aec2-094e02b5ca60 -->
<!-- cubic:review-run=7fabac28-6d54-5e8a-ab2e-9158eb8aa7c6 -->
<!-- metadata:{"confidence":9} -->
P1: The new all-reference loop also processes `*_other_calendar` references, then the dedicated non-traditional block processes them again. Exclude `other_calendar` references from the first loop or remove the second pass.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At packages/core/EventManager.ts, line 496:
<comment>The new all-reference loop also processes `*_other_calendar` references, then the dedicated non-traditional block processes them again. Exclude `other_calendar` references from the first loop or remove the second pass.</comment>
<file context>
@@ -468,33 +493,62 @@ export default class EventManager {
calendarReference = newBooking?.references.length
- ? newBooking.references.find((reference) => reference.type.includes("_calendar"))
- : booking.references.find((reference) => reference.type.includes("_calendar"));
+ ? newBooking.references.filter((reference) => reference.type.includes("_calendar"))
+ : booking.references.filter((reference) => reference.type.includes("_calendar"));
</file context>
```
</details>
<!-- cubic:v=0e534cd7-d5a5-4738-abcb-ead0f6c8ec88 -->
<!-- cubic:review-run=7fabac28-6d54-5e8a-ab2e-9158eb8aa7c6 -->
<!-- metadata:{"confidence":8} -->
P1: With multiple destinations, Office 365 and Lark receive the full array and always create on its first calendar. Pass an event copy containing only the current `destination` to each calendar call.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At packages/core/EventManager.ts, line 370:
<comment>With multiple destinations, Office 365 and Lark receive the full array and always create on its first calendar. Pass an event copy containing only the current `destination` to each calendar call.</comment>
<file context>
@@ -332,29 +334,52 @@ export default class EventManager {
+ }
+ }
+ if (credential) {
+ const createdEvent = await createEvent(credential, event, destination.externalId);
+ if (createdEvent) {
+ createdEvents.push(createdEvent);
</file context>
```
</details>
<!-- cubic:v=00a13fda-66d7-48a4-96e2-aec2b8472da5 -->
<!-- cubic:review-run=7fabac28-6d54-5e8a-ab2e-9158eb8aa7c6 -->
<!-- metadata:{"confidence":10} -->
P1: When `destinationCalendar` is empty or null, this dereference throws for every Meet event without a configured Google Calendar. Use optional chaining so the existing Cal Video fallback can run.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At packages/core/EventManager.ts, line 119:
<comment>When `destinationCalendar` is empty or null, this dereference throws for every Meet event without a configured Google Calendar. Use optional chaining so the existing Cal Video fallback can run.</comment>
<file context>
@@ -114,7 +114,9 @@ export default class EventManager {
- if (evt.location === MeetLocationType && evt.destinationCalendar?.integration !== "google_calendar") {
+ // @NOTE: destinationCalendar it's an array now so as a fallback we will only check the first one
+ const [mainHostDestinationCalendar] = evt.destinationCalendar ?? [];
+ if (evt.location === MeetLocationType && mainHostDestinationCalendar.integration !== "google_calendar") {
evt["location"] = "integrations:daily";
}
</file context>
```
</details>
```suggestion
if (evt.location === MeetLocationType && mainHostDestinationCalendar?.integration !== "google_calendar") {
```
<!-- cubic:v=0c7c2184-5204-42bc-a72e-7a5e35029230 -->
<!-- cubic:review-run=7fabac28-6d54-5e8a-ab2e-9158eb8aa7c6 -->
<!-- metadata:{"confidence":9} -->
P1: When a collective booking has multiple Lark destination calendars, this always selects the organizer's first calendar even though `EventManager` invokes the service once per destination. The event is therefore duplicated on the first Lark calendar and omitted from teammates' calendars; select the calendar matching the current credential/destination rather than unconditionally taking element 0.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At packages/app-store/larkcalendar/lib/CalendarService.ts, line 128:
<comment>When a collective booking has multiple Lark destination calendars, this always selects the organizer's first calendar even though `EventManager` invokes the service once per destination. The event is therefore duplicated on the first Lark calendar and omitted from teammates' calendars; select the calendar matching the current credential/destination rather than unconditionally taking element 0.</comment>
<file context>
@@ -125,7 +125,8 @@ export default class LarkCalendarService implements Calendar {
let eventId = "";
let eventRespData;
- const calendarId = event.destinationCalendar?.externalId;
+ const [mainHostDestinationCalendar] = event.destinationCalendar ?? [];
+ const calendarId = mainHostDestinationCalendar?.externalId;
if (!calendarId) {
</file context>
```
</details>
<!-- cubic:v=66a420c0-c368-4fdb-9ac6-2a67395ffafe -->
<!-- cubic:review-run=7fabac28-6d54-5e8a-ab2e-9158eb8aa7c6 -->
<!-- metadata:{"confidence":9} -->
P1: When a collective booking has multiple Office 365 destinations, this always selects the host calendar even during later destination iterations. Select the destination matching the credential/current iteration, otherwise team-member events are duplicated in the host calendar or fail with an invalid calendar ID.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At packages/app-store/office365calendar/lib/CalendarService.ts, line 73:
<comment>When a collective booking has multiple Office 365 destinations, this always selects the host calendar even during later destination iterations. Select the destination matching the credential/current iteration, otherwise team-member events are duplicated in the host calendar or fail with an invalid calendar ID.</comment>
<file context>
@@ -70,9 +70,10 @@ export default class Office365CalendarService implements Calendar {
}
async createEvent(event: CalendarEvent): Promise<NewCalendarEventType> {
+ const [mainHostDestinationCalendar] = event.destinationCalendar ?? [];
try {
- const eventsUrl = event.destinationCalendar?.externalId
</file context>
```
</details>
<!-- cubic:v=69893967-46c6-4753-8125-bea68060daf9 -->
<!-- cubic:review-run=7fabac28-6d54-5e8a-ab2e-9158eb8aa7c6 -->
<!-- metadata:{"confidence":9} -->
P1: For collective bookings with multiple destination calendars, this always selects the first destination for every `BaseCalendarService` invocation. `EventManager` passes the same array to each credential, so a secondary CalDAV or Exchange account silently returns success without creating its event; select the destination matching the current credential instead.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At packages/lib/CalendarService.ts, line 156:
<comment>For collective bookings with multiple destination calendars, this always selects the first destination for every `BaseCalendarService` invocation. `EventManager` passes the same array to each credential, so a secondary CalDAV or Exchange account silently returns success without creating its event; select the destination matching the current credential instead.</comment>
<file context>
@@ -153,12 +153,14 @@ export default abstract class BaseCalendarService implements Calendar {
if (error || !iCalString)
throw new Error(`Error creating iCalString:=> ${error?.message} : ${error?.name} `);
+ const [mainHostDestinationCalendar] = event.destinationCalendar ?? [];
+
// We create the event directly on iCal
</file context>
```
</details>
<!-- cubic:v=94ccddd0-29b8-4689-abd9-8f07bc8bf0ce -->
<!-- cubic:review-run=7fabac28-6d54-5e8a-ab2e-9158eb8aa7c6 -->
<!-- metadata:{"confidence":9} -->
P1: When a recurring booking uses a credential recovered from Prisma, this branch never deletes its events because it iterates only `user.credentials`. Include `calendarCredential` in the recurring credential set before building `promises`.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At packages/features/bookings/lib/handleCancelBooking.ts, line 449:
<comment>When a recurring booking uses a credential recovered from Prisma, this branch never deletes its events because it iterates only `user.credentials`. Include `calendarCredential` in the recurring credential set before building `promises`.</comment>
<file context>
@@ -411,58 +415,71 @@ async function handler(req: CustomRequest) {
+ bookingToDelete.recurringEventId &&
+ allRemainingBookings
+ ) {
+ const promises = bookingToDelete.user.credentials
+ .filter((credential) => credential.type.endsWith("_calendar"))
+ .map(async (credential) => {
</file context>
```
</details>
```suggestion
const calendarCredentials = bookingToDelete.user.credentials.some(
(credential) => credential.id === calendarCredential.id
)
? bookingToDelete.user.credentials
: [...bookingToDelete.user.credentials, calendarCredential];
const promises = calendarCredentials
```
<!-- cubic:v=e894be30-b7db-42ad-a6eb-63b12e32748c -->
<!-- cubic:review-run=7fabac28-6d54-5e8a-ab2e-9158eb8aa7c6 -->
<!-- metadata:{"confidence":9} -->
P1: When `externalCalendarId` is null or omitted, this predicate can never match a destination calendar, so Google receives `undefined` for `calendarId` and the update fails. Fall back to `event.destinationCalendar?.[0]?.externalId` when no external ID is supplied.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At packages/app-store/googlecalendar/lib/CalendarService.ts, line 256:
<comment>When `externalCalendarId` is null or omitted, this predicate can never match a destination calendar, so Google receives `undefined` for `calendarId` and the update fails. Fall back to `event.destinationCalendar?.[0]?.externalId` when no external ID is supplied.</comment>
<file context>
@@ -244,7 +253,7 @@ export default class GoogleCalendarService implements Calendar {
const selectedCalendar = externalCalendarId
? externalCalendarId
- : event.destinationCalendar?.externalId;
+ : event.destinationCalendar?.find((cal) => cal.externalId === externalCalendarId)?.externalId;
calendar.events.update(
</file context>
```
</details>
```suggestion
: event.destinationCalendar?.[0]?.externalId;
```
<!-- cubic:v=27b33e9c-cc2b-47d8-ae33-dd5dc9bf896e -->
<!-- cubic:review-run=7fabac28-6d54-5e8a-ab2e-9158eb8aa7c6 -->
<!-- metadata:{"confidence":9} -->
P1: When the destination has no matching `credentialId` (or no destination exists), `selectedCalendar` is undefined. The insert then silently uses `primary`, and the Meet-link patch is called with an undefined `calendarId`; fall back to the destination calendar and explicitly use `primary` when none exists.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At packages/app-store/googlecalendar/lib/CalendarService.ts, line 147:
<comment>When the destination has no matching `credentialId` (or no destination exists), `selectedCalendar` is undefined. The insert then silently uses `primary`, and the Meet-link patch is called with an undefined `calendarId`; fall back to the destination calendar and explicitly use `primary` when none exists.</comment>
<file context>
@@ -138,13 +142,16 @@ export default class GoogleCalendarService implements Calendar {
- : "primary";
+ // Find in calEventRaw.destinationCalendar the one with the same credentialId
+
+ const selectedCalendar = calEventRaw.destinationCalendar?.find(
+ (cal) => cal.credentialId === credentialId
+ )?.externalId;
</file context>
```
</details>
```suggestion
const selectedCalendar =
calEventRaw.destinationCalendar?.find((cal) => cal.credentialId === credentialId)?.externalId ??
calEventRaw.destinationCalendar?.[0]?.externalId ??
"primary";
```
<!-- cubic:v=91975315-c53a-4205-a625-d51ff872099e -->
<!-- cubic:review-run=7fabac28-6d54-5e8a-ab2e-9158eb8aa7c6 -->
<!-- metadata:{"confidence":9} -->
P2: When a collective event has no event-type or organizer destination calendar, this optional push discards every collected team calendar. Initialize the destination list before appending so team members' calendar events are still created.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At packages/features/bookings/lib/handleNewBooking.ts, line 1078:
<comment>When a collective event has no event-type or organizer destination calendar, this optional push discards every collected team calendar. Initialize the destination list before appending so team members' calendar events are still created.</comment>
<file context>
@@ -1040,16 +1060,24 @@ async function handler(
};
+ if (isTeamEventType && eventType.schedulingType === "COLLECTIVE") {
+ evt.destinationCalendar?.push(...teamDestinationCalendars);
+ }
+
</file context>
```
</details>
```suggestion
evt.destinationCalendar = [...(evt.destinationCalendar ?? []), ...teamDestinationCalendars];
```
<!-- cubic:v=23af9f90-c322-446e-bbad-3fc2584cb0dc -->
<!-- cubic:review-run=7fabac28-6d54-5e8a-ab2e-9158eb8aa7c6 -->
<!-- metadata:{"confidence":9} -->
P2: When cancelling a recurring collective booking with multiple calendar references, this loop repeats the all-bookings deletion pass once per reference. Run the recurring deletion pass once and handle each booking reference within that pass.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At packages/features/bookings/lib/handleCancelBooking.ts, line 423:
<comment>When cancelling a recurring collective booking with multiple calendar references, this loop repeats the all-bookings deletion pass once per reference. Run the recurring deletion pass once and handle each booking reference within that pass.</comment>
<file context>
@@ -411,58 +415,71 @@ async function handler(req: CustomRequest) {
- const deletedEvent = await calendar?.deleteEvent(uid, evt, externalCalendarId);
- apiDeletes.push(deletedEvent);
+ if (bookingCalendarReference.length > 0) {
+ for (const reference of bookingCalendarReference) {
+ const { credentialId, uid, externalCalendarId } = reference;
+ // If the booking calendar reference contains a credentialId
</file context>
```
</details>
<!-- cubic:review-summary:start -->
**15 issues found** across 22 files
<!-- cubic:review-summary:end -->
<details>
<summary>Prompt for AI agents (unresolved issues)</summary>
```text
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/trpc/server/routers/viewer/organizations/create.handler.ts">
<violation number="1" location="packages/trpc/server/routers/viewer/organizations/create.handler.ts:151">
P1: This reverses the billing-mode behavior: billing-enabled organizations receive a live `team.slug` before payment, while billing-disabled organizations receive neither a slug nor `requestedSlug`. The latter cannot be published or create subteams; restore the non-billing `{ slug }` branch and keep billing-enabled organizations slugless until upgrade.</violation>
</file>
<file name="packages/core/EventManager.ts">
<violation number="1" location="packages/core/EventManager.ts:119">
P1: When `destinationCalendar` is empty or null, this dereference throws for every Meet event without a configured Google Calendar. Use optional chaining so the existing Cal Video fallback can run.</violation>
<violation number="2" location="packages/core/EventManager.ts:208">
P1: After a location edit, calendar references lose `externalCalendarId` and `credentialId` because `updateEvent` does not return either field. Preserve the corresponding calendar reference metadata when constructing `referencesToCreate`.</violation>
<violation number="3" location="packages/core/EventManager.ts:370">
P1: With multiple destinations, Office 365 and Lark receive the full array and always create on its first calendar. Pass an event copy containing only the current `destination` to each calendar call.</violation>
<violation number="4" location="packages/core/EventManager.ts:380">
P1: When a destination has no `credentialId`, this branch omits its `externalId`, so the booking reference cannot target that calendar during later updates or cancellations. Pass `destination.externalId` to `createEvent`.</violation>
<violation number="5" location="packages/core/EventManager.ts:496">
P1: When merging bookings with multiple calendar references, only the first old calendar event is deleted, leaving stale events on the remaining calendars. Delete every old calendar reference that is not reused.</violation>
<violation number="6" location="packages/core/EventManager.ts:496">
P1: The new all-reference loop also processes `*_other_calendar` references, then the dedicated non-traditional block processes them again. Exclude `other_calendar` references from the first loop or remove the second pass.</violation>
</file>
<file name="packages/app-store/larkcalendar/lib/CalendarService.ts">
<violation number="1" location="packages/app-store/larkcalendar/lib/CalendarService.ts:128">
P1: When a collective booking has multiple Lark destination calendars, this always selects the organizer's first calendar even though `EventManager` invokes the service once per destination. The event is therefore duplicated on the first Lark calendar and omitted from teammates' calendars; select the calendar matching the current credential/destination rather than unconditionally taking element 0.</violation>
</file>
<file name="packages/app-store/office365calendar/lib/CalendarService.ts">
<violation number="1" location="packages/app-store/office365calendar/lib/CalendarService.ts:73">
P1: When a collective booking has multiple Office 365 destinations, this always selects the host calendar even during later destination iterations. Select the destination matching the credential/current iteration, otherwise team-member events are duplicated in the host calendar or fail with an invalid calendar ID.</violation>
</file>
<file name="packages/lib/CalendarService.ts">
<violation number="1" location="packages/lib/CalendarService.ts:156">
P1: For collective bookings with multiple destination calendars, this always selects the first destination for every `BaseCalendarService` invocation. `EventManager` passes the same array to each credential, so a secondary CalDAV or Exchange account silently returns success without creating its event; select the destination matching the current credential instead.</violation>
</file>
<file name="packages/features/bookings/lib/handleNewBooking.ts">
<violation number="1" location="packages/features/bookings/lib/handleNewBooking.ts:1078">
P2: When a collective event has no event-type or organizer destination calendar, this optional push discards every collected team calendar. Initialize the destination list before appending so team members' calendar events are still created.</violation>
</file>
<file name="packages/features/bookings/lib/handleCancelBooking.ts">
<violation number="1" location="packages/features/bookings/lib/handleCancelBooking.ts:423">
P2: When cancelling a recurring collective booking with multiple calendar references, this loop repeats the all-bookings deletion pass once per reference. Run the recurring deletion pass once and handle each booking reference within that pass.</violation>
<violation number="2" location="packages/features/bookings/lib/handleCancelBooking.ts:449">
P1: When a recurring booking uses a credential recovered from Prisma, this branch never deletes its events because it iterates only `user.credentials`. Include `calendarCredential` in the recurring credential set before building `promises`.</violation>
</file>
<file name="packages/app-store/googlecalendar/lib/CalendarService.ts">
<violation number="1" location="packages/app-store/googlecalendar/lib/CalendarService.ts:147">
P1: When the destination has no matching `credentialId` (or no destination exists), `selectedCalendar` is undefined. The insert then silently uses `primary`, and the Meet-link patch is called with an undefined `calendarId`; fall back to the destination calendar and explicitly use `primary` when none exists.</violation>
<violation number="2" location="packages/app-store/googlecalendar/lib/CalendarService.ts:256">
P1: When `externalCalendarId` is null or omitted, this predicate can never match a destination calendar, so Google receives `undefined` for `calendarId` and the update fails. Fall back to `event.destinationCalendar?.[0]?.externalId` when no external ID is supplied.</violation>
</file>
```
</details>
<sub>Reply with feedback, questions, or to request a fix.<br /><br />[Re-trigger cubic](https://www.cubic.dev/action/re-review/pr/drape-io/crbench-cubic-2026-09/17/ai_pr_review_github_delivery_f9abcd306f142ee2dd0c57dd890997f2cdefe952d3677ddab256a0454d6560c1?returnTo=https%3A%2F%2Fgithub.com%2Fdrape-io%2Fcrbench-cubic-2026-09%2Fpull%2F17)</sub>
<!-- cubic:review-post:ai_pr_review_github_delivery_f9abcd306f142ee2dd0c57dd890997f2cdefe952d3677ddab256a0454d6560c1:1c3280a82581f59a0ab32d88d0abdc99304fa3d9:7fabac28-6d54-5e8a-ab2e-9158eb8aa7c6 -->
cursor · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
| d3 | medium | ✓ | off by one |
| d4 | high | ✓ | exact |
| d5 | high | ✓ | off by one |
| d6 | high | ✓ | exact |
| d7 | medium | ✓ | exact |
| d8 | medium | ✓ | exact |
raw comments (8)
### Meet fallback crashes without destination calendar
**High Severity**
<!-- DESCRIPTION START -->
`mainHostDestinationCalendar` is taken from `evt.destinationCalendar` without a fallback, then `.integration` is read with no optional chaining. When location is Google Meet and `destinationCalendar` is `null` or empty, this throws and booking creation fails instead of falling back to Cal Video.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 80df05c6-5b7f-4fe2-8d72-d7cbaee99e9d -->
<!-- LOCATIONS START
packages/core/EventManager.ts#L117-L120
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmIxM2FmMGNhLWRjYTYtNDljZC1iZTg0LTE3MmUyYjllMDAzYSIsImVuY3J5cHRpb25LZXkiOiJqck5Qc2QtWW5KWEp3WlB3aDMxRGk2b0xRZ2RFenlkYTJxazY1elZBYjBNIiwiYnJhbmNoIjoidDItY2FsLWNvbS0xMDk2NyIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmIxM2FmMGNhLWRjYTYtNDljZC1iZTg0LTE3MmUyYjllMDAzYSIsImVuY3J5cHRpb25LZXkiOiJqck5Qc2QtWW5KWEp3WlB3aDMxRGk2b0xRZ2RFenlkYTJxazY1elZBYjBNIiwiYnJhbmNoIjoidDItY2FsLWNvbS0xMDk2NyIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJOdW1iZXIiOjE3LCJjb21taXRTaGEiOiJiNDdmMzM2ZjM4ODI0YzY5ZWE4MjcwYWZjMGY5ZGQ5OWQ2NmE5NDYzIiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b47f336f38824c69ea8270afc0f9dd99d66a9463. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### Google update and delete calendar lookup
**High Severity**
<!-- DESCRIPTION START -->
When `externalCalendarId` is missing, both `updateEvent` and `deleteEvent` search `destinationCalendar` for an entry whose `externalId` equals that same missing value. The find never matches, so updates get a missing `calendarId` and deletes fall back to `primary` instead of the real destination calendar.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: d85a05b4-c0ec-4c60-93ba-7d1cb9c54f7f -->
<!-- LOCATIONS START
packages/app-store/googlecalendar/lib/CalendarService.ts#L253-L256
packages/app-store/googlecalendar/lib/CalendarService.ts#L314-L317
LOCATIONS END -->
<details>
<summary>Additional Locations (1)</summary>
- [`packages/app-store/googlecalendar/lib/CalendarService.ts#L314-L317`](https://github.com/drape-io/crbench-cursor-2026-09/blob/b47f336f38824c69ea8270afc0f9dd99d66a9463/packages/app-store/googlecalendar/lib/CalendarService.ts#L314-L317)
</details>
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjUzMjFlNWZhLTI0OGEtNDI3Mi04OTVmLTE4YjcyZWMxNTFkMiIsImVuY3J5cHRpb25LZXkiOiJiVGN1TXczZFBCbVFpRmtLbmYycndNODJDcXhIdEZHZVR3djk0STFnZFg0IiwiYnJhbmNoIjoidDItY2FsLWNvbS0xMDk2NyIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjUzMjFlNWZhLTI0OGEtNDI3Mi04OTVmLTE4YjcyZWMxNTFkMiIsImVuY3J5cHRpb25LZXkiOiJiVGN1TXczZFBCbVFpRmtLbmYycndNODJDcXhIdEZHZVR3djk0STFnZFg0IiwiYnJhbmNoIjoidDItY2FsLWNvbS0xMDk2NyIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJOdW1iZXIiOjE3LCJjb21taXRTaGEiOiJiNDdmMzM2ZjM4ODI0YzY5ZWE4MjcwYWZjMGY5ZGQ5OWQ2NmE5NDYzIiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b47f336f38824c69ea8270afc0f9dd99d66a9463. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### Team calendars dropped when destination is null
**Medium Severity**
<!-- DESCRIPTION START -->
`evt.destinationCalendar` is initialized to `null` when neither the event type nor the organizer has a destination calendar. The later `evt.destinationCalendar?.push(...teamDestinationCalendars)` then no-ops, so collected COLLECTIVE member calendars never reach `EventManager`.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 4b2024b5-6dc4-40b2-985d-5f6d61d21323 -->
<!-- LOCATIONS START
packages/features/bookings/lib/handleNewBooking.ts#L1062-L1079
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmJjMTc2MmJhLWRmOGQtNDRkZS05MzlmLThjOTgyN2IwZjFlMyIsImVuY3J5cHRpb25LZXkiOiJEMEd4b1MwMHhhb2NBWV9kdkUzTlJWcy0wZzk3bUg4WWRjcUNFRnN2TmJNIiwiYnJhbmNoIjoidDItY2FsLWNvbS0xMDk2NyIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmJjMTc2MmJhLWRmOGQtNDRkZS05MzlmLThjOTgyN2IwZjFlMyIsImVuY3J5cHRpb25LZXkiOiJEMEd4b1MwMHhhb2NBWV9kdkUzTlJWcy0wZzk3bUg4WWRjcUNFRnN2TmJNIiwiYnJhbmNoIjoidDItY2FsLWNvbS0xMDk2NyIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJOdW1iZXIiOjE3LCJjb21taXRTaGEiOiJiNDdmMzM2ZjM4ODI0YzY5ZWE4MjcwYWZjMGY5ZGQ5OWQ2NmE5NDYzIiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b47f336f38824c69ea8270afc0f9dd99d66a9463. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### Organization slug billing condition inverted
**High Severity**
<!-- DESCRIPTION START -->
The team `slug` is now applied when `IS_TEAM_BILLING_ENABLED` is true, and omitted when billing is disabled. Previously slug was written only when billing was off, with `requestedSlug` reserved for the paid publish flow.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: f15b951c-0ece-4647-b9ab-cca80ab247dc -->
<!-- LOCATIONS START
packages/trpc/server/routers/viewer/organizations/create.handler.ts#L150-L153
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjMxZTIzYzc5LTg4ZDQtNDE2MC1iMTI0LTFkMmZjMDhlMTZlMiIsImVuY3J5cHRpb25LZXkiOiJfeU56eVBlR2RRWjV5TzUxYmZUN1h4LTdIWFRCY2twNG5SWVZwdlVkaXprIiwiYnJhbmNoIjoidDItY2FsLWNvbS0xMDk2NyIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjMxZTIzYzc5LTg4ZDQtNDE2MC1iMTI0LTFkMmZjMDhlMTZlMiIsImVuY3J5cHRpb25LZXkiOiJfeU56eVBlR2RRWjV5TzUxYmZUN1h4LTdIWFRCY2twNG5SWVZwdlVkaXprIiwiYnJhbmNoIjoidDItY2FsLWNvbS0xMDk2NyIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJOdW1iZXIiOjE3LCJjb21taXRTaGEiOiJiNDdmMzM2ZjM4ODI0YzY5ZWE4MjcwYWZjMGY5ZGQ5OWQ2NmE5NDYzIiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b47f336f38824c69ea8270afc0f9dd99d66a9463. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### Video references omit credential id
**High Severity**
<!-- DESCRIPTION START -->
`referencesToCreate` now sets `credentialId` only for calendar results. Video results previously stored `result.credentialId` from `createMeeting`; they now persist `undefined`.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: d6c2e05c-6397-4d69-b673-f7949ac8babe -->
<!-- LOCATIONS START
packages/core/EventManager.ts#L168-L170
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjkzNzlkNjIwLTRiY2QtNDg2MC04OTkzLWQ3MzQzMGU5NWMxMSIsImVuY3J5cHRpb25LZXkiOiJiQXBKajBFN0x0M1VPT0VteVIxbFRCcFdRZHVXZWQwbWUybmw3UE9kdjlvIiwiYnJhbmNoIjoidDItY2FsLWNvbS0xMDk2NyIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjkzNzlkNjIwLTRiY2QtNDg2MC04OTkzLWQ3MzQzMGU5NWMxMSIsImVuY3J5cHRpb25LZXkiOiJiQXBKajBFN0x0M1VPT0VteVIxbFRCcFdRZHVXZWQwbWUybmw3UE9kdjlvIiwiYnJhbmNoIjoidDItY2FsLWNvbS0xMDk2NyIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJOdW1iZXIiOjE3LCJjb21taXRTaGEiOiJiNDdmMzM2ZjM4ODI0YzY5ZWE4MjcwYWZjMGY5ZGQ5OWQ2NmE5NDYzIiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b47f336f38824c69ea8270afc0f9dd99d66a9463. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### Non-Google creates ignore matching destination
**Medium Severity**
<!-- DESCRIPTION START -->
`EventManager` now creates an event per destination calendar with that host’s credential, but Office 365, Lark, and CalDAV still always use `destinationCalendar[0]`. Team-member credentials therefore write to the organizer’s calendar id.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 6da80b85-fc45-45a3-aca0-b6953e4b2dee -->
<!-- LOCATIONS START
packages/app-store/office365calendar/lib/CalendarService.ts#L71-L77
packages/app-store/larkcalendar/lib/CalendarService.ts#L127-L129
packages/lib/CalendarService.ts#L155-L164
LOCATIONS END -->
<details>
<summary>Additional Locations (2)</summary>
- [`packages/app-store/larkcalendar/lib/CalendarService.ts#L127-L129`](https://github.com/drape-io/crbench-cursor-2026-09/blob/b47f336f38824c69ea8270afc0f9dd99d66a9463/packages/app-store/larkcalendar/lib/CalendarService.ts#L127-L129)
- [`packages/lib/CalendarService.ts#L155-L164`](https://github.com/drape-io/crbench-cursor-2026-09/blob/b47f336f38824c69ea8270afc0f9dd99d66a9463/packages/lib/CalendarService.ts#L155-L164)
</details>
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjRhMDMzNDdlLWM2NjYtNDY1Ny05ZGMwLWIzMjQyZmFlMDZhOCIsImVuY3J5cHRpb25LZXkiOiJUZm1zWS10VzJwMWo0eUZZRUt1Zkp3WDdURzVMWWtDbDdfUHdCLVc1cFEwIiwiYnJhbmNoIjoidDItY2FsLWNvbS0xMDk2NyIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjRhMDMzNDdlLWM2NjYtNDY1Ny05ZGMwLWIzMjQyZmFlMDZhOCIsImVuY3J5cHRpb25LZXkiOiJUZm1zWS10VzJwMWo0eUZZRUt1Zkp3WDdURzVMWWtDbDdfUHdCLVc1cFEwIiwiYnJhbmNoIjoidDItY2FsLWNvbS0xMDk2NyIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJOdW1iZXIiOjE3LCJjb21taXRTaGEiOiJiNDdmMzM2ZjM4ODI0YzY5ZWE4MjcwYWZjMGY5ZGQ5OWQ2NmE5NDYzIiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b47f336f38824c69ea8270afc0f9dd99d66a9463. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### Recurring cancel misses extra calendar refs
**Medium Severity**
<!-- DESCRIPTION START -->
The recurring “delete all remaining” block now runs inside a loop over every calendar reference, but each remaining booking still uses `references.find` for a single `_calendar` ref. Extra destination events on the rest of the series are never deleted, and the first one is deleted repeatedly.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 0f35d97f-06f6-4302-b568-cb8d26d4b426 -->
<!-- LOCATIONS START
packages/features/bookings/lib/handleCancelBooking.ts#L421-L458
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmQzYTllZWU1LWExNjAtNDUwZS1iYzdjLTcyYTI1Y2RlODg2ZSIsImVuY3J5cHRpb25LZXkiOiJvSmVrVlFTOVEyaXNOb1pLZlRLelBMcTNLZGdsbDVwMjhCV3o4aTE5bW1zIiwiYnJhbmNoIjoidDItY2FsLWNvbS0xMDk2NyIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmQzYTllZWU1LWExNjAtNDUwZS1iYzdjLTcyYTI1Y2RlODg2ZSIsImVuY3J5cHRpb25LZXkiOiJvSmVrVlFTOVEyaXNOb1pLZlRLelBMcTNLZGdsbDVwMjhCV3o4aTE5bW1zIiwiYnJhbmNoIjoidDItY2FsLWNvbS0xMDk2NyIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJOdW1iZXIiOjE3LCJjb21taXRTaGEiOiJiNDdmMzM2ZjM4ODI0YzY5ZWE4MjcwYWZjMGY5ZGQ5OWQ2NmE5NDYzIiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b47f336f38824c69ea8270afc0f9dd99d66a9463. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- BUGBOT_REVIEW -->
Cursor Bugbot has reviewed your changes using high effort and found 7 potential issues.
<!-- BUGBOT_FIX_ALL -->
<a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9BTExfSU5fQ1VSU09SIiwiZGF0YSI6eyJyZWRpc0tleSI6ImJ1Z2JvdC1tdWx0aTo0YmQyYTE1Ny0zMjhmLTQ5OTQtODY2My01NmE5NjM5YmFjZjYiLCJlbmNyeXB0aW9uS2V5IjoiUTdPSXV2clplSnVhQlNab2FoTTgwYzJ3VUVkNVpKemdkTk5MUVBEWlZRdyIsImJyYW5jaCI6InQyLWNhbC1jb20tMTA5NjciLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix All in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a>
<!-- /BUGBOT_FIX_ALL -->
<!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_BEGIN -->
<sup>❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_END -->
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b47f336f38824c69ea8270afc0f9dd99d66a9463. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
Drape (Deep Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
| d3 | medium | ✓ | exact |
| d4 | high | ✓ | exact |
| d5 | high | ✓ | off by one |
| d6 | high | ✓ | exact |
| d7 | medium | ✓ | exact |
| d8 | medium | ✓ | exact |
The fallback runs only when externalCalendarId is falsy, so the find compares against a falsy value and never matches. Before this change the fallback used destinationCalendar.externalId; now the delete always goes to 'primary'. [grounded: diff] [consensus 3/3: valid=3]
The updateEvent result in CalendarManager sets neither externalId nor credentialId. The old code took both from evt.destinationCalendar, so calendar references created from location edits now lose these fields. [grounded: diff] [consensus 3/3: valid=3]
selectedCalendar used to always fall back to 'primary'. It can now be undefined, and only the insert applies the 'primary' fallback, so the patch call gets an undefined calendarId. [grounded: tree packages/app-store/googlecalendar/lib/CalendarService.ts] [consensus 3/3: valid=3]
EventManager now calls createEvent once per destination, each with that host's credential, but CalDAV still filters by the first host's externalId. For other hosts nothing matches, so no event is created and success is still reported. Office365 has the same problem: it builds the URL from the first host's calendar id. [grounded: diff] [consensus 3/3: valid=3]
The organizer email always comes from the first destination calendar, even when the event is created for another host's credential and calendar. [grounded: diff] [consensus 3/3: valid=3]
The old catch returned a single failure result and logged the error. The new one returns [] when calendarReference is unset and the console.error was removed, so the failure is invisible to callers. [grounded: diff] [consensus 3/3: valid=3]
In the branch for destinations without a credentialId, createEvent gets no externalId, so result.externalId is undefined and so is the reference's externalCalendarId. The old code used evt.destinationCalendar.externalId. [grounded: diff] [consensus 3/3: valid=3]
A destination with a null credentialId never matches the numeric credentialId, so the insert falls back to 'primary'. The old code used destinationCalendar.externalId. [grounded: diff] [consensus 3/3: valid=3]
raw comments (15)
**Video references saved without credentialId**
For video results `credentialId` is now always undefined, though `createMeeting` sets it. Cancelling then finds no `credentialId` on the video reference and never deletes the meeting. Keep `result.credentialId` for non-calendar results.
```
packages/core/EventManager.ts:170 credentialId: isCalendarType ? result.credentialId : undefined,
packages/core/videoClient.ts:78 credentialId: credential.id,
packages/features/bookings/lib/handleCancelBooking.ts:491 if (bookingVideoReference && bookingVideoReference.credentialId) {
```
**Google update loses destination calendar fallback**
The fallback only runs when `externalCalendarId` is empty, and then it searches for a calendar whose id equals that empty value, so it always yields undefined. References with no stored calendar id can't be updated any more. Fall back to the matching (or first) destinationCalendar's externalId, as before.
```
packages/app-store/googlecalendar/lib/CalendarService.ts:254 const selectedCalendar = externalCalendarId
packages/app-store/googlecalendar/lib/CalendarService.ts:255 ? externalCalendarId
packages/app-store/googlecalendar/lib/CalendarService.ts:256 : event.destinationCalendar?.find((cal) => cal.externalId === externalCalendarId)?.externalId;
packages/app-store/googlecalendar/lib/CalendarService.ts:258 calendar.events.update(
packages/app-store/googlecalendar/lib/CalendarService.ts:259 {
packages/app-store/googlecalendar/lib/CalendarService.ts:260 auth: myGoogleAuth,
packages/app-store/googlecalendar/lib/CalendarService.ts:261 calendarId: selectedCalendar,
```
**Lark events for other hosts use wrong calendar**
Lark `createEvent` and `createAttendees` always use the first host's calendar id, even when running with another collective host's credential. Select the destination that matches the credential being used.
```
packages/app-store/larkcalendar/lib/CalendarService.ts:128 const [mainHostDestinationCalendar] = event.destinationCalendar ?? [];
packages/app-store/larkcalendar/lib/CalendarService.ts:129 const calendarId = mainHostDestinationCalendar?.externalId;
packages/app-store/larkcalendar/lib/CalendarService.ts:130 if (!calendarId) {
packages/app-store/larkcalendar/lib/CalendarService.ts:131 throw new Error("no calendar id");
packages/app-store/larkcalendar/lib/CalendarService.ts:132 }
```
**Recurring cancel repeats deletes for every host reference**
The recurring branch now runs once per calendar reference, but each run deletes every remaining occurrence with the organizer's credentials. So a collective booking repeats all deletes per host and never removes other hosts' events. Run the recurring deletion once per reference using that reference's credential.
```
packages/features/bookings/lib/handleCancelBooking.ts:422 if (bookingCalendarReference.length > 0) {
packages/features/bookings/lib/handleCancelBooking.ts:423 for (const reference of bookingCalendarReference) {
packages/features/bookings/lib/handleCancelBooking.ts:424 const { credentialId, uid, externalCalendarId } = reference;
packages/features/bookings/lib/handleCancelBooking.ts:425 // If the booking calendar reference contains a credentialId
packages/features/bookings/lib/handleCancelBooking.ts:449 const promises = bookingToDelete.user.credentials
packages/features/bookings/lib/handleCancelBooking.ts:450 .filter((credential) => credential.type.endsWith("_calendar"))
packages/features/bookings/lib/handleCancelBooking.ts:451 .map(async (credential) => {
packages/features/bookings/lib/handleCancelBooking.ts:452 const calendar = await getCalendar(credential);
packages/features/bookings/lib/handleCancelBooking.ts:453 for (const updBooking of updatedBookings) {
packages/features/bookings/lib/handleCancelBooking.ts:454 const bookingRef = updBooking.references.find((ref) => ref.type.includes("_calendar"));
```
**Google delete falls back to primary, not destination**
The fallback matches `cal.externalId === externalCalendarId` only when `externalCalendarId` is empty, so it never finds anything and the delete goes to "primary". Events created in a non-primary destination calendar are left behind. Fall back to the first destination calendar's externalId.
```
packages/app-store/googlecalendar/lib/CalendarService.ts:315 const calendarId = externalCalendarId
packages/app-store/googlecalendar/lib/CalendarService.ts:316 ? externalCalendarId
packages/app-store/googlecalendar/lib/CalendarService.ts:317 : event.destinationCalendar?.find((cal) => cal.externalId === externalCalendarId)?.externalId;
packages/app-store/googlecalendar/lib/CalendarService.ts:319 calendar.events.delete(
packages/app-store/googlecalendar/lib/CalendarService.ts:320 {
packages/app-store/googlecalendar/lib/CalendarService.ts:321 auth: myGoogleAuth,
packages/app-store/googlecalendar/lib/CalendarService.ts:322 calendarId: calendarId ? calendarId : defaultCalendarId,
packages/app-store/googlecalendar/lib/CalendarService.ts:323 eventId: uid,
packages/app-store/googlecalendar/lib/CalendarService.ts:324 sendNotifications: false,
packages/app-store/googlecalendar/lib/CalendarService.ts:325 sendUpdates: "none",
```
**Google Meet booking crashes without destination calendar**
When the event has no destination calendar (null or the new empty `[]` default), `mainHostDestinationCalendar` is undefined, and reading `.integration` on it throws instead of falling back to Cal Video. Use optional chaining: `mainHostDestinationCalendar?.integration`.
```
packages/core/EventManager.ts:118 const [mainHostDestinationCalendar] = evt.destinationCalendar ?? [];
packages/core/EventManager.ts:119 if (evt.location === MeetLocationType && mainHostDestinationCalendar.integration !== "google_calendar") {
```
**Org slug condition inverted on create**
The `slug` condition was flipped: with team billing on, the slug is now claimed right away before payment, and with billing off, the org gets neither `slug` nor `requestedSlug`. Restore `...(!IS_TEAM_BILLING_ENABLED ? { slug } : {})`.
```
packages/trpc/server/routers/viewer/organizations/create.handler.ts:151 ...(IS_TEAM_BILLING_ENABLED ? { slug } : {}),
packages/trpc/server/routers/viewer/organizations/create.handler.ts:151 (base) ...(!IS_TEAM_BILLING_ENABLED && { slug }),
```
**Location edits drop calendar reference IDs**
In `updateLocation`, references built from `updateEvent` results now take `externalId`/`credentialId` from the result. `updateEvent` sets neither, so the new calendar references are saved without a calendar id or credential. Have updateEvent return credentialId/externalId, or fall back to the matching destination calendar.
```
packages/core/EventManager.ts:208 externalCalendarId: result.externalId,
packages/core/EventManager.ts:209 credentialId: result.credentialId ?? undefined,
packages/core/CalendarManager.ts:313 return {
packages/core/CalendarManager.ts:314 appName: credential.appName,
packages/core/CalendarManager.ts:315 type: credential.type,
packages/core/CalendarManager.ts:316 success,
packages/core/CalendarManager.ts:317 uid,
packages/core/CalendarManager.ts:318 updatedEvent: updatedResult,
packages/core/CalendarManager.ts:319 originalEvent: calEvent,
packages/core/CalendarManager.ts:320 calError,
```
**Meet link patch sends undefined calendarId**
The insert falls back to `"primary"`, but the hangout-link `patch` still passes the raw `selectedCalendar`. That value can now be undefined, so the follow-up patch fails and the description never gets the Meet link. Compute `const calendarId = selectedCalendar || "primary"` once and use it for both insert and patch.
```
packages/app-store/googlecalendar/lib/CalendarService.ts:147 const selectedCalendar = calEventRaw.destinationCalendar?.find(
packages/app-store/googlecalendar/lib/CalendarService.ts:148 (cal) => cal.credentialId === credentialId
packages/app-store/googlecalendar/lib/CalendarService.ts:149 )?.externalId;
packages/app-store/googlecalendar/lib/CalendarService.ts:151 calendar.events.insert(
packages/app-store/googlecalendar/lib/CalendarService.ts:165 if (event && event.data.id && event.data.hangoutLink) {
packages/app-store/googlecalendar/lib/CalendarService.ts:166 calendar.events.patch({
packages/app-store/googlecalendar/lib/CalendarService.ts:167 // Update the same event but this time we know the hangout link
packages/app-store/googlecalendar/lib/CalendarService.ts:168 calendarId: selectedCalendar,
packages/app-store/googlecalendar/lib/CalendarService.ts:169 auth: myGoogleAuth,
packages/app-store/googlecalendar/lib/CalendarService.ts:170 eventId: event.data.id || "",
```
**CalDAV events skipped for non-main collective hosts**
CalDAV `createEvent` keeps only calendars matching the first destination calendar's externalId. For another host's credential nothing matches, so no event is created, but the call still reports success. Use the destination calendar whose credentialId matches this service's credential.
The same mistake is at `packages/app-store/office365calendar/lib/CalendarService.ts:73`.
```
packages/lib/CalendarService.ts:156 const [mainHostDestinationCalendar] = event.destinationCalendar ?? [];
packages/lib/CalendarService.ts:158 // We create the event directly on iCal
packages/lib/CalendarService.ts:159 const responses = await Promise.all(
packages/lib/CalendarService.ts:160 calendars
packages/lib/CalendarService.ts:161 .filter((c) =>
packages/lib/CalendarService.ts:162 mainHostDestinationCalendar?.externalId
packages/lib/CalendarService.ts:163 ? c.externalId === mainHostDestinationCalendar.externalId
packages/lib/CalendarService.ts:164 : true
```
**Team calendars skipped when organizer has none**
If neither the event type nor the organizer has a destination calendar, `evt.destinationCalendar` is null and `?.push` does nothing, so the other collective hosts' calendars are silently dropped. Initialize `evt.destinationCalendar` to `[]` when absent before pushing team calendars.
```
packages/features/bookings/lib/handleNewBooking.ts:1063 destinationCalendar: eventType.destinationCalendar
packages/features/bookings/lib/handleNewBooking.ts:1064 ? [eventType.destinationCalendar]
packages/features/bookings/lib/handleNewBooking.ts:1065 : organizerUser.destinationCalendar
packages/features/bookings/lib/handleNewBooking.ts:1066 ? [organizerUser.destinationCalendar]
packages/features/bookings/lib/handleNewBooking.ts:1067 : null,
```
**Organizer email set to first host's calendar id**
For another collective host's Google event, the organizer attendee email is the first host's calendar id, not the calendar the event is created in. Use the destination matching `credentialId` here too.
```
packages/app-store/googlecalendar/lib/CalendarService.ts:100 const [mainHostDestinationCalendar] =
packages/app-store/googlecalendar/lib/CalendarService.ts:101 calEventRaw?.destinationCalendar && calEventRaw?.destinationCalendar.length > 0
packages/app-store/googlecalendar/lib/CalendarService.ts:102 ? calEventRaw.destinationCalendar
packages/app-store/googlecalendar/lib/CalendarService.ts:103 : [];
packages/app-store/googlecalendar/lib/CalendarService.ts:147 const selectedCalendar = calEventRaw.destinationCalendar?.find(
packages/app-store/googlecalendar/lib/CalendarService.ts:148 (cal) => cal.credentialId === credentialId
packages/app-store/googlecalendar/lib/CalendarService.ts:149 )?.externalId;
```
**Calendar update errors reported as no results**
If the error happens before `calendarReference` is assigned (e.g. the booking lookup throws), the catch now returns an empty array instead of a failed result, and the error log was removed. Callers see no failure. Return a single failure result when `calendarReference` is unset, and keep the log.
```
packages/core/EventManager.ts:590 return Promise.all(result);
packages/core/EventManager.ts:591 } catch (error) {
packages/core/EventManager.ts:592 let message = `Tried to 'updateAllCalendarEvents' but there was no '{thing}' for '${credential?.type}', userId: '${credential?.userId}', bookingId: '${booking?.id}'`;
packages/core/EventManager.ts:593 if (error instanceof Error) {
packages/core/EventManager.ts:597 return Promise.resolve(
packages/core/EventManager.ts:598 calendarReference?.map((reference) => {
packages/core/EventManager.ts:599 return {
packages/core/EventManager.ts:600 appName: "none",
packages/core/EventManager.ts:601 type: reference?.type || "calendar",
packages/core/EventManager.ts:602 success: false,
```
**Legacy destination calendar loses externalCalendarId on references**
When a destination calendar has no `credentialId`, `createEvent` is called without `destination.externalId`, so the stored reference gets no `externalCalendarId`. The old code took it from `evt.destinationCalendar.externalId`, so later updates and deletes now target the wrong calendar. Pass `destination.externalId` into `createEvent` in this branch too.
```
packages/core/EventManager.ts:375 } else {
packages/core/EventManager.ts:376 const destinationCalendarCredentials = this.calendarCredentials.filter(
packages/core/EventManager.ts:377 (c) => c.type === destination.integration
packages/core/EventManager.ts:378 );
packages/core/CalendarManager.ts:267 externalId,
```
**Google event goes to primary, ignoring chosen calendar**
`selectedCalendar` now only matches destination calendars by `credentialId`. A destination calendar with no credentialId (older rows, handled by EventManager's integration-type branch) now writes to "primary" instead of its `externalId`. Fall back to the first google destination calendar's externalId when no credentialId matches.
```
packages/app-store/googlecalendar/lib/CalendarService.ts:147 const selectedCalendar = calEventRaw.destinationCalendar?.find(
packages/app-store/googlecalendar/lib/CalendarService.ts:148 (cal) => cal.credentialId === credentialId
packages/app-store/googlecalendar/lib/CalendarService.ts:149 )?.externalId;
packages/app-store/googlecalendar/lib/CalendarService.ts:151 calendar.events.insert(
packages/app-store/googlecalendar/lib/CalendarService.ts:141 (base) const selectedCalendar = calEventRaw.destinationCalendar?.externalId
packages/app-store/googlecalendar/lib/CalendarService.ts:142 (base) ? calEventRaw.destinationCalendar.externalId
packages/app-store/googlecalendar/lib/CalendarService.ts:143 (base) : "primary";
```
Drape (Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
| d3 | medium | ✓ | off by one |
| d4 | high | ✓ | exact |
| d5 | high | ✓ | off by one |
| d6 | high | ✓ | off by one |
| d7 | medium | ✓ | exact |
| d8 | medium | ✗ | — |
When a destination calendar has no credentialId, EventManager calls createEvent for each credential of that type. The credentialId match never succeeds, so the event goes to 'primary'. Before this change it used destinationCalendar.externalId. [grounded: diff] [consensus 3/3: valid=3]
No externalId is passed in this branch, so result.externalId is undefined and the reference's externalCalendarId is lost. Before this change it came from evt.destinationCalendar.externalId. [grounded: diff] [consensus 3/3: valid=3]
CalendarManager.updateEvent returns neither externalId nor credentialId. The old fallbacks to evt.destinationCalendar were removed, so references recreated by updateLocation lose both values. [grounded: diff] [consensus 3/3: valid=3]
The fallback only runs when externalCalendarId is falsy, and then it compares against that falsy value, so it never matches and deletion falls back to 'primary'. Before this change it used destinationCalendar.externalId. [grounded: diff] [consensus 3/3: valid=3]
The recurring block deletes every remaining booking's events across all credentials, and it now sits inside the per-reference loop, so it runs once per calendar reference. Before this change it ran once. [grounded: diff] [consensus 3/3: valid=3]
When the credential is undefined, updateEvent reads credential.appName and rejects. The returned Promise.all is not awaited inside the try, so the rejection propagates. Now that multiple references are processed, one missing credential fails the update for the valid references too. [grounded: diff] [consensus 3/4: valid=3, invalid=1]
evt is spread into webhook payloads, so destinationCalendar changes from an object to an array, which breaks external consumers. The empty value is also null in handleNewBooking but [] elsewhere, as the e2e change shows. [grounded: diff] [consensus 3/3: valid=3]
raw comments (13)
**Google update/delete lose destination calendar fallback**
The fallback `event.destinationCalendar?.find(cal => cal.externalId === externalCalendarId)` only runs when `externalCalendarId` is falsy, so it can never match. The calendar falls back to undefined/primary instead of the destination calendar. Fall back to the first destination calendar's externalId (`event.destinationCalendar?.[0]?.externalId`).
```
packages/app-store/googlecalendar/lib/CalendarService.ts:254 const selectedCalendar = externalCalendarId
packages/app-store/googlecalendar/lib/CalendarService.ts:255 ? externalCalendarId
packages/app-store/googlecalendar/lib/CalendarService.ts:256 : event.destinationCalendar?.find((cal) => cal.externalId === externalCalendarId)?.externalId;
packages/app-store/googlecalendar/lib/CalendarService.ts:315 const calendarId = externalCalendarId
```
**Google event created on primary, not chosen calendar**
`selectedCalendar` is now found by matching `cal.credentialId === credentialId`. Destination calendars without a credentialId never match, so events go to "primary" instead of the destination's externalId. Fall back to the first destination calendar's externalId when no credentialId match exists.
```
packages/app-store/googlecalendar/lib/CalendarService.ts:145 // Find in calEventRaw.destinationCalendar the one with the same credentialId
packages/app-store/googlecalendar/lib/CalendarService.ts:147 const selectedCalendar = calEventRaw.destinationCalendar?.find(
packages/app-store/googlecalendar/lib/CalendarService.ts:148 (cal) => cal.credentialId === credentialId
packages/app-store/googlecalendar/lib/CalendarService.ts:149 )?.externalId;
```
**Calendar externalId not saved without credentialId**
In the destination-without-credentialId branch, `createEvent(c, event)` is called without `destination.externalId`. `result.externalId` is then undefined, so the booking reference loses `externalCalendarId`, which used to come from `evt.destinationCalendar.externalId`. Pass `destination.externalId` in this branch too.
```
packages/core/EventManager.ts:374 }
packages/core/EventManager.ts:375 } else {
packages/core/EventManager.ts:376 const destinationCalendarCredentials = this.calendarCredentials.filter(
packages/core/EventManager.ts:377 (c) => c.type === destination.integration
```
**Other Lark hosts get no collective event**
In collective bookings, every Lark host's credential is used with the first destination's calendarId, which is the main host's calendar. Other hosts' events go to a calendar their account doesn't own, so they are not created there. Pick the destination whose credentialId matches the credential.
The same mistake is at `packages/app-store/office365calendar/lib/CalendarService.ts:73`.
```
packages/app-store/larkcalendar/lib/CalendarService.ts:128 const [mainHostDestinationCalendar] = event.destinationCalendar ?? [];
packages/app-store/larkcalendar/lib/CalendarService.ts:129 const calendarId = mainHostDestinationCalendar?.externalId;
```
**Crash on Google Meet when no destination calendar**
`mainHostDestinationCalendar` is undefined when `evt.destinationCalendar` is null or an empty array, and `.integration` is read without `?.`. Any booking with Meet location and no destination calendar now throws instead of falling back to Cal Video. Use `mainHostDestinationCalendar?.integration`.
```
packages/core/EventManager.ts:116 // Fallback to Cal Video if Google Meet is selected w/o a Google Cal
packages/core/EventManager.ts:117 // @NOTE: destinationCalendar it's an array now so as a fallback we will only check the first one
packages/core/EventManager.ts:118 const [mainHostDestinationCalendar] = evt.destinationCalendar ?? [];
packages/core/EventManager.ts:119 if (evt.location === MeetLocationType && mainHostDestinationCalendar.integration !== "google_calendar") {
```
**Org slug set with billing, lost without**
The slug condition was inverted. With billing enabled, the org gets its slug at creation, before the payment-gated upgrade assigns it. With billing disabled, neither slug nor requestedSlug is stored, so the org has no slug. Restore `...(!IS_TEAM_BILLING_ENABLED && { slug })`.
```
packages/trpc/server/routers/viewer/organizations/create.handler.ts:151 ...(IS_TEAM_BILLING_ENABLED ? { slug } : {}),
packages/trpc/server/routers/viewer/organizations/create.handler.ts:152 metadata: {
packages/trpc/server/routers/viewer/organizations/create.handler.ts:153 ...(IS_TEAM_BILLING_ENABLED ? { requestedSlug: slug } : {}),
packages/trpc/server/routers/viewer/organizations/create.handler.ts:151 (base) ...(!IS_TEAM_BILLING_ENABLED && { slug }),
```
**Video references lose credentialId**
The reference's `credentialId` is now `undefined` for every non-calendar result. Video references (Zoom, Daily, etc.) used to store `result.credentialId`, so later updates/deletes of the meeting can't find the right credential. Use `result.credentialId` for non-calendar types as before.
```
packages/core/EventManager.ts:170 credentialId: isCalendarType ? result.credentialId : undefined,
packages/core/EventManager.ts:168 (base) credentialId: isCalendarType ? evt.destinationCalendar?.credentialId : result.credentialId,
packages/core/videoClient.ts:70 credentialId: number;
packages/core/videoClient.ts:71 } = {
packages/core/videoClient.ts:72 appName: credential.appName,
packages/core/videoClient.ts:73 type: credential.type,
packages/core/videoClient.ts:74 uid,
packages/core/videoClient.ts:75 originalEvent: calEvent,
packages/core/videoClient.ts:76 success: false,
packages/core/videoClient.ts:77 createdEvent: undefined,
```
**updateLocation drops calendar reference ids**
`updateLocation` now builds `externalCalendarId` and `credentialId` from `result.externalId`/`result.credentialId`, but `CalendarManager.updateEvent` returns neither. Reference rows recreated by editLocation lose their externalCalendarId and credentialId. Return `externalId` and `credentialId` from `updateEvent`, or reuse the existing booking reference values.
```
packages/core/EventManager.ts:208 externalCalendarId: result.externalId,
packages/core/EventManager.ts:209 credentialId: result.credentialId ?? undefined,
```
**Team calendars dropped when organizer has none**
Team members' destination calendars are pushed with `evt.destinationCalendar?.push(...)`, but `destinationCalendar` is `null` when neither the event type nor organizer has one. The optional chain silently skips the push, so collective hosts' calendars get no event. Initialize `destinationCalendar` to an array and push into it, or assign the combined array.
```
packages/features/bookings/lib/handleNewBooking.ts:1063 destinationCalendar: eventType.destinationCalendar
packages/features/bookings/lib/handleNewBooking.ts:1064 ? [eventType.destinationCalendar]
packages/features/bookings/lib/handleNewBooking.ts:1065 : organizerUser.destinationCalendar
packages/features/bookings/lib/handleNewBooking.ts:1066 ? [organizerUser.destinationCalendar]
```
**Google delete fallback never finds a calendar**
In `deleteEvent`, the fallback finds a destination whose `externalId === externalCalendarId` only when `externalCalendarId` is falsy, so it never matches. Fall back to `event.destinationCalendar?.[0]?.externalId`.
```
packages/app-store/googlecalendar/lib/CalendarService.ts:315 const calendarId = externalCalendarId
packages/app-store/googlecalendar/lib/CalendarService.ts:316 ? externalCalendarId
packages/app-store/googlecalendar/lib/CalendarService.ts:317 : event.destinationCalendar?.find((cal) => cal.externalId === externalCalendarId)?.externalId;
```
**Recurring cancel repeats deletions per reference**
The recurring cleanup, which deletes every remaining booking's events across all user credentials, now runs inside the loop over calendar references. With N references it repeats N times. Run the recurring cleanup once, outside the per-reference loop.
```
packages/features/bookings/lib/handleCancelBooking.ts:436 },
packages/features/bookings/lib/handleCancelBooking.ts:437 });
packages/features/bookings/lib/handleCancelBooking.ts:438 if (foundCalendarCredential) {
packages/features/bookings/lib/handleCancelBooking.ts:439 calendarCredential = foundCalendarCredential;
```
**Deleted credential fails whole calendar update**
When a reference's credentialId is in neither calendarCredentials nor the DB, updateEvent gets an undefined credential and throws reading credential.appName. The unawaited Promise.all rejects and fails the whole update, including valid references. Skip references whose credential can't be found.
```
packages/core/EventManager.ts:506 let calenderExternalId: string | null = null;
packages/core/EventManager.ts:507 if (bookingExternalCalendarId) {
packages/core/EventManager.ts:508 calenderExternalId = bookingExternalCalendarId;
packages/core/EventManager.ts:509 }
```
**Webhook payload destinationCalendar shape changed**
`evt.destinationCalendar` is now an array and is serialized into webhook payloads, so receivers reading `destinationCalendar.externalId` break. The empty value is also null for created events but [] for rejected ones. Keep the payload shape stable (send the first entry) and use one empty value.
```
packages/features/bookings/lib/handleNewBooking.ts:1063 destinationCalendar: eventType.destinationCalendar
packages/features/bookings/lib/handleNewBooking.ts:1064 ? [eventType.destinationCalendar]
packages/features/bookings/lib/handleNewBooking.ts:1065 : organizerUser.destinationCalendar
packages/features/bookings/lib/handleNewBooking.ts:1066 ? [organizerUser.destinationCalendar]
```
greptile · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
| d3 | medium | ✗ | — |
| d4 | high | ✓ | exact |
| d5 | high | ✗ | — |
| d6 | high | ✗ | — |
| d7 | medium | ✓ | off by one |
| d8 | medium | ✓ | off by one |
Google createEvent now selects calendar by credentialId match, falling back to "primary"; with no credentialId and no externalId passed, the selected externalId is lost (previously used destinationCalendar.externalId), and the reference's externalCalendarId becomes undefined. [grounded: diff] [consensus 5/5: valid=5]
If DB lookup fails, credential stays undefined; updateEvent accesses credential.appName and rejects, causing the un-awaited Promise.all(result) to reject the whole multi-reference update. Mechanism detail ('skips later updates') is slightly off since promises still start, but the claimed failure of all results holds and is worsened by the new loop. [grounded: diff] [consensus 5/5: valid=5]
raw comments (7)
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **Missing Calendar Crashes Booking**
When a Google Meet booking has no destination calendar, `mainHostDestinationCalendar` is `undefined`, so accessing `.integration` throws before the Cal Video fallback can run. New bookings explicitly allow `destinationCalendar` to be `null`, making this a reachable booking-creation failure.
```suggestion
if (evt.location === MeetLocationType && mainHostDestinationCalendar?.integration !== "google_calendar") {
```
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **Co-host Calendar Is Misrouted**
Collective booking creation calls each host credential with the full destination-calendar array, but this code always chooses the first destination. A Lark co-host therefore attempts to create an event using the organizer's calendar ID, which can fail or write to the wrong calendar. The Office 365 implementation has the same first-entry assumption.
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **Selected Calendar ID Is Lost**
A destination calendar can specify a non-primary `externalId` without a `credentialId`, but this branch calls `createEvent` without that external ID. The event is then routed to the provider's primary calendar, and its booking reference cannot preserve the selected calendar for later updates or deletion.
```suggestion
createdEvents = createdEvents.concat(
await Promise.all(
destinationCalendarCredentials.map(async (c) =>
await createEvent(c, event, destination.externalId)
)
)
);
```
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **Recurring Events Remain Undeleted**
Collective bookings can now have multiple calendar references, but this recurring-cancellation loop selects only the first reference from each booking and sends it through every user calendar credential. Additional host events remain undeleted, while the first event receives duplicate or misrouted deletion requests.
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **Stale Credential Aborts Updates**
When a booking reference points to a credential that has since been deleted, the database lookup leaves `credential` undefined, but the code still passes it to `updateEvent`. That throws out of the shared loop, so every later valid calendar reference is skipped and reported as failed.
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **Organizations Lose Their Slug**
When team billing is disabled, including on ordinary self-hosted deployments, these conditions store neither `slug` nor `metadata.requestedSlug`. The resulting organization cannot complete the non-billing publish flow, and subsequent team creation rejects it because it has no supported identifier.
```suggestion
...(!IS_TEAM_BILLING_ENABLED && { slug }),
metadata: {
...(IS_TEAM_BILLING_ENABLED && { requestedSlug: slug }),
```
<h3>Greptile Summary</h3>
This PR expands calendar events and booking references to support multiple destination calendars, principally for collective hosts, and updates downstream calendar, cancellation, payment, and booking flows. It also changes organization slug assignment.
- Creates and updates calendar events across multiple destination credentials.
- Persists credential and external-calendar routing data in booking references.
- Converts existing event producers and provider adapters to the destination-calendar array contract.
- Contains blocking regressions in empty-destination handling, provider routing, recurring cancellation, stale-credential handling, and organization creation.
<h3>Confidence Score: 0/5</h3>
This PR is not safe to merge because several normal booking and organization workflows can crash, target the wrong calendar, leave external events undeleted, or become unusable.
Empty-destination Google Meet bookings can throw; collective Lark and Office events use the wrong destination; legacy destination records lose calendar routing; recurring cancellation mishandles multiple references; a stale credential prevents remaining updates; and billing-disabled organizations lose both supported slug fields.
**Files Needing Attention:** packages/core/EventManager.ts, packages/features/bookings/lib/handleCancelBooking.ts, packages/app-store/larkcalendar/lib/CalendarService.ts, packages/app-store/office365calendar/lib/CalendarService.ts, packages/trpc/server/routers/viewer/organizations/create.handler.ts
<details><summary><h3>Important Files Changed</h3></summary>
| Filename | Overview |
|----------|----------|
| packages/core/EventManager.ts | Adds multi-destination creation and update routing, but crashes on empty destinations, loses some external calendar IDs, and aborts all updates when one credential is stale. |
| packages/features/bookings/lib/handleCancelBooking.ts | Iterates multiple booking references, but recurring cancellation repeatedly processes only the first reference and can leave other host events undeleted. |
| packages/features/bookings/lib/handleNewBooking.ts | Builds collective-host destination arrays and persists the primary destination, exposing downstream assumptions about empty and multi-calendar arrays. |
| packages/app-store/larkcalendar/lib/CalendarService.ts | Adapts to destination arrays by selecting the first entry, which misroutes collective co-host credentials. |
| packages/app-store/office365calendar/lib/CalendarService.ts | Adapts to destination arrays by selecting the first entry, which misroutes collective co-host credentials. |
| packages/app-store/googlecalendar/lib/CalendarService.ts | Selects creation calendars by credential ID, but missing external IDs make later update and deletion routing invalid. |
| packages/trpc/server/routers/viewer/organizations/create.handler.ts | Reverses slug assignment conditions, breaking organization setup when team billing is disabled. |
</details>
<details open><summary><h3>Flowchart</h3></summary>
```mermaid
%%{init: {'theme': 'neutral'}}%%
flowchart TD
B[Collective booking] --> D[Destination calendar array]
D --> E[EventManager iterates destinations]
E --> G[Google credential-matched calendar]
E --> L[Lark uses first destination]
E --> O[Office 365 uses first destination]
G --> R[Booking calendar references]
L --> R
O --> R
R --> U[Update or reschedule]
R --> C[Recurring cancellation]
U --> S{Credential still exists?}
S -->|Yes| X[Update external event]
S -->|No| F[Current loop aborts remaining updates]
C --> Y[Current code repeatedly selects first reference]
```
</details>
<!-- greptile_other_comments_section -->
<sub>Reviews (1): Last reviewed commit: ["Update apps/web/pages/api/cron/bookingRe..."](https://github.com/drape-io/crbench-greptile-2026-09/commit/4d3e767d6aae66d3eac34225195e15b588cda86a) | [Re-trigger Greptile](https://app.greptile.com/api/retrigger?id=64284224)</sub>
Mjolnir (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
| d3 | medium | ✓ | exact |
| d4 | high | ✓ | exact |
| d5 | high | ✓ | off by one |
| d6 | high | ✓ | exact |
| d7 | medium | ✓ | exact |
| d8 | medium | ✗ | — |
`evt.destinationCalendar` falls back to `null` when neither the event type nor the organizer has a destination calendar. In that case the optional-chained push is a no-op, and the collective hosts' calendars collected in `teamDestinationCalendars` are thrown away. [grounded: diff] [consensus 3/3: valid=3]
The `find` only runs when `externalCalendarId` is falsy, so it compares each `externalId` against a falsy value and returns `undefined`. Before this change the code fell back to `destinationCalendar.externalId`. Google `update` now receives `calendarId: undefined`. [grounded: diff] [consensus 3/3: valid=3]
Before this change, non-calendar (video) results kept `result.credentialId`. Video references are now saved without it. The seat-cancellation path, and the video-delete path in `handleCancelBooking`, both need `reference.credentialId`, so they now silently skip the video meeting. [grounded: diff] [consensus 3/3: valid=3]
With no destination calendar, `?? []` destructures to `undefined`. Accessing `.integration` without optional chaining then throws a TypeError for Google Meet locations. The old code used `?.` and did not crash. [grounded: diff] [consensus 3/3: valid=3]
raw comments (10)
[P1] Crash when Google Meet is selected and there is no destination calendar
`evt.destinationCalendar ?? []` gives an empty array when there is no destination calendar, so `mainHostDestinationCalendar` is `undefined`. The next line then reads `mainHostDestinationCalendar.integration` without optional chaining. The old code used `evt.destinationCalendar?.integration`. Now, for any booking with location `integrations:google:meet` where neither the event type nor the organizer has a destination calendar, `create()` throws a TypeError. It should fall back to Cal Video instead.
[P2] Collective team members' destination calendars are dropped when the organizer has none
When neither `eventType.destinationCalendar` nor `organizerUser.destinationCalendar` is set, `evt.destinationCalendar` is `null`. `evt.destinationCalendar?.push(...teamDestinationCalendars)` then does nothing, and the destination calendars collected from the other collective hosts are thrown away. Whether the other hosts get calendar events depends on the first host having a destination calendar. The base should be an empty array, not `null`, so the team calendars are still added.
[P2] Non-Google calendar services always use the first host's calendar, even with another host's credential
`createAllCalendarEvents` now calls `createEvent` once per destination calendar, each time with that host's credential. Only Google uses the new `credentialId` argument to choose the matching destination. Office365 (here), Lark and CalDAV/BaseCalendarService (`packages/lib/CalendarService.ts:156-164`) always take `destinationCalendar[0]`, which belongs to the organizer. For a collective event, a second host on Office365 gets a POST to `/me/calendars/‹organizer's calendar id›/events` with their own token, which fails. A second CalDAV host's calendars get filtered by the organizer's calendar URL, so nothing matches and no event is created. Those hosts get no calendar event.
[P2] Google update has no calendar ID when the reference has no externalCalendarId
The fallback `event.destinationCalendar?.find((cal) =› cal.externalId === externalCalendarId)` only runs when `externalCalendarId` is falsy, so it can never match and always returns `undefined`. Before this change it fell back to the destination calendar's `externalId`. Now `calendar.events.update` gets `calendarId: undefined`, and rescheduling or updating a location fails for references stored without `externalCalendarId`. That includes legacy bookings and references created by the no-`credentialId` and fallback branches, which now store `result.externalId`, and that is undefined. The same dead fallback is in `deleteEvent`. It is less harmful there because `deleteEvent` still defaults to `"primary"`.
[P2] Video booking references no longer store credentialId
`credentialId: isCalendarType ? result.credentialId : undefined` now drops the credential ID for video results. The old code stored `result.credentialId` for them, and `createVideoEvent` still returns one. New `_video` references are therefore saved without `credentialId`. Code that relies on it then silently skips them, for example the seat-cancellation path in `handleCancelBooking.ts`, which only calls `updateMeeting` when `reference.credentialId` is set. Removing an attendee from a seated booking will then leave the video meeting unchanged.
[P1] Google Meet fallback crashes when there is no destination calendar
`evt.destinationCalendar ?? []` gives an empty array when the booking has no destination calendar (the common case: `handleNewBooking` sets it to `null`, and other callers pass `[]`). That makes `mainHostDestinationCalendar` `undefined`, so `mainHostDestinationCalendar.integration` throws a TypeError. The `&&` short-circuit only protects bookings whose location isn't Google Meet, so any Google Meet booking where neither the event type nor the organizer has a destination calendar now fails in `EventManager.create` instead of falling back to Cal Video. The old code used `?.` and did not have this problem.
[P1] Organization slug condition is inverted
The old code set `slug` only when team billing was disabled (`!IS_TEAM_BILLING_ENABLED && { slug }`) and stored `requestedSlug` in metadata when billing was enabled, so the slug was only claimed after payment. The new code drops the negation: `IS_TEAM_BILLING_ENABLED ? { slug } : {}`. With billing enabled, the org gets its slug immediately, before payment, and also gets `requestedSlug`. With billing disabled (self-hosted), the org is created with no slug at all. This looks like an accidental change, since the `requestedSlug` line still uses the un-negated condition.
[P1] Video meeting references no longer store `credentialId`
The reference mapping changed from `isCalendarType ? evt.destinationCalendar?.credentialId : result.credentialId` to `isCalendarType ? result.credentialId : undefined`, so the reference for a video result (Zoom, Daily, etc.) is now saved with no `credentialId`. `handleCancelBooking` only deletes a video meeting when `bookingVideoReference.credentialId` is set (`if (bookingVideoReference && bookingVideoReference.credentialId)`). As a result, cancelling a new booking will leave its third-party video meeting in place.
[P2] Google update/delete no longer fall back to the booking's destination calendar
In both `updateEvent` and `deleteEvent`, the fallback branch only runs when `externalCalendarId` is falsy, and it then looks for `cal.externalId === externalCalendarId`. That can never match a real calendar ID, so the fallback always resolves to `undefined`. Previously it used `event.destinationCalendar.externalId`. For booking references stored without `externalCalendarId` (older bookings, or references from the integration-type path where `createEvent` gets no `externalId`), updates now go out with `calendarId: undefined` and fail, and deletes go to `"primary"` instead of the calendar the event was actually created in (same pattern at lines 315-317).
[P2] Collective members' calendars are dropped when the organizer has no destination calendar
`evt.destinationCalendar` is set to `null` when neither the event type nor the organizer has a destination calendar. In that case `evt.destinationCalendar?.push(...teamDestinationCalendars)` does nothing, so the destination calendars collected from the other collective hosts are silently discarded and their calendars never get the event. Initialising to `[]`, or building the array including the team calendars, would avoid this; any empty-array checks downstream already handle `[]`.
Mjolnir (Sonnet 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
| d3 | medium | ✓ | exact |
| d4 | high | ✓ | exact |
| d5 | high | ✓ | off by one |
| d6 | high | ✗ | — |
| d7 | medium | ✓ | exact |
| d8 | medium | ✗ | — |
CalendarManager.updateEvent returns neither externalId nor credentialId, so the calendar references updateLocation builds now get undefined values. The old code took them from evt.destinationCalendar. [grounded: diff] [consensus 3/3: valid=3]
No externalId is passed here, and Google's createEvent now matches by credentialId, which can't match a destination with a null credentialId. The event goes to the primary calendar and the reference has no externalCalendarId. [grounded: diff] [consensus 3/3: valid=3]
The old code set slug only when billing was disabled; the new code sets it only when billing is enabled. That inverts the behaviour in both modes. [grounded: diff] [consensus 3/3: valid=3]
Destructuring an empty or null array leaves mainHostDestinationCalendar undefined, so reading .integration throws a TypeError for Meet locations. The old code used optional chaining. [grounded: diff] [consensus 3/3: valid=3]
This branch only runs when externalCalendarId is falsy, so the find can't match a real calendar. The old fallback to destinationCalendar.externalId is lost, and deletes fall through to primary. [grounded: diff] [consensus 3/3: valid=3]
The updateEvent result has no credentialId or externalId, so the persisted references lose both values. Previously they came from evt.destinationCalendar. [grounded: diff] [consensus 3/3: valid=3]
The recurring branch deletes events across all credentials and now runs once per calendar reference, so every deletion is repeated N times when there are several references. The old code ran it only once. [grounded: diff] [consensus 3/3: valid=3]
raw comments (12)
[P1] Organization slug/requestedSlug condition inverted
The original code spread `slug` when `!IS_TEAM_BILLING_ENABLED` and `requestedSlug` when `IS_TEAM_BILLING_ENABLED`. The rewrite changes the slug line to `IS_TEAM_BILLING_ENABLED ? { slug } : {}`, which flips the condition. With team billing enabled, the org is now created with its final slug before payment. With billing disabled, no slug is set at all. The change is unrelated to the destinationCalendar refactor and looks accidental.
[P1] Meet fallback dereferences possibly-undefined destination calendar
`mainHostDestinationCalendar` is `undefined` whenever `evt.destinationCalendar` is null or empty. Many callers now pass `[]`, for example the payment webhooks and the reminder cron. `mainHostDestinationCalendar.integration` then throws a TypeError. The old code used `evt.destinationCalendar?.integration`. Any booking with a Google Meet location and no destination calendar now crashes in `create()` instead of falling back to Cal Video. The fix is to use optional chaining.
[P2] updateLocation drops externalCalendarId and credentialId for calendar references
`updateLocation` builds `referencesToCreate` from the results of `updateAllCalendarEvents`. Those come from `CalendarManager.updateEvent`, which returns neither `externalId` nor `credentialId`. `externalCalendarId` is therefore always `undefined`, and `credentialId` is `undefined` for calendar results. The old code filled both from `evt.destinationCalendar`. After a location edit, the calendar booking references lose the calendar id and credential. Later updates and deletes then fall back to the legacy behavior of trying every credential.
[P2] Google update/delete lookups can never match the destination calendar
In the `externalCalendarId ? externalCalendarId : event.destinationCalendar?.find(cal =› cal.externalId === externalCalendarId)` fallback, `externalCalendarId` is falsy in that branch. The `find` therefore never matches (it compares against undefined or an empty string). The previous fallback to `event.destinationCalendar.externalId` is lost in both `updateEvent` and `deleteEvent` (line 317). When a reference has no stored externalCalendarId, the update or delete targets the default calendar instead of the destination calendar.
[P2] Destination calendars without credentialId lose their externalId on create
For destination calendars with no `credentialId`, `createEvent(c, event)` is called without the `externalId` argument. Google's `createEvent` now picks its calendar by `cal.credentialId === credentialId`, which can't match these entries. The event goes to "primary" instead of the destination `externalId`. The stored reference also gets `externalCalendarId: result.externalId`, which is `undefined`. The old code used `evt.destinationCalendar.externalId` in both places. This regresses legacy destination calendars that have only an `integration` set.
[P2] Non-Google calendars use the first host's calendar for every credential
For collective team events, `evt.destinationCalendar` now holds one entry per host, and `createAllCalendarEvents` calls `createEvent` once per entry. The Office365, Lark and CalDAV base services ignore the `credentialId` argument and always read `destinationCalendar[0]`. Each team member's credential therefore creates its event in the first host's calendar id. This fails or creates duplicate events in the wrong calendar. Only the Google service was updated to select the calendar by credential.
[P1] Org slug / requestedSlug logic inverted
The change from `!IS_TEAM_BILLING_ENABLED && { slug }` to `IS_TEAM_BILLING_ENABLED ? { slug } : {}` flips the condition. With team billing enabled, the slug is now written directly to the org, bypassing the pending `requestedSlug` flow. With billing disabled, no slug is set at all, so the org is created without one. Both modes now behave the opposite of what they did before. The change also has nothing to do with the destinationCalendar refactor.
[P1] Unguarded `.integration` access crashes Meet bookings that have no destination calendar
`mainHostDestinationCalendar` is `undefined` when `evt.destinationCalendar` is null or empty. This happens for a user with no destination calendar, and every caller above now passes `[]` in that case. The condition `evt.location === MeetLocationType && mainHostDestinationCalendar.integration` then throws a TypeError instead of falling back to Cal Video. The old code used `?.`. Use `mainHostDestinationCalendar?.integration`.
[P2] Google update/delete lose their destination-calendar fallback
In the `: event.destinationCalendar?.find((cal) =› cal.externalId === externalCalendarId)` branch, `externalCalendarId` is already falsy. The `find` can therefore never match a real calendar and always yields `undefined`. When a booking reference has no `externalCalendarId` (older bookings), `updateEvent` no longer falls back to the destination calendar's `externalId`. The same pattern in `deleteEvent` (around lines 315-317) means those events fall through to "primary" and may update or delete the wrong calendar. The fallback should use the first destination calendar's `externalId`.
[P2] Location update drops externalCalendarId and credentialId from new calendar references
`updateLocation` now reads `result.externalId` and `result.credentialId`. Those results come from `updateAllCalendarEvents` → `CalendarManager.updateEvent`, which returns neither field (its return object only has `appName`, `type`, `success`, `uid`, `updatedEvent`, `originalEvent`, `calError` and `calWarnings`). `editLocation.handler` persists `referencesToCreate`, so the new calendar references are stored with null `externalCalendarId` and `credentialId`. Later updates and cancellations then lose the target calendar and credential. Previously these values came from `evt.destinationCalendar`.
[P2] Team destination calendars are silently dropped when the organizer has none
`evt.destinationCalendar` is `null` when neither the event type nor the organizer has a destination calendar. `evt.destinationCalendar?.push(...teamDestinationCalendars)` is then a no-op. For a COLLECTIVE event where only the other hosts have destination calendars, their calendars are never used. The collective-event feature does not work in that case.
[P2] Recurring cancellation repeats the whole delete loop for every calendar reference
The recurring branch deletes every remaining booking's calendar event across all user calendar credentials. That branch now runs inside `for (const reference of bookingCalendarReference)`. A booking with N calendar references (now normal with multiple destination calendars) therefore repeats the whole deletion N times. It issues duplicate `deleteEvent` calls, which can fail or return 404/410, and the cost grows with N. Run the recurring branch once, outside the per-reference loop.
qodo · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✗ | — |
| d3 | medium | ✗ | — |
| d4 | high | ✗ | — |
| d5 | high | ✗ | — |
| d6 | high | ✗ | — |
| d7 | medium | ✗ | — |
| d8 | medium | ✗ | — |
raw comments (2)
<h3>Qodo is busy working</h3>
Check back in a few minutes. Qodo's code review agents are on it.
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<img src="https://www.qodo.ai/wp-content/uploads/2026/01/anteater-looking-at-ants-01-transparent-bg-croped-ezgif.com-optimize-1.gif" width="30%">
<h3>PR Summary by Qodo</h3>
Support multiple destination calendars for collective bookings
<code>✨ Enhancement</code> <code>🐞 Bug fix</code> <code>🧪 Tests</code> <code>🕐 40+ Minutes</code>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<details>
<summary>AI Description</summary>
<dl>
<dd>
<br/>
><pre>
>• Supports collective bookings across every host's destination calendar.
>• Routes create, update, and delete operations through matching credentials and stored references.
>• Migrates calendar event contracts and integrations to destination-calendar arrays.
></pre>
</dd>
</dl>
</details>
<details>
<summary>Diagram</summary>
<dl>
<dd>
<br/>
```mermaid
graph TD
A["Booking handlers"] --> B["Calendar event"] --> C["Event manager"] --> D["Calendar manager"] --> E["Calendar providers"]
C --> F[("Credential store")]
E --> G["Booking references"]
G --> C
```
</dd>
</dl>
</details>
<details>
<summary>High-Level Assessment</summary>
<dl>
<dd>
<br/>
>The following are alternative approaches to this PR:
<details>
<summary><b>1. Credential-keyed destination map</b></summary>
<dl>
<dd>
- ➕ Provides direct destination lookup by credential ID
- ➕ Avoids repeated array searches within provider implementations
- ➖ Loses explicit organizer-first ordering without additional metadata
- ➖ Requires a broader contract migration across booking and email consumers
</dd>
</dl>
</details>
<details>
<summary><b>2. Persist booking destinations relationally</b></summary>
<dl>
<dd>
- ➕ Makes all host calendars first-class booking data
- ➕ Provides an authoritative source for lifecycle operations
- ➖ Requires database schema and migration work
- ➖ Adds persistence complexity when references already identify created events
</dd>
</dl>
</details>
>**Recommendation:** The destination array plus per-event booking references is the best incremental approach because it preserves organizer-first behavior and avoids a schema migration. A shared credential-resolution helper would be a useful follow-up to remove duplicated database fallback logic from creation, update, and cancellation paths.
</dd>
</dl>
</details>
<details>
<summary> Files changed (22) <code> +368 / -216 </code> </summary>
<dl>
<dd>
<br/>
<details>
<summary>Enhancement (17) <code> +295 / -166 </code></summary>
<dl>
<dd>
<details>
<summary>bookingReminder.ts<code>Wrap reminder destination calendars in an array</code> <code>+2/-2</code></summary>
<br/>
>Wrap reminder destination calendars in an array
>
><pre>
>• Normalizes the booking or user destination calendar into the new CalendarEvent array contract before sending organizer reminders.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/17/files#diff-0ed1a25bc2b8d928031876cb39f6f3b36f92f7ffcb685ba658c4e22c9a73650a'>apps/web/pages/api/cron/bookingReminder.ts</a>
</details>
<details>
<summary>CalendarService.ts<code>Route Google events by destination credential</code> <code>+22/-11</code></summary>
<br/>
>Route Google events by destination credential
>
><pre>
>• Accepts the active credential ID when creating events and selects its matching destination calendar. Organizer metadata continues to use the primary host destination while update and delete paths accommodate the array contract.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/17/files#diff-6bfbaf63c841dc9343dba0c7487e30a546ffe2a63c9d9418379d0dbb88644d27'>packages/app-store/googlecalendar/lib/CalendarService.ts</a>
</details>
<details>
<summary>CalendarService.ts<code>Adapt Lark operations to destination arrays</code> <code>+8/-4</code></summary>
<br/>
>Adapt Lark operations to destination arrays
>
><pre>
>• Uses the primary host destination calendar for create, attendee, update, and delete operations while preserving explicit external-calendar overrides.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/17/files#diff-a6aff4ec08b825b3e3be78d11a16b79ed4b91d17cc3a005f1bdb59799e642e1e'>packages/app-store/larkcalendar/lib/CalendarService.ts</a>
</details>
<details>
<summary>CalendarService.ts<code>Adapt Office 365 event creation to destination arrays</code> <code>+3/-2</code></summary>
<br/>
>Adapt Office 365 event creation to destination arrays
>
><pre>
>• Builds the Microsoft Graph events endpoint from the primary host destination calendar, falling back to the default calendar.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/17/files#diff-4f075841987a4d1474327cb5c6097757822d5df69616798d8014ff3207a3034b'>packages/app-store/office365calendar/lib/CalendarService.ts</a>
</details>
<details>
<summary>CalendarManager.ts<code>Propagate credential and destination identifiers</code> <code>+24/-19</code></summary>
<br/>
>Propagate credential and destination identifiers
>
><pre>
>• Passes the active credential ID into calendar providers and returns both credential and external calendar identifiers for reference creation. Also standardizes the hidden-notes organizer spelling.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/17/files#diff-1edf77640cddbeb991fcd8211c16508c055ff086f3c04f58a4e951f1e6710b14'>packages/core/CalendarManager.ts</a>
</details>
<details>
<summary>EventManager.ts<code>Process every calendar destination and reference</code> <code>+124/-68</code></summary>
<br/>
>Process every calendar destination and reference
>
><pre>
>• Creates events for every destination calendar, resolves missing credentials from the database, and records credential-specific result metadata. Updates now process all calendar references instead of only the first reference.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/17/files#diff-f028774ebd744c3141fb60f0fb171c59a2ae4773b285b70f834114e7a3d7afa2'>packages/core/EventManager.ts</a>
</details>
<details>
<summary>class.ts<code>Model destination calendars as an array</code> <code>+1/-1</code></summary>
<br/>
>Model destination calendars as an array
>
><pre>
>• Updates the CalendarEvent class contract to allow multiple destination calendars.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/17/files#diff-5ff78615d5b9f07fd744a6beee2dd3c6ca6ff907fb9bb112f67fa63937ccb63f'>packages/core/builders/CalendarEvent/class.ts</a>
</details>
<details>
<summary>handleNewBooking.ts<code>Collect destination calendars for collective hosts</code> <code>+72/-43</code></summary>
<br/>
>Collect destination calendars for collective hosts
>
><pre>
>• Adds each collective host's destination calendar to CalendarEvent and stores the primary destination on the booking. It also hardens user loading errors and carries scheduling type through event creation.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/17/files#diff-a7c21727d9a0d4d1aaff9d24fca9293bc28468861bc8022dfa03116908b6fae7'>packages/features/bookings/lib/handleNewBooking.ts</a>
</details>
<details>
<summary>paypal-webhook.ts<code>Normalize PayPal booking destination calendars</code> <code>+5/-1</code></summary>
<br/>
>Normalize PayPal booking destination calendars
>
><pre>
>• Wraps the booking or user destination calendar in an array when constructing events after successful PayPal payments.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/17/files#diff-a13d00a61c07ea04cdd181273c0a3f526274257089bd2d6527323773f5fe090c'>packages/features/ee/payments/api/paypal-webhook.ts</a>
</details>
<details>
<summary>webhook.ts<code>Normalize Stripe booking destination calendars</code> <code>+4/-4</code></summary>
<br/>
>Normalize Stripe booking destination calendars
>
><pre>
>• Converts selected booking or user destination calendars to arrays for Stripe booking retrieval and payment-success event processing.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/17/files#diff-a7465f88de2bc8248ea4b41e520970c3c294bfb5e54e1de6a6df45900efe3307'>packages/features/ee/payments/api/webhook.ts</a>
</details>
<details>
<summary>CalendarService.ts<code>Use primary destinations in generic calendar services</code> <code>+7/-5</code></summary>
<br/>
>Use primary destinations in generic calendar services
>
><pre>
>• Updates iCal filtering and integration-calendar primary selection to read the primary host destination from the array contract.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/17/files#diff-5513752d49ca0ab1439d31deb7de4254db8bd37a192da60caa2f346d8552eb6a'>packages/lib/CalendarService.ts</a>
</details>
<details>
<summary>deleteCredential.handler.ts<code>Normalize cancellation destinations after credential deletion</code> <code>+5/-1</code></summary>
<br/>
>Normalize cancellation destinations after credential deletion
>
><pre>
>• Constructs cancellation events with an array containing the booking or user destination calendar when a credential is removed.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/17/files#diff-d5bbe62ffe47184bd72f97b2b4f711f941f579c0711aa4325753cee98c3c0cdb'>packages/trpc/server/routers/loggedInViewer/deleteCredential.handler.ts</a>
</details>
<details>
<summary>confirm.handler.ts<code>Normalize confirmed booking destination calendars</code> <code>+5/-1</code></summary>
<br/>
>Normalize confirmed booking destination calendars
>
><pre>
>• Wraps the selected booking or user destination calendar in an array before confirming and creating calendar events.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/17/files#diff-5b9cda898ebe85743cda6fafe2e3b717e4472ef671890844941ba8fe11905562'>packages/trpc/server/routers/viewer/bookings/confirm.handler.ts</a>
</details>
<details>
<summary>editLocation.handler.ts<code>Normalize destinations during location edits</code> <code>+5/-1</code></summary>
<br/>
>Normalize destinations during location edits
>
><pre>
>• Uses the destination-calendar array contract when rebuilding an event after its location changes.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/17/files#diff-73d0c6b2e4987d4a3cc5324f33ed69c86744f37f494be6d6c9fa8e4ec167893a'>packages/trpc/server/routers/viewer/bookings/editLocation.handler.ts</a>
</details>
<details>
<summary>requestReschedule.handler.ts<code>Normalize reschedule destination calendars</code> <code>+3/-1</code></summary>
<br/>
>Normalize reschedule destination calendars
>
><pre>
>• Wraps the booking destination calendar in an array when creating the reschedule cancellation event.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/17/files#diff-996f30ba1e1ba6fd2ab362610a0d2db28f464b8125cb33e6ef4903f05de1d69f'>packages/trpc/server/routers/viewer/bookings/requestReschedule.handler.ts</a>
</details>
<details>
<summary>Calendar.d.ts<code>Extend calendar contracts for multiple destinations</code> <code>+4/-2</code></summary>
<br/>
>Extend calendar contracts for multiple destinations
>
><pre>
>• Changes CalendarEvent destinations to an array, adds scheduling type, and requires calendar creation calls to identify the active credential.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/17/files#diff-a473357fe87256dbdcd09db4fdfd6090829d87196b788a810c8580984e916834'>packages/types/Calendar.d.ts</a>
</details>
<details>
<summary>EventManager.d.ts<code>Expose destination identifiers in event results</code> <code>+1/-0</code></summary>
<br/>
>Expose destination identifiers in event results
>
><pre>
>• Adds the external calendar identifier to EventResult so created references retain the destination used by each credential.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/17/files#diff-e67496263e565e4f0aa99cb10ccbb48fde6b281bcd5d4ec4903ffb55ba249826'>packages/types/EventManager.d.ts</a>
</details>
</dd>
</dl>
</details>
<details>
<summary>Bug fix (3) <code> +70 / -48 </code></summary>
<dl>
<dd>
<details>
<summary>BrokenIntegrationEmail.tsx<code>Read the primary destination in integration emails</code> <code>+3/-2</code></summary>
<br/>
>Read the primary destination in integration emails
>
><pre>
>• Derives the broken calendar integration name from the first destination calendar under the new array contract.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/17/files#diff-9a7c3c4c01957b78277ab704d189f3bbb98702d127bd2d745a738adb23a819ee'>packages/emails/src/templates/BrokenIntegrationEmail.tsx</a>
</details>
<details>
<summary>handleCancelBooking.ts<code>Delete events across all calendar references</code> <code>+65/-44</code></summary>
<br/>
>Delete events across all calendar references
>
><pre>
>• Builds cancellation events with destination arrays and deletes every referenced calendar event. Missing user credentials are loaded directly from the database, while legacy references retain the all-credentials fallback.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/17/files#diff-87a46901f0685bc1affbfaab91860fb47aaf0f689c17bd379a56d8a9aaa51716'>packages/features/bookings/lib/handleCancelBooking.ts</a>
</details>
<details>
<summary>create.handler.ts<code>Correct organization slug assignment condition</code> <code>+2/-2</code></summary>
<br/>
>Correct organization slug assignment condition
>
><pre>
>• Assigns the organization slug and requested-slug metadata only when team billing is enabled.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/17/files#diff-42734d743fea59a1d1cee85fe56008373af9ef29fc61e207c6c707d44f6c6dfa'>packages/trpc/server/routers/viewer/organizations/create.handler.ts</a>
</details>
</dd>
</dl>
</details>
<details>
<summary>Refactor (1) <code> +2 / -1 </code></summary>
<dl>
<dd>
<details>
<summary>builder.ts<code>Separate Booking type import</code> <code>+2/-1</code></summary>
<br/>
>Separate Booking type import
>
><pre>
>• Converts Booking to a type-only import while retaining Prisma as a runtime import.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/17/files#diff-4084c97c8b3b2988e3c1de3f5de7aa8187c0abf3f00711841a8ea629d81fe0e9'>packages/core/builders/CalendarEvent/builder.ts</a>
</details>
</dd>
</dl>
</details>
<details>
<summary>Tests (1) <code> +1 / -1 </code></summary>
<dl>
<dd>
<details>
<summary>webhook.e2e.ts<code>Update webhook expectation for destination arrays</code> <code>+1/-1</code></summary>
<br/>
>Update webhook expectation for destination arrays
>
><pre>
>• Changes the rejected-booking webhook assertion from a null destination calendar to an empty array.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/17/files#diff-626ed3e0802f81e81883f572981e05f39b85bb11e9510bf25c911379216015a1'>apps/web/playwright/webhook.e2e.ts</a>
</details>
</dd>
</dl>
</details>
</dd>
</dl>
</details>