Repository navigation
[MBA-3823] Coexistence without drift: single writer, legacy write denial, outbox relay, trigger neutralization, reconciliation - #96
Conversation
…ox relay, trigger neutralization, reconciliation Co-Authored-By: Mason <masonbatchelor81@gmail.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Co-Authored-By: Mason <masonbatchelor81@gmail.com>
…step before commit Co-Authored-By: Mason <masonbatchelor81@gmail.com>
…y writes Co-Authored-By: Mason <masonbatchelor81@gmail.com>
…r write a local AssessmentDelivery Co-Authored-By: Mason <masonbatchelor81@gmail.com>
…oking ids before stopping scheduling-service Co-Authored-By: Mason <masonbatchelor81@gmail.com>
|
UI/E2E test (testing agent, Windows VM): passed. Tested in the browser through the gateway
Not covered by the UI run (they are covered by ITs or the scripts in the description instead):
Pre-existing behaviour (M3): Note on an earlier failed run. That run showed 9 mismatches on sessions 154, 155, 163, 263 and 300. The cause was in the tests, not the runtime: the scheduling-service Spring ITs started with the relay on, and by default it pointed at |
…e it before returning to modern Co-Authored-By: Mason <masonbatchelor81@gmail.com>
scheduling-service checks X-Service-Token in constant time against scheduling.attendance.service-token (fail closed when unset, 401 with the usual error body, no outbox event). results-service sends scheduling.service-token; run scripts set the same dev value. The gateway answers 404 for /api/v2/bookings/*/attendance. OpenAPI: serviceToken security scheme and a separate ServiceTokenError 401 schema so ApiError stays compatible with the published baseline. Co-Authored-By: Mason <masonbatchelor81@gmail.com>
Co-Authored-By: Mason <masonbatchelor81@gmail.com>
b88cdaf
into
estate/legacy-baseline
Summary
MBA-3823 (M4): scheduling-service becomes the only writer of bookings and seat counts. Every modern mutation writes an
outbox_eventrow in the same transaction, and an idempotent relay (running asad_sched_relay) projects it intoAssessmentDelivery. Legacy logins can no longer write booking or seat tables. After the M1 mixed traffic goes through the routing gateway (:8000), reconciliation shows 0 mismatches anddb/checks/seat-drift.sqlreturns 0 rows. On the legacy baseline the same report shows 2 mismatches and 2 drift rows.Deliberate legacy behaviour changes (all cited in ADR 0003):
db/security/040_single_writer.sql. Covers HB-01, HB-02, HB-28, HB-29, MR-01, MR-02 and MR-07. Every legacy login getsDENY INSERT/UPDATE/DELETEonBooking/Waitlist,DENY UPDATEonExamSession(Capacity, SeatsAvailable, AccommodationCapacity), andDENY EXECUTEonusp_BookSeat/CancelBooking/ChangeCapacity/RescheduleBooking. Onlyad_sched_relaycan write.036_component_logins.sql):ad_portal,ad_booking_api,ad_results,ad_capacity_sync,ad_sched_relay, plus the existingad_sched_import. These replace the sharedad_app. The local-dev passwords follow the convention035_sched_import_login.sqlalready uses. Azure/Release configs contain placeholders only.032_trg_Booking_SeatSyncand033_trg_ExamSession_Updatereturn early whenSESSION_CONTEXT(N'writer') = N'scheduling-relay'.033still stampsLastModified.capacity.sync.enabled=false.runSynconly writes itsCAPACITY_SYNCAuditLog row, marked SKIPPED. Reconciliation takes over its role.Booking.Status='ATTENDED'itself. It callsPOST /api/v2/bookings/{id}/attendanceon scheduling-service (:8090 directly), and the relay projects the result back to legacy.routing.modern-centers=*). A write that hits :8081 directly is rejected by SQL (permission error) and mapped to403 LEGACY_WRITE_DENIED.How the pieces work:
V2__outbox.sqladdsoutbox_event(seq BIGINT IDENTITY, uniqueevent_id) andbooking.legacy_booking_id.BookingCreated,BookingCancelled,BookingRescheduled,BookingWaitlisted,AttendanceRecorded,CapacityChanged, plusInventoryBaselined. The importer emitsInventoryBaselinedonce after a snapshot import, so the first relay pass aligns legacy counters with the modern derived values. Without it, pre-existing legacy drift would carry over.routing.coexistence-mode=relayandrouting.modern-centers=*. The*wildcard is accepted only in relay mode; withnone, the startup guard still refuses it.X-Routeand the floor of 50000000 are unchanged.AttendanceTokenGuardcompares headerX-Service-Tokenwithscheduling.attendance.service-token(envSCHEDULING_ATTENDANCE_SERVICE_TOKEN) usingMessageDigest.isEqual, beforerecordAttendance. A missing or wrong token gets 401{"error":"UNAUTHORIZED",...}and no outbox event. If the property is unset, every call is refused (fail closed). results-service sendsscheduling.service-token(envSCHEDULING_SERVICE_TOKEN).run-scheduling-service.*andrun-legacy.*set the same dev-only value; Azure takes the env var. The gateway answers 404 for/api/v2/bookings/*/attendanceon :8000. The path is normalised first: decoded,;paramsstripped,//collapsed, lower-cased. The other v2 writes stay unauthenticated, matching the legacy no-auth model (MR-16).serviceTokenapiKey security scheme and a 401 that uses a separateServiceTokenErrorschema. Other attendance errors reuseNOT_CANCELLABLE. This keeps the sharedApiErrorenum unchanged, soOpenApiCompatibilityTestagainst the published baseline still passes.api/openapi.yamlwas regenerated as described inapi/README.md.scripts/mixed-traffic.ps1: behind the gateway, the portal/Booking/Bookform redirects to the modern UI. The script now finishes that booking (and its cancel) the way/appdoes, through/api/v2/bookings. Direct legacy runs behave as before.Evidence
reports/reconciliation-20261111-205430.mdshows 462 sessions and 3,627 bookings with 0 mismatches;reports/seat-drift-m4-relay.txthas 0 rows.reports/reconciliation-20261111-205122-legacy-baseline.mdshows 2 session mismatches;reports/seat-drift-legacy-baseline.txthas 2 rows (session 155 drift 7, session 158 drift 4).dbo.Bookingrow is visible (includes sqlcmd polling): p50 0.28 s, p95 0.29 s, max 0.30 s.reports/attendance-auth-live-check.txt):POST :8000/api/v1/resultsreturned 201. The booking became ATTENDED in Scheduling and in legacy, with AuditLogBooking|ATTENDED|scheduling-service.AttendanceRecordedevent was written before the result. Afterwards reconciliation shows 462 sessions, 0 mismatches, 0 seat drift, and the relay has 0 pending.POST :8081/api/v1/bookings, returns403 LEGACY_WRITE_DENIED.Tests (Windows Server 2022 VM; Docker was available, so the Testcontainers ITs ran too)
mvn -B clean verify(JDK 21, Maven 3.9.9)src/test/resources/application.properties), so the suite never writes to a localAssessmentDelivery.mvn -B verify(JDK 21)services/mvnw.cmd -B -pl booking-api,results-service,capacity-sync verify(JDK 8)New coverage:
LegacySingleWriterIT(8): each legacy login gets a permission error onBookingINSERT and onSeatsAvailableUPDATE, procedure EXECUTE is denied, and the relay login can write. It runs against local SQL Express viaLegacyEstateDb, or skips.RelayIT(4): book, cancel, capacity increase and decrease, then reconciliation is exact. Every event is replayed twice with no duplicate Booking, Waitlist or AuditLog rows.InventoryBaselinedbrings drift to 0. Attendance is relayed.AttendanceViaSchedulingTest,AttendanceRecorderTest,CapacitySyncServiceTest(skip path),ApiExceptionHandlerTest.AttendanceTokenGuardTest(valid, missing, wrong, blank, unset).SchedulingApiITchecks 401 without a token and with a wrong token, the booking still BOOKED, no outbox event, then 200 ATTENDED with exactly one event.OpenApiSpecITchecks the security scheme.AttendanceRecorderTestchecks the header is sent and a 401 maps to 502. The results-service ITs use aSchedulingStubthat requires the token.InternalPathTestandGatewayIntegrationTestcheck the gateway 404.ReconcileCommandTest:reconcileforces--scheduling.relay.enabled=false --scheduling.import.on-startup=falseas command-line args, so it stays read-only.UI/E2E (testing agent, browser through
:8000, freshly reseeded estate): passed. Recording and screenshots are in the PR comment.Open / notes
Jira is read-only for this run (requester's rule), so the PR link was not posted to the ticket.
booking-api is not modified to proxy through HTTP. Its v1 writes reach scheduling-service via the gateway, and its DAO writes are now denied at the SQL level (see ADR 0003).
The attendance endpoint previously had no authentication (Devin Review escalation). Per the coordinator's decision it now requires
X-Service-Token, and the gateway does not expose it (see above).Cutover and rollback order is in runbook §6: re-import before
*, and hand attendance and modern-owned ids back before stopping scheduling-service.Devin-Org: engineering
Link to Devin session: https://devin-gtm.devinenterprise.com/sessions/790bcbf347474e669d759bbef4b2fe6f
Open in Devin Desktop: https://devin-gtm.devinenterprise.com/desktop/session/790bcbf347474e669d759bbef4b2fe6f?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