Skip to content

feat(reschedule): respect guest availability during host-initiated rescheduling#28713

Closed
Harry-jain wants to merge 4 commits intocalcom:mainfrom
Harry-jain:feat/guest-availability-reschedule
Closed

feat(reschedule): respect guest availability during host-initiated rescheduling#28713
Harry-jain wants to merge 4 commits intocalcom:mainfrom
Harry-jain:feat/guest-availability-reschedule

Conversation

@Harry-jain
Copy link
Copy Markdown

/claim #16378

Adds guest availability awareness to host-initiated rescheduling.

The system now intersects host availability with guest busy times (for Cal.com users), preventing invalid slot selection. Handles edge cases like pending bookings, secondary emails, and excludes the current booking.

Includes tests and integrates cleanly with the existing availability pipeline.

Implements guest availability filtering during host-initiated reschedule.
When a host reschedules a booking, the system checks if attendees are
Cal.com users and filters out time slots where they are unavailable.

Key Features:
- Case-insensitive email lookup (primary + verified secondary emails)
- Includes both ACCEPTED and PENDING bookings as busy
- Excludes the booking being rescheduled (prevents self-blocking)
- Skips COLLECTIVE events (already coordinated)
- Graceful error handling (never blocks rescheduling)

Implementation:
- Created GuestBusyTimesService for guest availability lookup
- Integrated into AvailableSlotsService slot calculation flow
- Added DI tokens, modules, and container configuration
- Created NestJS wrapper for API v2 integration

Test Coverage:
- 15+ unit tests covering all edge cases
- Tests for email matching, deduplication, error handling

Closes calcom#16378
@Harry-jain Harry-jain requested review from a team as code owners April 2, 2026 19:00
Copilot AI review requested due to automatic review settings April 2, 2026 19:00
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 11 files

Prompt for AI agents (unresolved issues)

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/features/busyTimes/services/getGuestBusyTimes.ts">

<violation number="1" location="packages/features/busyTimes/services/getGuestBusyTimes.ts:129">
P1: Guest busy-time attendee matching uses only primary email after secondary-email user resolution, which can omit attendee bookings made under verified secondary emails.</violation>

<violation number="2" location="packages/features/busyTimes/services/getGuestBusyTimes.ts:147">
P1: Custom agent: **Avoid Logging Sensitive Information**

Do not log the raw error object in this guest-availability path; log only sanitized, non-sensitive error metadata to avoid leaking PII/sensitive context.

(Based on your team's feedback about not logging raw error objects that may expose sensitive data.) [FEEDBACK_USED]</violation>
</file>

<file name="packages/trpc/server/routers/viewer/slots/util.ts">

<violation number="1" location="packages/trpc/server/routers/viewer/slots/util.ts:1540">
P1: Custom agent: **Avoid Logging Sensitive Information**

Do not log the raw `error` object here; log only sanitized fields (for example, error name) to avoid leaking sensitive data.

(Based on your team's feedback about avoiding raw error-object logging that can expose sensitive data.) [FEEDBACK_USED]</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds guest availability awareness to the slot-generation pipeline during rescheduling by excluding candidate slots that overlap with busy times of Cal.com guest users on the original booking.

Changes:

  • Introduces GuestBusyTimesService to derive guest busy times (via booking + secondary-email user lookup).
  • Integrates guest busy-time filtering into AvailableSlotsService when rescheduleUid is present.
  • Wires the new service through DI + exposes it via platform libraries and the API v2 Nest module, with new unit tests.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
packages/trpc/server/routers/viewer/slots/util.ts Injects guestBusyTimesService and filters available slots against guest busy windows during reschedule.
packages/platform/libraries/slots.ts Re-exports GuestBusyTimesService for platform/API consumption.
packages/features/di/tokens.ts Adds DI tokens for guest busy times service + module.
packages/features/di/modules/GuestBusyTimes.ts Adds DI module binding for GuestBusyTimesService.
packages/features/di/modules/AvailableSlots.ts Injects guestBusyTimesService into AvailableSlotsService.
packages/features/di/containers/AvailableSlots.ts Loads the guest busy times DI module into the available-slots container.
packages/features/busyTimes/services/getGuestBusyTimes.ts New service: resolves Cal.com guests from booking attendees and returns their busy bookings in range.
packages/features/busyTimes/services/getGuestBusyTimes.test.ts Unit tests for guest busy-times resolution behavior.
apps/api/v2/src/lib/services/guest-busy-times.service.ts Nest wrapper around the base guest busy-times service using PrismaWriteService.
apps/api/v2/src/lib/services/available-slots.service.ts Plumbs GuestBusyTimesService into the API v2 available-slots service wiring.
apps/api/v2/src/lib/modules/available-slots.module.ts Registers the new GuestBusyTimesService provider in the API v2 module.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Check bookings against all verified emails (primary + secondaries)
- Sanitize error logging to avoid PII leakage
- Update tests to handle additional email lookups

Fixes:
1. Guest busy-time now checks attendee bookings made under any verified email
2. Error objects no longer logged raw (only name and message)
3. All unit tests updated to match new behavior
Copy link
Copy Markdown
Author

@Harry-jain Harry-jain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please let me know of any required changes

Harry-jain and others added 2 commits April 3, 2026 19:39
- Make guestBusyTimesService optional in IAvailableSlotsService to avoid breaking existing instantiations
- Update comment to accurately reflect that filtering runs for any rescheduleUid
- Optimize slot filtering performance by pre-normalizing busy times to milliseconds
- Remove unused dayjs import from getGuestBusyTimes.ts
- Remove unused Mock type import from test file
- Fix TypeScript iterator issue with Map.values() by using Array.from()
Copy link
Copy Markdown
Author

@Harry-jain Harry-jain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please let me know of any discrepency

Copy link
Copy Markdown
Member

@romitg2 romitg2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, but we'll require video demo. going with other open prs on this issue.

@romitg2 romitg2 closed this Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants