Introducing a new way to review your PRs.

Read the announcement

calicastle / cali.so

Personal website for Cali Castle

View on GitHub

21 documents · Updated Sep 21, 2026

docs / ama-booking-lifecycle

AMA booking lifecycle

The AMA booking lifecycle takes a guest from a public time choice to a paid 60-minute AMA Session with Cali. It protects each time with a short Slot Hold, turns verified payment into a Booking, creates meeting details, and gives the guest private control through a Manage Link. See the AMA booking platform overview, AMA availability, and AMA external integrations for the systems around this flow.

Booking journey

The journey has two separate outcomes. A guest can complete a paid Booking, or can send an unpaid Alternate Time Request when no listed time works. The public pages keep these paths clear so a request for help never looks like a reservation.

flowchart TD
    A[Public booking page] --> B[View available times]
    B --> C[Enter guest details and Booking Brief]
    C --> D[Create 15-minute Slot Hold]
    D --> E{Payment completed}
    E -->|Yes| F[Verified payment creates Booking claim]
    F --> G[Confirmation checks Booking state]
    G --> H[Finalizing Booking]
    H --> I[Confirmed Booking and Manage Link]
    E -->|No| J[Hold expires and time is released]
    B --> K[Send Alternate Time Request]
    K --> L[Owner reviews request]

Public booking

The public booking page at app/…/ama-book-page.tsx presents the offer and starts the transactional flow. It shows available times through the public slots service, then collects the guest name, email, topics, guest time zone, meeting choice, and Booking Brief before it asks the system to protect the selected time.

The Booking Brief is the guest's short explanation of what would make the AMA Session valuable. The form keeps this work while it recovers from a stale time, a failed request, or an expired hold, so the guest can choose again without losing context.

References: app/…/ama-book-page.tsx• L25-49 components/…/booking-flow.tsx• L353-417 components/…/booking-flow.tsx• L840-1100 app/…/route.ts• L1-7

Time selection

The public slot list is a current view of availability, not a promise that a time is still free. It reflects the availability rules, calendar conflicts, active Slot Holds, Bookings, notice limits, and time buffers described in AMA availability.

The guest's display time zone affects how the chosen instant is shown. The Schedule Time Zone remains an owner setting used to build the available schedule. This separation lets guests choose with local times without changing the schedule itself.

References: lib/…/service.ts• L177-193 components/…/booking-flow.tsx• L678-683 db/schema.ts• L89-158

Slot holds

A Slot Hold is a 15-minute temporary claim on one available AMA Session start time. It bridges the gap between a guest's form submission and payment, while the claim store prevents another guest from taking the same effective time.

Hold creation

When the guest submits the form, the service checks the intake and checks that the selected time is still in the current public slot list. It then creates the Slot Hold and stores the Booking intent that carries the guest's details and Booking Brief toward payment.

The hold covers the session and its policy buffer. The data store allows only one active claim for an overlapping buffered interval, so two guests racing to submit cannot both receive a valid hold. A stale selection and a race for the same time have different recovery paths, but both return the guest to time selection without discarding the form.

References: components/…/booking-flow.tsx• L508-614 lib/…/service.ts• L230-270 lib/…/claims.ts• L108-146 db/…/0011_ama_booking_system.sql• L138-157

Hold expiry

The browser countdown is only a display of server time. It checks the hold state again when the countdown reaches zero, when the page becomes visible, and when the network returns. This avoids treating a delayed browser clock as proof that the time is free.

An unpaid hold is released when it expires or when its payment session is abandoned. The guest is not charged and can choose another time. A payment that is still settling keeps the confirmation path in a processing state instead of showing an incorrect expiry.

References: components/…/booking-flow.tsx• L430-506 lib/…/service.ts• L272-324 lib/…/claims.ts• L191-230 lib/…/service.ts• L419-427

Payment and booking claims

Payment takes place on a Stripe-hosted page for the AMA Session price. The return page helps the guest see progress, but the signed Stripe webhook is the source of truth that creates a Booking.

Checkout

The guest can start checkout only while the Slot Hold is active. The system creates or reuses one Checkout Session for that hold, then sends the guest to Stripe. A checkout session can outlive the 15-minute Slot Hold, which allows a late payment to reach the recovery rules rather than failing silently.

The confirmation and cancel return paths do not decide whether payment succeeded. They only bring the guest back to a page that reads the hold or Booking state from the server.

References: components/…/booking-flow.tsx• L616-646 lib/…/service.ts• L326-385 app/…/route.ts• L1-14

Payment verification

The Stripe webhook accepts verified paid events and records each provider event before it applies changes. It converts an active Slot Hold into a Booking claim, then creates one Booking from the payment session and records the payment event.

If the hold has expired, the webhook tries to claim the same time again. If another active claim now blocks it, the paid Booking enters needs_reschedule. This state preserves the payment and tells the guest to use the Manage Link to select a new time at no extra charge.

Duplicate or out-of-order webhook delivery does not create a second Booking. Provider event records, the unique payment-session relationship, and the claim conversion rules make the payment path safe to retry.

