> ## Documentation Index
> Fetch the complete documentation index at: https://klipy.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# How does Klipy's booking scheduler work under the hood?

> How Klipy computes open slots, claims and confirms a booking, plans reminders, and syncs cancellations and reschedules to your calendar.

This page explains the mechanism behind a Klipy booking link. It covers how open slots are computed, how a claimed slot becomes a calendar event, and what runs on approval, reminder, cancel, and reschedule.

## Computing availability

A slot grid comes from three inputs: the host's weekly schedule, the link's own booking rules, and the busy intervals that should block a slot. Rules cover duration, buffers, notice, and the booking horizon. The pure engine that combines them, `computeSlots`, walks each calendar day the query window touches, in the schedule's own timezone. For each day it resolves the open hours — the weekly grid, or a date override. It then steps candidate starts every `slotIntervalMinutes` and keeps the ones that clear both the open hours and the padded busy time (`convex/domains/availability/domain/computeSlots.lib.ts:226-360`). Date overrides — a blocked day, or custom hours for one date — are resolved by `resolveScheduleToOpenHours` before the engine ever sees them (`convex/domains/availabilitySchedules/domain/resolveScheduleToOpenHours.lib.ts:111-147`).

Buffers are applied by padding each busy block, rather than shrinking the candidate slot. A busy interval's leading edge grows by the new meeting's `bufferAfter`. Its trailing edge grows by `bufferBefore`. The padding direction is therefore the reverse of what the field names suggest (`computeSlots.lib.ts:288-298`). Minimum notice, booking horizon, and the per-day cap are resolved against product defaults at one single point, `linkToSlotRules`. An absent `minBookingNoticeMinutes` on a link means the 120-minute default, not zero (`convex/domains/availability/domain/publicMonth.lib.ts:213-233`). The default horizon is 28 days.

Calendar busy time comes from a per-user, per-UTC-day cache called `freeBusyCache`. It refreshes by fanning a Nylas free/busy call out over the host's own non-shared grants and merging the results (`convex/domains/availability/actions/refreshBusy.ts:33-53`). A cache row is fresh for 60 seconds. It is proactively renewed once it turns 30 seconds old, so the public booking page's poll cadence never outruns it (`convex/domains/availability/domain/freeBusyCache.model.lib.ts:57-92`). A grant that fails to report, or one that never connected, marks the row `degraded` rather than treating that calendar as empty (`refreshBusy.ts:120-125, 180-185`). The public page's first paint calls `getPublicMonthFresh`. It refreshes only when a touched bucket is missing or due for renewal, then reads through the same query the client polls (`convex/domains/availability/actions/getPublicMonthFresh.ts:19-42, 106-116`).

## Claiming a slot

Both the public "book this slot" mutation and the reschedule mutation route through one shared core, `claimSlotCore`. A claim is therefore validated and inserted exactly one way (`convex/domains/bookings/domain/claimSlot.core.lib.ts:1-19`). It validates the untrusted name and email before any read or write. It then resolves the link, organizer, and calendar grant, and replays an existing booking when the caller reuses an idempotency key (`claimSlot.core.lib.ts:114-240`).

The requested slot is then re-verified against live availability inside the same transaction. The host's active bookings across every link in the affected window, plus the cached busy intervals, are read and fed back through `computeSlots` (`claimSlot.core.lib.ts:242-424`). This read is the concurrency gate. Two simultaneous claims for the same slot both read the host's booking range, but only the first to commit succeeds. The second observes the now-taken slot and fails with `CONFLICT` (`claimSlot.core.lib.ts:322-334`, `mutations/claimSlot.ts:32-37`). The gate also fails closed. If any UTC-day bucket the slot's buffered footprint touches is missing or stale, the claim is rejected rather than confirmed over unverified coverage (`claimSlot.core.lib.ts:363-394`). Only after the slot clears every check does the core upsert a contact and insert a `pending` booking with a fresh `manageToken` (`claimSlot.core.lib.ts:426-483`).

From there the claim mutation branches on the link's `requireConfirmation` setting. A confirmation-required link leaves the booking `pending` and emails the host an approve/decline request. Every other link immediately schedules `confirmBooking` to create the calendar event (`convex/domains/bookings/mutations/claimSlot.ts:82-92`). This decision is captured once, on the booking row's `confirmationRequiredAtClaim` field, so a later change to the link's setting never alters an already-claimed booking.

## Confirming the slot

`confirmBooking` moves the booking `pending|failed → confirming`. It then calls Nylas `events.create` on the link's grant, listing the invitee, guests, and host as participants with `notify_participants` set (`convex/domains/bookings/actions/confirmBooking.ts:106-156, 1021-1061`). The calendar event's description is built from the booking's own details, plus separate reschedule and cancel manage links. The invite is therefore never a bare title (`confirmBooking.ts:259-284`).

Because Nylas exposes no idempotency key, the action first claims a PII-free, `bookingId`-scoped lock in the shared action-cache component. A concurrent or retried invocation that loses that claim skips `events.create` entirely (`confirmBooking.ts:44-51, 959-1019`). Once an `eventId` is durably attached to the booking, a later retry never re-creates the event. It re-fetches the existing one and resumes from there instead. A crash between creation and confirmation therefore cannot double-book the calendar (`confirmBooking.ts:891-951`). A calendar write failure retries with 2- and 10-second backoff, for up to two retries. The third failure marks the booking `failed`, releases the slot, and notifies the host. It also deletes any transferred event, so `failed` never orphans a live one (`confirmBooking.ts:36-38, 173-226, 296-312`).

If the booking is cancelled or declined while `events.create` is still in flight, the just-created event belongs to nobody. `confirmBooking` detects this on the next read and destroys the orphaned event, instead of attaching it (`confirmBooking.ts:1071-1093`).

Once the booking is durably `confirmed`, a best-effort tail runs step by step. Each step degrades independently, without re-running steps that already succeeded (`confirmBooking.ts:606-741`):

* A `BOOKING_CREATED` interaction.
* An opportunity capture keyed by `booking:{bookingId}`.
* A Recall notetaker bot, scheduled only when the link's `automaticallyInviteKlipy` is on (see [Meeting notetaker](https://klipy.ai/docs/product/meetings/overview.md)).
* Confirmation emails to both sides.
* Reminder planning.
* The `booking.created` event.
* A PostHog track.

## The confirmation-required approval path

> [!WARNING]
>
> Klipy never adds a confirmation-required booking to the host's calendar until the host approves it. The invitee's claim only holds the slot as a `pending` row.

Approving a pending booking transitions it `pending → confirming`, records who decided and when, and schedules `confirmBooking` (`convex/domains/bookings/mutations/approve.ts:101-125`). Declining transitions it straight to the terminal `declined` status. If the booking carries a transferred calendar event, from a rescheduled confirmation-required booking re-entering approval, decline also deletes it so nothing is orphaned (`convex/domains/bookings/mutations/decline.ts:98-124`). A decline is emitted onto the bus as `booking.cancelled` — there is no separate `booking.declined` lifecycle event.

A host can also decide from the pending-approval email without opening Klipy. That link carries an HMAC-SHA-256-signed token: `bookingId`, action, and an expiry capped at the booking's own start time. It is verified with a constant-time comparison (`convex/domains/bookings/_shared/approvalLink.lib.ts:111-188`). The action that verifies it re-dispatches through the exact same authenticated `approve`/`decline` mutations a host uses in-app. The token only proves which decision was requested. It can never bypass the ownership check those mutations already enforce against the clicking, signed-in user (`convex/domains/bookings/actions/applySignedDecision.ts:16-30`).

Rescheduling a confirmation-required booking defers the calendar handoff: the original row and its live event stay untouched while the replacement waits as `pending`. Only once the replacement is both approved and its calendar update succeeds does `finalizeDeferredReschedule` run. That one transaction cancels the source, clears its `eventId`, and transitions the replacement to `confirmed` with the same event id (`convex/domains/bookings/mutations/rescheduleBooking.ts:93-163`). An instant (non-confirmation) reschedule instead transfers the event and cancels the source synchronously, inside the reschedule mutation itself, before the calendar is even updated (`rescheduleBooking.ts:322-355`).

## Reminders and calendar drift

Every host-configured attendee-reminder offset becomes its own scheduled job. `planAttendeeReminders` drops invalid or already-past offsets, de-duplicates repeats, and sorts what remains earliest-first (`convex/domains/bookings/_shared/attendeeReminderPolicy.lib.ts:87-119`). A host reminder, when enabled, reuses the earliest attendee offset, or falls back to a 30-minute default when none are configured (`convex/domains/bookings/_shared/reminders.lib.ts:31-61`). Scheduling the jobs and recording them both happen inside one mutation. A reschedule or a settings edit therefore replaces the prior set atomically, instead of appending duplicate jobs (`reminders.lib.ts:26-29`).

When a host edits the calendar event's time directly in Google or Outlook, the resulting `event.updated` webhook reaches `reconcileBookingsWithCalendarEventTimes`. It patches the booking's `startTime`/`endTime` and schedules `replanRemindersAndNotify` (`convex/domains/bookings/primitives/reconcileBookingsWithCalendarEventTimes.ts:146-167`). That action re-plans every reminder against the new time, emits `booking.rescheduled`, and sends the "rescheduled" email to both sides (`convex/domains/bookings/actions/replanRemindersAndNotify.ts:34-83`). This is the only path that sends that email as `by: "host"`, since an in-app reschedule already carries its own status-aware notification. A legacy `booked`-era booking (pre-dating the native lifecycle) instead keeps a single reminder job at a fixed 30 minutes before start, rescheduled the same way.

## Cancelling and rescheduling

Both mutations are reachable two ways: by the host from an authenticated session, or by the invitee holding the booking's `manageToken`. Each resolves which one is acting before doing anything else. An authenticated session that owns the booking is always the host, regardless of any token also supplied. Otherwise, a byte-exact token match identifies the invitee (`convex/domains/bookings/_shared/bookingActor.lib.ts:39-71`). The host bypasses every link policy. The invitee is bound by `allowCancel`/`allowReschedule` and the link's minimum-notice window — enforced server-side, regardless of what the client sends (`convex/domains/bookings/domain/policy.lib.ts:86-180`).

