Repository navigation
feat(mcp): owner/admin skip_availability on create_booking and reschedule_booking (#270) - #305
portfoliomanufaktur wants to merge 3 commits into
Conversation
…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.
There was a problem hiding this comment.
ℹ️ 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 —
mcpAvailabilityOverridederives the role fromMCPCallerMiddleware, refuses non-admins and the identity-less stdio transport before anything is loaded, and returns the id that doubles as the flag. - Create path —
validateBookingTimesplit into a waiver wrapper overcheckBookingTime;createBookingForSluggainsoverrideByplus anattemptclosure, and the round-robin retry books a rotation host outside hours only after the in-hours pool fails. - Reschedule path —
validateRescheduleTimethreads the flag through,Service.Reschedulerewrites/clears the column in the same UPDATE as the new times, and MCP gets a distincterrRescheduleOutsideAvailability. - Persistence — migration
00080adds a nullablebookings.availability_override_by;bookingColumns/scanBookingread 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
/mcpbearer-token test; README, ARCHITECTURE §4/§9/§19 and the changelog are updated. The full handler, booking and db suites pass locally, andgofmt/go vetare 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
filterAvailableHostson a min-notice or booking-window waiver can assign a rotation host who is outside their hours.overriddenis true for anyerrSlotUnavailable, includingcheckBookingTime's early notice/window returns, which happen before host hours are evaluated; theoverriddenbranch then hands the unfiltered pool topickRotationHost, 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 witherrSlotUnavailable" rationale only holds when the waived refusal was the hours rule. Running the filter even under the override and falling back tocandidateswhen 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
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.
|
Thanks, both findings are addressed in ffb58bf.
ARCHITECTURE §19, the changelog and the tool descriptions are updated. |
There was a problem hiding this comment.
✅ 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.
createBookingForSlugnow runsfilterAvailableHostsforround_robineven 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.
validateBookingTimenow returnserrStartInPastinstead of waiving a start that has already passed,reschedule_bookinganswers 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_byuntouched.
go test ./internal/booking/ ./internal/handler/, go vet ./internal/handler/ and gofmt -l are clean.
deepseek-v4.1-flash | 𝕏

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_bookingandreschedule_bookingaccept an optionalskip_availability. For an owner or admin it waives minimum notice,max_future_daysand the hosts' availability windows. Nothing else.booking.Service.Create/Rescheduleis not touched. A request with the flag that collides with an existing booking is refused.mcpAvailabilityOverride) reads the caller bound byMCPCallerMiddleware. 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.validateBookingTimewaives 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.createBookingForSlugthen 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.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.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.TestMCP_skipAvailability_createStillRefusesConflictTestMCP_skipAvailability_rescheduleStillRefusesConflictTestMCP_skipAvailability_memberRefused(create),TestMCP_skipAvailability_memberRefusedOnRescheduleTestMCP_skipAvailability_recordsActingUser(create),TestMCP_skipAvailability_rescheduleRecordsActingUserTestMCP_reschedule_unavailableTargetNeedsFlagTestMCP_reschedule_normalMoveClearsOverrideNotes on two of them:
create_bookingreports a conflict in the same words as an unavailable slot, so the test also assertsbooking.ErrDoubleBookedone layer down, checks that no row was created, and has a control (the same request on a free time outside availability succeeds).start_atand the column are unchanged after a refusal.Beyond the six:
TestMCP_skipAvailability_overHTTP_identityComesFromTheTokenand..._overHTTP_memberRefusedOnRescheduleserve/mcpthe 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.TestMCP_skipAvailability_waivesMinNoticeAndBookingWindowand..._rescheduleWaivesMinNoticeAndBookingWindowcover minimum notice andmax_future_days > 0, each on its own and inside the hosts' hours.TestMCP_skipAvailability_notRecordedForBookableSlotand..._rescheduleNotRecordedForBookableTarget.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...._roundRobinFallbackOnCalendarBusyis 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.TestMCP_skipAvailability_waivesOnlyTheAvailabilityRefusaland..._rescheduleWaivesOnlyTheAvailabilityRefusal: unknown, deactivated or paid event type, invalid address or time, a failing lookup inside the rules, a cancelled or unknown booking.TestMCP_skipAvailability_roundRobinKeepsHostFilterUnderWaivedNotice(a waived minimum notice still books the in-hours host; recorded because notice was waived),..._collectiveKeepsEveryHost,..._createRefusesStartInPastand..._rescheduleRefusesTargetInPast.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.validateBookingTimeandvalidateRescheduleTimetake 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 before00075–00079have landed, as you asked in the issue; this branch is cut frommainat00074. 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
createBookingForSlugkeepsfilterAvailableHostsfor 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.bookingJSONdoes not expose the column, because that struct also serves the public create response. Webhook payloads are unchanged.created_atdates an override only when the booking was created with it. An override applied by a reschedule is dated byupdated_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 addavailability_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 inREADME.mdare 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).
mcpCallerScopereturns"", truethere, so there is no user id to record. Default:skip_availabilityis 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?errStartInPast) and is not a waivable availability refusal. (Originally built literal, with no floor; changed in the third commit.)availability_override_bybe visible inget_booking/list_bookingsfor owners and admins? Default: no, it is only in the database for now.Not in this PR
REST (
#269step 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:
feat(mcp): skip_availability on create_booking for owners and admins (#270)with the migration and tests 1, 3 and 4.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.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.