References: lib/…/service.ts• L387-554 app/…/route.ts• L10-23 lib/…/repository.ts• L214-264 lib/…/claims.ts• L149-170

Confirmation and finalization

The confirmation page reports the state that the server can prove. It polls while payment or meeting setup is in progress, then shows the session time, length, meeting choice, and meeting link when the link exists.

Confirmation states

The confirmation flow distinguishes a missing record, an active or settling payment, an expired hold, a cancelled Booking, a paid Booking that still needs rescheduling, and a completed confirmation. It never treats a browser return from Stripe as payment proof.

The normal paid path first shows a Finalizing Booking while meeting and calendar details are created. Once those details are ready, the page shows the meeting link and tells the guest that the confirmation email and Manage Link are on the way. A needs_reschedule Booking shows a paid conflict instead of presenting the old time as confirmed.

References: app/…/ama-confirmation-page.tsx• L35-52 components/…/booking-confirmation.tsx• L173-263 components/…/booking-confirmation.tsx• L288-443 lib/…/service.ts• L53-77

Meeting and message finalization

Finalization turns a paid Booking into a usable session. It creates the selected meeting and calendar artifacts, sends the guest the confirmation message, and schedules later reminders and removal of the private Booking Brief after its retention period.

These actions are durable work rather than one request that must finish before the guest sees payment success. If a provider or mail service is down, the Booking stays Finalizing Booking and appears for owner attention. A later worker run or an owner retry can complete the work without creating a second meeting or email task.

References: lib/…/service.ts• L196-225 lib/…/repository.ts• L12-27 lib/…/repository.ts• L49-90 lib/…/booking-calendar.ts• L115-162 docs/ama-booking-operations.md• L55-60

A Manage Link is a private capability link for one Booking. It lets the guest view the session, reschedule it, or cancel it without an account or sign-in flow.

Token access

The Manage Link is sent after payment and finalization work creates the guest message. The raw token is used as a capability in the URL, while the system stores only a hash for lookup. An unknown, revoked, or malformed token has one generic invalid result and does not reveal whether a Booking exists.

The manage page at app/…/ama-manage-page.tsx loads the Booking through the token and shows the current time, meeting choice, status, refund status, and meeting link when it is safe to show. The page is private and must not be indexed.

References: app/…/ama-manage-page.tsx• L10-43 components/…/manage-booking.tsx• L126-164 lib/…/manage-token.ts• L5-28 lib/…/repository.ts• L282-308 app/…/route.ts• L4-11

Guest changes

The guest can reschedule or cancel through the same private link. Online changes close 24 hours before the session, except for a paid needs_reschedule Booking whose original time was lost during payment. Rescheduling claims the new time before it releases the old claim and returns the Booking to Finalizing Booking so its artifacts and message can be updated.

Cancellation releases the Booking claim, stops work that no longer applies, and records who cancelled. A cancellation before the cutoff normally starts an automatic full refund. A cancellation inside the cutoff can still release the time, but it does not receive an automatic refund unless an owner grants an exception.

References: components/…/manage-booking.tsx• L409-583 lib/…/manage.ts• L45-125 lib/…/manage.ts• L146-239 lib/…/manage.ts• L241-334 app/…/route.ts• L10-27 app/…/route.ts• L10-27

Alternate time requests

An Alternate Time Request is an unpaid request for help when no public start time works. It does not create a Slot Hold, a Booking, or a charge.

Request submission

The public booking flow offers this path when times are unavailable, when the next 30 days have no open times, or when the guest expands the recovery option. The guest provides contact details, a time zone, preferred time windows, and an optional note.

After submission, the request is stored as new. A success message says that the owner will review the windows and reply by email. The request stays separate from the paid lifecycle until the owner chooses a time and starts a normal booking flow.

References: components/…/booking-flow.tsx• L153-239 components/…/booking-flow.tsx• L714-737 components/…/booking-flow.tsx• L871-899 app/…/route.ts• L5-10 lib/…/service.ts• L556-590

Request resolution

The owner reviews Alternate Time Requests as a separate work list. Each request ends as resolved or dismissed and records its resolution time. Resolving a request does not itself claim a time or create payment records.

References: lib/…/repository.ts• L103-114 lib/…/repository.ts• L716-765 lib/…/admin.ts• L67-69 lib/…/admin.ts• L195-204 db/…/0011_ama_booking_system.sql• L1-18

Administrative operations

The owner-facing AMA operations surface is the recovery and oversight path for Bookings that need human action. It exposes Booking search and detail history, upcoming and past views, attention items, Alternate Time Requests, and durable work that did not finish.

Booking actions

An owner can reschedule or cancel a Booking through the same shared lifecycle rules used by a guest. The owner can also grant a refund exception when the normal time rule no longer allows an automatic refund. Successful privileged actions are recorded in the security audit trail.

The owner view groups finalizing Bookings, needs_reschedule Bookings, and failed refunds as attention items. Booking detail joins the current record with its lifecycle events and durable operations, which gives the owner the context needed to retry or resolve work.

References: lib/…/admin.ts• L49-163 lib/…/repository.ts• L509-635 lib/…/manage.ts• L146-334 lib/…/booking-http.ts• L94-133

