Skip to content

feat(mcp): owner/admin skip_availability on create_booking and reschedule_booking (#270) - #305

Open
portfoliomanufaktur wants to merge 3 commits into
Calnode:mainfrom
portfoliomanufaktur:feat/270-mcp-skip-availability
Open

portfoliomanufaktur wants to merge 3 commits into
Calnode:mainfrom
portfoliomanufaktur:feat/270-mcp-skip-availability

Conversation

@portfoliomanufaktur

@portfoliomanufaktur portfoliomanufaktur commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Implements the MCP half of #270, measured against the acceptance criteria and the final six test cases in that issue. No REST, no public page, no admin UI.

What it does

  • create_booking and reschedule_booking accept an optional skip_availability. For an owner or admin it waives minimum notice, max_future_days and the hosts' availability windows. Nothing else.
  • The overlap check in booking.Service.Create / Reschedule is not touched. A request with the flag that collides with an existing booking is refused.
  • The gate (mcpAvailabilityOverride) reads the caller bound by MCPCallerMiddleware. No request field can grant it. It runs before anything is loaded; on reschedule that is before the member's "booking not found" check, so the refusal reads the same whether or not the booking exists. A member sending the flag gets an explicit tool error and nothing is written, also for a time they could have booked without it.
  • bookings.availability_override_by (nullable, user id) is written in the same INSERT as the booking, and in the same UPDATE as the new times on a reschedule. A reschedule under the override records whoever made that move.
  • The override is recorded only when it was needed. The rules are always evaluated; validateBookingTime waives a refusal under the flag and reports that it did. If an owner sends the flag for a time that is bookable anyway, the booking takes the ordinary path and the column stays NULL; on a reschedule it is cleared, like on any normal move. So the column never claims an override for a booking that sits in a regular slot. The gate itself does not depend on this: a member sending the flag is refused whatever the time. Only the availability refusal is waived; any other error is returned as it is.
  • Round robin is the one case decided after the rules. There the slot "exists" as soon as one rotation host is within hours, so the rules can pass while that host is already taken. Under the flag, and only when the host filter actually removed someone, createBookingForSlug then retries once with exactly the hosts the filter removed, through the same calendar busy and overlap checks. That pool holds nobody within their hours, so the booking lands on a rotation host outside their hours by construction and is recorded as an override: a set column always means a host outside their availability, or a time that failed notice or the booking window. Without the flag the refusal stands as before. Reschedule has no such case: it selects no host, every assigned host keeps their seat.
  • A reschedule without the override clears the column. This lives in Service.Reschedule, so it also holds for the admin REST endpoint and for the guest's manage link, neither of which accepts the flag. The manage link has its own handler test (TestRescheduleByToken_clearsAvailabilityOverride): the link holder moves an override booking into a regular slot and the column is NULL afterwards, and the same link cannot move it to another time outside availability.
  • Rescheduling to a target that fails availability without the flag returns a message that names the reason and the flag, instead of the wording used for a taken slot. Only the MCP wording changed; the two branches were already separate. REST and the manage page keep their messages.

The six tests

All in internal/handler/mcp_skip_availability_test.go. They call the tool handlers with a bound caller (the in-memory transport binds none, which is the stdio case) and read the stored column, not just the tool's answer.

# Case from the issue Test
1 Create, conflict refusal TestMCP_skipAvailability_createStillRefusesConflict
2 Reschedule, conflict refusal TestMCP_skipAvailability_rescheduleStillRefusesConflict
3 Unauthorised refusal TestMCP_skipAvailability_memberRefused (create), TestMCP_skipAvailability_memberRefusedOnReschedule
4 Authorised success is recorded TestMCP_skipAvailability_recordsActingUser (create), TestMCP_skipAvailability_rescheduleRecordsActingUser
5 Reschedule to an unavailable target without the flag TestMCP_reschedule_unavailableTargetNeedsFlag
6 Normal reschedule clears it TestMCP_reschedule_normalMoveClearsOverride

Notes on two of them:

  • Test 1: create_booking reports a conflict in the same words as an unavailable slot, so the test also asserts booking.ErrDoubleBooked one layer down, checks that no row was created, and has a control (the same request on a free time outside availability succeeds).
  • Tests 2 and 5 assert that the conflict refusal and the availability refusal are different messages, and that start_at and the column are unchanged after a refusal.

Beyond the six:

  • Identity through the real stack. TestMCP_skipAvailability_overHTTP_identityComesFromTheToken and ..._overHTTP_memberRefusedOnReschedule serve /mcp the way the server mounts it (RequireBearerToken → MCPCallerMiddleware → streamable handler) and call it with real API keys. A member's key with the flag is refused explicitly and books nothing, also when the arguments try to claim a role; the owner's key with the same arguments books and is recorded.
  • The other two rules. TestMCP_skipAvailability_waivesMinNoticeAndBookingWindow and ..._rescheduleWaivesMinNoticeAndBookingWindow cover minimum notice and max_future_days > 0, each on its own and inside the hosts' hours.
  • Only when needed. TestMCP_skipAvailability_notRecordedForBookableSlot and ..._rescheduleNotRecordedForBookableTarget.
  • Round robin. TestMCP_skipAvailability_roundRobinFallsBackToHostOutsideHours: in-hours host taken and the other host outside their hours → booked on that host and recorded with the flag, refused without it; in-hours host free → booked on them, column NULL; every host taken → still refused. ..._roundRobinFallbackOnCalendarBusy is the same with a fake calendar provider as the trigger: the in-hours host's calendar is busy → the host outside their hours is booked and recorded; that host's calendar busy too → refused.
  • Nothing else is waived. TestMCP_skipAvailability_waivesOnlyTheAvailabilityRefusal and ..._rescheduleWaivesOnlyTheAvailabilityRefusal: unknown, deactivated or paid event type, invalid address or time, a failing lookup inside the rules, a cancelled or unknown booking.
  • Review findings (third commit). TestMCP_skipAvailability_roundRobinKeepsHostFilterUnderWaivedNotice (a waived minimum notice still books the in-hours host; recorded because notice was waived), ..._collectiveKeepsEveryHost, ..._createRefusesStartInPast and ..._rescheduleRefusesTargetInPast.
  • Manage link. TestRescheduleByToken_clearsAvailabilityOverride, as above.
  • TestMCP_skipAvailability_needsAnIdentity (stdio, see question 1), TestMCP_skipAvailability_overTheWire (in-memory transport: the flag is in the published schema of both tools), and two service tests (TestCreate_recordsAvailabilityOverride, TestReschedule_setsAndClearsAvailabilityOverride).

How the flag travels

The flag and the actor are one value (overrideBy, the acting user id, empty for none) from the tool handler down to the SQL, so an override cannot be applied without being recorded. validateBookingTime and validateRescheduleTime take the bypass as a parameter, as the spec asks, and return whether a refusal was actually waived; there is no second code path. The changed signatures (validateBookingTime, validateRescheduleTime, createBookingForSlug, Service.Reschedule) make every existing caller pass "no override" explicitly; a forgotten caller does not compile.

Migration

00080_booking_availability_override.sql: ALTER TABLE bookings ADD COLUMN availability_override_by TEXT (nullable, no default, no foreign key). Don't merge before 00075–00079 have landed, as you asked in the issue; this branch is cut from main at 00074. If the number moves, I'll rename the file in a follow-up commit.

No foreign key on purpose: removing a user neither is blocked by the record nor silently erases it.

Things worth a look

  • createBookingForSlug keeps filterAvailableHosts for round robin even when a refusal was waived (changed after the review, third commit): the waived rule may have been minimum notice or the booking window, which say nothing about hours, so the rotation still prefers a host within theirs. Only when the filter finds nobody within hours does the rotation pick among all candidates. Fixed and collective under a waiver skip the filter, because there every candidate has a seat and filtering would drop the out-of-hours host from the booking. The round-robin retry described above is unchanged and is the part of this PR I'd most like a second pair of eyes on. The external calendar busy check (calendarFreeHosts) still runs on create, on every attempt. Reschedule has never had one, with or without the flag, so nothing changes there.
  • bookingJSON does not expose the column, because that struct also serves the public create response. Webhook payloads are unchanged.
  • No timestamp column, as I wrote in the issue. created_at dates an override only when the booking was created with it. An override applied by a reschedule is dated by updated_at, and only until the next write to the row. I think that is acceptable for a column that means "where this booking currently sits", and it keeps this PR to one column. If you want it visible in Calnode itself, I'd add availability_override_at, meaning when the override was last used, not when the booking was created.
  • docs/ARCHITECTURE.md §19, §9 and §4, the [Unreleased] changelog and one sentence in README.md are updated.

Questions

Questions 1 and 3 are built to the default below and I'll change them if you prefer the other answer. Question 2 is decided (see there).

  1. stdio has no caller identity. mcpCallerScope returns "", true there, so there is no user id to record. Default: skip_availability is refused on stdio with an explicit message, because an override nobody is named for is the case the column exists to prevent. Alternative: attribute it to the workspace owner. Which do you want?
  2. A start in the past. Decided after the review: "not in the past" stays a hard limit even with the flag, on create and on reschedule. Such a start is refused with an explicit message (errStartInPast) and is not a waivable availability refusal. (Originally built literal, with no floor; changed in the third commit.)
  3. Reading the column. Should availability_override_by be visible in get_booking / list_bookings for owners and admins? Default: no, it is only in the database for now.

Not in this PR

REST (#269 step 2), created_by, any UI.

Checks run locally

gofmt -l . (empty), go vet ./..., go build ./... after a frontend build, go test ./... (all packages pass) on Go 1.26.11, run for each of the first two commits separately and again on the third, plus the new handler tests under -race. Not done: a manual pass against a running instance.

Commits

Two, create path then reschedule, as announced in the issue, plus a third for the two review findings:

  1. feat(mcp): skip_availability on create_booking for owners and admins (#270) with the migration and tests 1, 3 and 4.
  2. feat(mcp): skip_availability on reschedule_booking, clear the override on a normal move (#270) with tests 2, 5 and 6 and the reschedule halves of 3 and 4.
  3. fix(mcp): keep host-hours filter and the not-in-the-past floor under skip_availability (#270): round robin keeps the host filter under a waived notice or window, a start in the past is refused with the flag too, with tests for both (create and reschedule).

The first is not meant to ship alone: until the second, a normal reschedule does not clear the column.

…alnode#270)

An owner or admin can pass skip_availability to create_booking to book a time
the public calendar would not have offered. It waives minimum notice,
max_future_days and the hosts' availability windows, nothing else: the overlap
check in booking.Service.Create, the calendar busy check, intake answers and
the paid-event refusal still run.

The gate reads the caller bound by MCPCallerMiddleware, before anything is
loaded. A member sending the flag gets an explicit tool error and no booking;
so does the stdio transport, which has no user to record.

bookings.availability_override_by (migration 00080, nullable, no foreign key)
holds the acting user's id and is written in the same INSERT as the booking.
The flag and the actor travel as one value from the tool handler to the SQL,
so the rules cannot be waived without the id being stored.
validateBookingTime takes the bypass as a parameter, still evaluates the
rules, and reports whether a refusal was waived: for a time that is normally
bookable the flag changes nothing and the column stays NULL. REST and the
assistant pass "no override".

Round robin is the one case decided after the rules: they pass as soon as
one rotation host is within hours, even if that host is taken. Under the
flag the create then retries once with exactly the hosts the availability
filter removed, through the same calendar busy and overlap checks, and
records the override. That pool holds nobody within their hours, so a
recorded override always means a host outside their availability.

Not meant to ship alone: a normal reschedule does not clear the column until
the next commit.
…e on a normal move (Calnode#270)

reschedule_booking accepts skip_availability under the same gate as
create_booking, checked before the booking is loaded. validateRescheduleTime
hands the bypass to validateBookingTime; the per-host overlap check in
booking.Service.Reschedule is untouched, so a target that collides with
another booking is refused with the flag as without it.

Service.Reschedule takes the acting user and writes
availability_override_by in the same UPDATE as the new times. An override
records whoever made that move; every ordinary move clears the column, so
it keeps meaning "where this booking currently sits". That holds for the
admin REST endpoint and the guest's manage link as well, which pass "no
override" and accept no flag. As on create, the override is recorded only
when it was needed: with the flag, a move into a normally bookable slot is
an ordinary move and clears the column too.

Without the flag, a target that fails minimum notice, the booking window
or the hosts' hours now gets its own refusal from the MCP tool, naming the
reason and skip_availability, instead of the wording used for a taken
slot. REST and the manage page keep their messages.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No blocking issues — two non-blocking findings below.

Approach: sound — the override is one actor id that both switches the checks off and is written to the booking, so it cannot be applied without being recorded, and the overlap check stays inside the transactional create.

Reviewed changes

  • MCP gate — mcpAvailabilityOverride derives the role from MCPCallerMiddleware, refuses non-admins and the identity-less stdio transport before anything is loaded, and returns the id that doubles as the flag.
  • Create path — validateBookingTime split into a waiver wrapper over checkBookingTime; createBookingForSlug gains overrideBy plus an attempt closure, and the round-robin retry books a rotation host outside hours only after the in-hours pool fails.
  • Reschedule path — validateRescheduleTime threads the flag through, Service.Reschedule rewrites/clears the column in the same UPDATE as the new times, and MCP gets a distinct errRescheduleOutsideAvailability.
  • Persistence — migration 00080 adds a nullable bookings.availability_override_by; bookingColumns/scanBooking read it; REST, manage link and assistant all pass "no override".
  • Tests/docs — the six spec cases plus round-robin, min-notice/window, manage-link clearing and a real /mcp bearer-token test; README, ARCHITECTURE §4/§9/§19 and the changelog are updated. The full handler, booking and db suites pass locally, and gofmt/go vet are clean.

On the PR's three questions: refusing skip_availability on stdio (Q1) is the right call — attributing it to the workspace owner would fabricate the audit record the column exists to prevent; keeping the column out of get_booking/list_bookings (Q3) is fine for this slice. Q2 is the second item below. Merge also remains gated on 00075–00079 landing first, as the issue says; nothing in CI can catch an out-of-order merge of 00080.

Non-blocking

  • Skipping filterAvailableHosts on a min-notice or booking-window waiver can assign a rotation host who is outside their hours. overridden is true for any errSlotUnavailable, including checkBookingTime's early notice/window returns, which happen before host hours are evaluated; the overridden branch then hands the unfiltered pool to pickRotationHost, so a round-robin booking can land on an out-of-hours host while an in-hours host was available and free. The "it would end every override booking with errSlotUnavailable" rationale only holds when the waived refusal was the hours rule. Running the filter even under the override and falling back to candidates when it reports nobody in hours would keep the assignment right; a round-robin min-notice test would pin it. booking_handler.go#L676-L690
  • A start in the past is bookable under the flag (Q2). Waiving minimum notice also waives the startAt.Before(now) floor, so an owner can create a booking whose start has already passed, with a calendar event and a confirmation email for a time that is gone. That is the right behaviour if logging completed appointments is the point; otherwise the not-in-the-past floor should stay outside the waived block. booking_handler.go#L347-L356

Pullfrog  | Fix it ➔ | View workflow run | Using deepseek-v4.1-flash | 𝕏

…skip_availability (Calnode#270)

Two findings from the review of Calnode#305.

Round robin: createBookingForSlug skipped filterAvailableHosts whenever a
refusal was waived, including a waived minimum notice or booking window,
which say nothing about hours. The rotation could then pick a host outside
their hours while one within theirs was free. The filter now also runs for
round robin under a waiver; only when it finds nobody within hours does the
rotation pick among all candidates. The retry with the hosts the filter
removed is unchanged. Fixed and collective under a waiver keep every
candidate, since filtering would drop the out-of-hours host from the booking.
The column is still set exactly when a refusal was waived or the retry
books a host outside their hours.

Past start: waiving minimum notice also waived the floor underneath it.
"Not in the past" is now a hard limit under the flag, on create and on
reschedule, refused with errStartInPast rather than as a waivable
availability refusal. Without the flag nothing changes for REST, the manage
link or create_booking; reschedule_booking names the past explicitly in
both cases, because "resend with skip_availability" would be wrong advice.
@portfoliomanufaktur

Copy link
Copy Markdown
Contributor Author

Thanks, both findings are addressed in ffb58bf.

  • Round robin: filterAvailableHosts now also runs when a refusal was waived, so a waived minimum notice or booking window can no longer put the booking on an out-of-hours host while an in-hours host is free. Only when nobody is within hours does the rotation pick among all candidates. Fixed and collective keep every candidate under a waiver, since filtering there would drop a host from the booking. A round-robin min-notice test pins it.
  • Past start (Q2): "not in the past" is now a hard floor under the flag, on create and reschedule, refused with an explicit message rather than as a waivable availability refusal. Tests for both.

ARCHITECTURE §19, the changelog and the tool descriptions are updated.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found — the two non-blocking findings from the prior review are addressed.

Reviewed changes — since 259031e (ffb58bf).

  • Round robin keeps the in-hours filter under a waived refusal. createBookingForSlug now runs filterAvailableHosts for round_robin even when a refusal was waived, keeps the removed hosts as the out-of-hours fallback pool, and falls back to every candidate only when the filter finds nobody within hours; fixed and collective under a waiver still keep all candidates so the out-of-hours host is booked, not dropped.
  • Not-in-the-past floor. validateBookingTime now returns errStartInPast instead of waiving a start that has already passed, reschedule_booking answers a past target with that same refusal with or without the flag, and the tool descriptions, README, architecture notes and changelog say so.
  • Tests. A priority rotation under a waived 48h notice still assigns the in-hours host and only falls back to (and records) the out-of-hours host once the in-hours one is taken; a collective override books both hosts; create and reschedule refuse past starts and leave the booking and its availability_override_by untouched.

go test ./internal/booking/ ./internal/handler/, go vet ./internal/handler/ and gofmt -l are clean.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash | 𝕏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant