Repository navigation
[MBA-3829] Waitlist auto-offer: offer a freed seat to the next waitlisted candidate - #99
Merged
devin-ai-integration[bot] merged 4 commits intoNov 11, 2026
Conversation
…sted candidate WaitlistOfferPolicy offers seats freed by cancel, reschedule-out, capacity increase, decline, expiry and withdrawal to the lowest-position eligible waitlist entry (ET25/ET50 skipped while no accommodation seat is free). Pending offers hold the seat. Accept/decline endpoints under /api/v2/offers, expiry job, seat_offer table (V3), SeatOffered/Accepted/Declined/Expired/Withdrawn outbox events, UI in My bookings and the admin waitlist. ADR 0004. Co-Authored-By: Mason <masonbatchelor81@gmail.com>
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
…session -> centre) Co-Authored-By: Mason <masonbatchelor81@gmail.com>
…in/mba-3829-waitlist-auto-offer-v2
… 0004) Co-Authored-By: Mason <masonbatchelor81@gmail.com>
devin-ai-integration
Bot
merged commit Nov 11, 2026
8cc35d8
into
estate/legacy-baseline
6 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements MBA-3829: a seat freed in an
OPENsession is offered automatically to the next eligible waitlisted candidate. This is a deliberate change from legacy, whereusp_CancelBookingpromotes nobody (HB-06, MR-12, ADR 0002 ODD-09). The new behaviour is recorded in ADR 0005 (docs/adr/0005-waitlist-auto-offer.md; renumbered because M5 #97 took 0004). Scheduling-service has been the single writer since M4, so legacy readers get the result through the existing outbox relay. There is also a minimal routing-gateway change so the new offer write paths go through the existing modern write guard (see below).SessionCapacityhas newheldSeats/accommodationHeldfields (pending offers).seatsAvailable = capacity - occupied - held, so a held seat cannot be booked (new bookings are waitlisted) andseatsAvailablestays 0. The hold exists only in Scheduling. In legacy the offered booking staysWAITLISTEDandSeatsAvailablestaysCapacity - (BOOKED+ATTENDED)(the formuladb/checks/seat-drift.sqlchecks), so reconciliation remains at 0 throughout an offer cycle. The relay needed no code change because every event carries the full resulting state.uq_seat_offer_pending_booking (booking_id) WHERE status='PENDING'plus the existing session lock. Concurrent ITs cover cancel+cancel and cancel+capacity-increase.V3__waitlist_offers.sql:seat_offertable, plusck_outbox_event_typeextended withSeatOffered,SeatOfferAccepted,SeatOfferDeclined,SeatOfferExpiredandSeatOfferWithdrawn.GET /api/v2/offers/{offerId},POST .../acceptandPOST .../decline(tagOffers, 404/409 as a separateOfferErrorschema so the publishedApiErrorenum does not change). Additive fields:SessionDto.heldSeats, plus nullableofferId,offerStatusandofferExpiresAtonBookingDtoandWaitlistEntryDto.services/routing-gateway, write-guard code only):ApiRoutes.matchV2Writenow matchesPOST /api/v2/offers/{id}/accept|declineasV2Op.OFFER.ModernApiWriteGuardresolves offer -> session -> centre via the newLookup.Kind.OFFER_ID, which callsGET /api/v2/internal/routing/resolve?offerId=(new parameter in scheduling-serviceInternalController). It refuses with403 CENTER_NOT_MODERNwhen that centre is not onrouting.modern-centersor the lookup fails (fail closed), the same as cancel/reschedule.scheduling.waitlist.offer-ttl(PT24H),expiry-enabled(true,falsein tests) andexpiry-poll(PT1M). The runbook has a new "Waitlist offers" scenario.Review focus
SchedulingService.cancel/reschedule/changeCapacityhooks andcloseOffer: each one emits the original event and then the offer event in the same transaction./api/v2candidate writes (cancel, reschedule). This is by design for now: the slice has no candidate login (MR-16), see ADR 0005 Consequences.Tests
The re-run results are on head
6bf1778, which includes the merge ofestate/legacy-baseline@192a423(M5 #97); that merge was clean. The original offer work was verified on6562610.services/scheduling-service)./mvnw -B verify -Dskip.frontend=true -Dtest=NONE -Dsurefire.failIfNoSpecifiedTests=false -Dit.test=OpenApiSpecIT,WaitlistOfferIT -Dopenapi.write=true(spec regen; the SPA is skipped because its contract check needs the new spec first)api/openapi.yamlregenerated, baseline untouched./mvnw -B verify(clean run with the SPA build and contract typecheck), on6bf1778services/routing-gateway:./mvnw -B verify, on the merged headGatewayIntegrationTest.offerAcceptAndDeclineAreGuardedByTheOffersCentre: allowed centre 200, refused centre 403, unresolvable offer 403; plus theRouteDeciderTestoffer matcher)New tests:
WaitlistOfferRulesTest(8): position order, held seats, ET skip (used and held accommodation seat), onlyOPENsessions, held seats reduce availability.WaitlistOfferIT(15, Testcontainers SQL Server): cancel creates a PENDING offer with 24h TTL and holds the seat (new booking gets WAITLISTED,seatsAvailable0,heldSeats1); accept gives BOOKED, positions 2-3 become 1-2,SeatOfferAcceptedpayload includes the shifted bookings, second accept gets 409OFFER_NOT_PENDING, unknown id gets 404OFFER_NOT_FOUND; decline offers to the next entry; expiry offers to the next entry and the last expiry releases the seat for ordinary booking; ET25/ET50 skipped and kept in place; capacity increase makes 2 offers in order and a decrease withdraws the newest; reschedule-out; cancelling an offered booking passes the seat on; CLOSED session makes no offer; concurrent cancel+cancel and cancel+capacity-up (each repeated 3x) give exactly 2 offers and no duplicates.RelayIT#waitlistOfferCycleReachesLegacyAndReconcilesToZero(realAssessmentDelivery, relay asad_sched_relay): offer, accept, decline, expire. After each step legacydbo.Booking/dbo.Waitlistmatch, reconcile reports 0 mismatches, seat-drift returns 0 rows, and every event replayed twice is a no-op.SchedulingApiITupdated for the intended change: Flyway history is 3, and raising capacity now offers seats to the waitlist instead of promoting nobody (ODD-09).Live gateway check through :8000 (merged head
6bf1778, live estate + relay)Allowed centre (
routing.modern-centers=*). Cancelling a booking in full DEN01 session 156 creates offer 4:Refused centre. Cancelling a booking in AKL01 session 325 creates offer 5; then
routing.modern-centersis temporarily narrowed toBOS01:After restoring
routing.modern-centers=*,POST /api/v2/offers/5/acceptreturns 200 ACCEPTED. M5's redirect still works:GET :8000/Booking/MyBookingsreturns 302 to/app/my-bookings. Reconciliation afterwards: 462 sessions and 3,587 bookings compared, 0 session mismatches, 0 booking mismatches, 0 seat-drift rows.Browser verification (testing agent, live estate)
Setup:
scripts/run-legacy.shandscripts/run-scheduling-service.sh(relay on), seed session 153 (full, waitlist 1-3), UI at:8090/app.heldSeatsis 1.dbo.Booking#1603 is BOOKED and has nodbo.Waitlistrow.GET /internal/reconciliation: 462 sessions and 3,587 bookings compared, 0 session mismatches, 0 booking mismatches, 0 seat drift.Admin offer column:


Decline hands the seat on:
Reconciliation:
Recording (animated):

Not covered in the browser (covered by ITs instead): reschedule-out, expiry, ET skip, concurrency.
Devin Review
hasSeatForis checked before full. A held accommodation seat counts as used, the same as a BOOKED ET25.Devin-Org: engineering
Link to Devin session: https://devin-gtm.devinenterprise.com/sessions/1887a2fe45044035a28ca9ce9e836c7d
Open in Devin Desktop: https://devin-gtm.devinenterprise.com/desktop/session/1887a2fe45044035a28ca9ce9e836c7d?variant=devin
Requested by: @mbatchelor81
Note
Devin errored when opening this Pull Request as mbatchelor81.
As a fallback, Devin opened this PR as itself.
🟢 Devin Review found nothing to fix · View findings · Follow Devin's work