Durable work recovery

Durable operations track finalization, messages, reminders, refunds, artifact changes, and Booking Brief purge work. A worker leases due work and retries failed attempts with bounded backoff; an expired lease lets a later run take the work again. Terminal failures stay available for owner retry or manual resolution.

Each worker run uses a soft time budget and stops starting work when that budget is spent. Provider requests also have a short request timeout and share the current drain deadline, so a late provider call can stop the drain instead of running past the hosting limit. Work that was claimed but not started stays leased for a later run, while interrupted work is recorded for retry. An inline drain starts work soon after a mutation, but the scheduled sweep remains the driver for reminders, retry timing, and expired Slot Hold release.

The owner can retry terminal failed work or mark work resolved when it was completed outside the system. Retry and resolution update the Booking history, so the operational state and the human record remain linked.

References: lib/…/repository.ts• L92-155 lib/…/repository.ts• L184-239 lib/…/repository.ts• L271-318 lib/…/runner.ts• L48-140 lib/…/deadline.ts• L8-34 lib/…/server.ts• L38-42 lib/…/server.ts• L231-261 lib/…/admin.ts• L165-192 lib/…/booking-http.ts• L136-165

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to Booking, Slot Hold, or claim states must stay aligned across the service results, public hold-state response, confirmation states, Manage Link view, and owner attention filters.
  • Changes to hold or checkout lifetimes must update the late-payment path and the guest-facing expiry and payment messages together.
  • Changes to payment event handling must preserve provider-event dedupe, payment-session uniqueness, and the rule that the webhook—not the return page—creates a Booking.
  • Changes to reschedule or cancel rules must cover both guest Manage Links and owner actions because both use the shared claim, artifact, refund, and event flow.
  • Changes to finalization work must keep operation dedupe keys aligned with meeting artifacts, message delivery, reminders, refund work, and Booking Brief purge timing.
  • Changes to operation time budgets, provider request limits, or inline draining must preserve lease recovery and the scheduled sweep's ownership of reminders, retry backoff, and expired Slot Hold release.
  • Changes to Manage Link derivation or issuance must preserve raw-token privacy, stored-hash lookup, revocation behavior, and the email link contract.
  • Changes to Alternate Time Requests must keep the unpaid boundary separate from Slot Holds and Bookings, including owner resolution states.

Important failure modes

TriggerConsequenceGuard
A guest submits a time after it leaves the public slot listNo hold is created and the guest must choose againRecheck availability before creating the hold and return a stale-slot result
Two guests claim overlapping buffered timesOne request loses instead of creating two active claimsThe claim store rejects overlapping active buffered intervals
A hold expires before a paid event arrivesThe payment is reclaimed to the same time when possible, or the Booking enters needs_rescheduleThe webhook tries a fresh Booking claim and never marks a conflicting time as confirmed
Stripe sends the same event more than onceA duplicate Booking or duplicate side effect could resultPersist the provider event first and enforce one Booking per checkout session
Meeting or email work fails after paymentThe guest has paid but does not yet have complete session detailsKeep the Booking in Finalizing Booking and expose durable retry and manual resolution
A provider call runs past the current operations drain deadlineThe operation does not finish in that drain and may leave work for a later retryCombine per-request timeout with the shared drain signal and keep claimed-but-unstarted work leased for recovery
A guest changes a Booking while another change is in progressOne change can become stale and release the wrong claimCompare the expected start time and release a superseded claim
A guest cancels inside the 24-hour cutoffThe Booking is cancelled without an automatic refundCompute refund eligibility from the cutoff and allow an owner refund exception
A Manage Link is unknown or revokedThe page must not disclose Booking dataHash the presented token for lookup and return one generic not-found result

Key files

FileWhy to read it
app/…/ama-book-page.tsx and components/…/booking-flow.tsxShows the public entry point, intake, Slot Hold step, payment handoff, and Alternate Time Request recovery path.
lib/…/service.tsDefines the main transition from available time to Slot Hold, checkout, verified payment, Booking, and unpaid request.
lib/…/claims.tsExplains how temporary and paid claims protect overlapping session times.
app/…/route.ts and lib/…/service.tsShows why Stripe's signed webhook is authoritative and how late or repeated payment events recover safely.
components/…/booking-confirmation.tsxShows the guest-visible states between payment, finalization, confirmation, and conflict recovery.
lib/…/manage.ts and lib/…/manage-token.tsDefines private token access and the shared guest and owner reschedule, cancel, and refund rules.
components/…/manage-booking.tsxShows the guest's view of Booking status and the available Manage Link actions.
lib/…/admin.ts and lib/…/booking-http.tsShows owner actions, attention work, Alternate Time Request resolution, and durable-operation recovery.
lib/…/runner.ts and lib/…/deadline.tsShows how durable work uses leases, bounded retries, provider timeouts, and shared drain deadlines.
lib/…/server.tsShows how the booking services and providers are composed and how mutations start an inline durable-work drain.
db/…/0011_ama_booking_system.sqlShows the durable relationships between intents, claims, Bookings, lifecycle events, provider events, and operations.