Cancelling transitions the booking to `cancelled`, tears down its reminder jobs, and — only if a calendar event exists — schedules a delete against it (`convex/domains/bookings/mutations/cancelBooking.ts:105-131`). Rescheduling claims the **new** slot first, through the same `claimSlotCore` used by a fresh claim, excluding the original booking from its own conflict check. If the new slot is already taken, this fails before the original booking is touched at all (`convex/domains/bookings/mutations/rescheduleBooking.ts:261-284`). The replacement row gets its own fresh `manageToken` — the invitee's old manage link no longer authorizes it (`rescheduleBooking.ts:296-309`).

The actual Nylas write for a cancel or a reschedule is best-effort and self-contained. `syncCalendarEvent` retries once; a failure past that is reported at `degraded` impact, then left alone rather than retried indefinitely. A delete that stays degraded after its retry can leave the calendar event orphaned, since there is no durable retry queue behind it yet (`convex/domains/bookings/actions/syncCalendarEvent.ts:22, 176-183`).

## Expiring unanswered requests

An hourly cron sweeps every `pending` booking whose start time has already passed into `expired`, in batches of up to 100 rows per run (`convex/domains/bookings/actions/expirePendingBookings.ts:12-36`). This catches a booking whose host never approved or declined it in time. A row that raced out of `pending` between the read and the transition — a concurrent approval, for instance — is skipped. It never aborts the rest of the batch. An expiring booking that carries a transferred calendar event has that event deleted, the same as a cancel or a decline.

## Booking lifecycle events and webhook payloads

Four events reach Klipy's internal event bus: `booking.created`, `booking.pending`, `booking.cancelled`, and `booking.rescheduled`. Each is scheduled fire-and-forget with a PII-safe payload of ids, status, and times (`convex/domains/bookings/_shared/bookingEvents.lib.ts:60-106`). Only three of those map to an external Svix subscriber event: `booking.created`, `booking.rescheduled`, and `booking.cancelled`. `booking.pending` has no external mapping and never leaves the internal bus (`convex/components/svix/domain/svixEvent.model.ts:13-15`, `convex/infrastructure/webhooks/svix/eventTypeMapping.ts:1-15`).

Each external event is normally enriched with the booking's title, times, organizer, attendee, and guests before it reaches a subscriber (`convex/infrastructure/webhooks/svix/enrichers/bookingCreated.ts:36-49`). That enrichment looks the booking up by its `externalId` field (`primitives/get.ts:16-24`) — a deprecated field from the retired Nylas Scheduler integration. A native booking created through `claimSlotCore` never sets `externalId` on its row at all (`primitives/create.ts`). The bus payload's `externalId: booking._id` (`bookingEvents.lib.ts:86`) is a value passed to the enricher — not something written back to that row. The lookup therefore finds nothing. Every external `booking.*` webhook today falls back to the minimal payload, `{ id: bookingId }`, instead of the enriched shape the enricher was built to return.

## Limits worth knowing

| Behavior | Limit |
| - | - |
| Meeting duration | 15–480 minutes |
| Before/after buffer | 0–1,440 minutes (24h) each side |
| Booking horizon | Default 28 days; configurable 1–365 |
| Minimum booking notice | Default 120 minutes |
| Attendee reminders per link | Up to 10 offsets, each up to 365 days before start |
| Free/busy cache freshness | Fresh for 60 seconds; renewed proactively at 30 seconds old |
| Calendar create/update retries | 2s then 10s backoff; 2 retries before the booking is marked `failed` |
| Calendar sync retries (cancel/reschedule) | 1 retry, then reported and left as-is |
| Pending-booking expiry sweep | Hourly, up to 100 bookings per run |
| Legacy (`booked`-era) reminder lead time | Fixed 30 minutes before start |
| Manage-token entropy | 256 random bits, base64url-encoded |

## What Klipy stores and sends

Availability reads the host's own weekly schedule and date overrides. It also reads free/busy data from the host's own non-shared Nylas grants, fetched in windows of up to 35 days (`convex/domains/availability/actions/refreshBusy.ts:16`). A claim writes the booker's name, email, notes, and any custom-field answers to a contact record and the booking row. The calendar event created from it lists the invitee, guests, and host as participants on the host's primary calendar. The invitee's manage token and the host's signed approval-link token are both generated fresh per booking and never reused across bookings. External `booking.*` webhooks currently carry only the booking id, per the payload gap described above, until a subscriber resolves the rest through the API.

## Related guides

> [card] [Bookings overview](https://klipy.ai/docs/product/bookings/overview.md)
>
> What booking links do and what the pre-meeting brief shows.

> [card] [How do I create and manage a booking link?](https://klipy.ai/docs/product/bookings/how-to.md)
>
> Creating a link, setting its hours, and approving or rescheduling bookings.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.