Skip to content

[MBA-3831] Capacity-change notification event to affected candidates (notification stub) - #98

Merged
devin-ai-integration[bot] merged 7 commits into
estate/legacy-baselinefrom
devin/mba-3831-capacity-impact-notifications
Nov 11, 2026
Merged

devin-ai-integration[bot] merged 7 commits into
estate/legacy-baselinefrom
devin/mba-3831-capacity-impact-notifications

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Summary

A6 / MBA-3831. PUT /api/v2/sessions/{id}/capacity now writes one CandidateCapacityImpactNotified outbox event for each affected candidate. Legacy never told anyone when their booking was demoted (MR-04 "who notifies demoted candidates?", HB-05 / ODD-02). The relay delivers these events to a new NotificationPort. The only implementation is the stub LoggingNotificationAdapter: it writes a structured log line and keeps an in-memory store, readable at GET /internal/notifications?candidateNumber= (the filter is required). Nothing is sent by email or SMS.

Merged with A4 (#99, waitlist auto-offer, base 8cc35d8). Both features run in the same changeCapacity transaction:

changeCapacity (one tx, session locked):
  before = repo.bookingStates(session); offeredBefore = pending seat_offer booking ids
  ...plan / demotions / capacity_change / outbox CapacityChanged...
  offers.withdrawExcess(...)    // A4: SeatOfferWithdrawn
  offers.offerFreedSeats(...)   // A4: SeatOffered
  for a in CapacityImpact.affected(old, new, before, repo.bookingStates(session), offeredBefore, pendingOffersNow):
      outbox.appendNotification(CandidateCapacityImpactNotified{eventId=outbox event_id, sessionId, centerCode,
          examCode, startsAt, oldCapacity, newCapacity, candidateNumber, bookingId, previousStatus, newStatus, impact})

CapacityImpact.affected: status changed                 -> STATUS_CHANGED  (e.g. BOOKED->WAITLISTED demotion)
                         new pending offer (A4)         -> SEAT_OFFERED    (WAITLISTED->WAITLISTED, seat held)
                         pending offer withdrawn (A4)   -> OFFER_WITHDRAWN (WAITLISTED->WAITLISTED, keeps place)
                         else new<old && BOOKED         -> SEAT_CONFIRMED  ("capacity reduced, your seat is confirmed")
                         increase, no offers            -> nothing

RelayWorker: e.type().projectsToLegacy() ? LegacyRelay.apply(e) : NotificationDelivery.deliver(e)
  • Legacy is untouched. Notification events write nothing to AssessmentDelivery: no AuditLog, no RelayCheckpoint, so reconciliation is unaffected. LegacyRelay.apply also returns false for these events as a guard. Delivery is at least once, and the stub ignores an eventId it has already recorded. A4's SeatOffer* events still project to legacy.
  • Migration. V4__candidate_notification_event.sql runs after A4's V3__waitlist_offers.sql and appends the event type to ck_outbox_event_type, rebuilding the constraint from its current definition so all of V2 and V3's types are kept. OutboxEventType keeps every type from M4, A4 and this story.
  • Additive API change. CapacityResultDto.notifiedCandidates is new. api/openapi.yaml was regenerated with the OpenApiSpecIT -Dopenapi.write=true command, and the UI contract capacity.yml was updated. The CapacityEditor toast now shows "N candidate notification(s) queued (stub, no email/SMS)", and the confirm dialog has a hint.
  • Schema and docs. services/scheduling-service/docs/events.md documents the event, and docs/schemas/candidate-capacity-impact-notified.schema.json holds the JSON Schema 2020-12. CandidateCapacityImpactSchemaTest checks the record against the schema; the ITs validate stored payloads against it.
  • Extra field impact. This is one field beyond the ticket's list. It tells consumers why the candidate is notified: an offer change leaves the status unchanged, so the status pair alone doesn't say.
  • Runbook. docs/runbooks/scheduling-service.md has both the "Candidate notifications" and A4's "Waitlist offers" sections.

Tests

  • JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64 SCHEDULING_IT_SQL_URL='jdbc:sqlserver://localhost:1433;encrypt=true;trustServerCertificate=true' ./mvnw -B clean verify in services/scheduling-service, on merged head 8af1a0b (base 8cc35d8, A4 included): 80 unit + 77 IT tests, 0 failures, BUILD SUCCESS. CI verify (API contract) is green. Runtime evidence is in a PR comment.
  • New tests:
    • CapacityImpactTest (7), LoggingNotificationAdapterTest (3), CandidateCapacityImpactSchemaTest (5).
    • CapacityImpactNotificationIT (5):
      • Capacity 20→8 with 10 booked gives exactly 2 STATUS_CHANGED and 8 SEAT_CONFIRMED.
      • An increase gives 0 notifications.
      • The same event delivered twice is recorded once.
      • The endpoint filter is required.
      • New A4 combined case on session 163. Capacity 3→5 gives CapacityChanged, 2× SeatOffered and 2× SEAT_OFFERED in one call. Capacity 5→2 then withdraws both offers and notifies OFFER_WITHDRAWN for both, STATUS_CHANGED for the demoted bookings and SEAT_CONFIRMED for the rest.
    • RelayIT order 6: the real worker delivers to the stub once, legacy gets +1 AuditLog / +1 RelayCheckpoint (CapacityChanged only), a replay changes nothing, and reconciliation shows 0 mismatches and 0 drift. A4's offer lifecycle relay test is order 5.

Devin-Org: engineering

Link to Devin session: https://devin-gtm.devinenterprise.com/sessions/9a510b2ddf494f54a366e5f0f28e49c0
Open in Devin Desktop: https://devin-gtm.devinenterprise.com/desktop/session/9a510b2ddf494f54a366e5f0f28e49c0?variant=devin
Requested by: @mbatchelor81


🟢 Devin Review found nothing to fix · View findings · Follow Devin's work

Devin Review

…nPort logging stub

Co-Authored-By: Mason <masonbatchelor81@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@socket-security

socket-security Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedmaven/​com.networknt/​json-schema-validator@​1.5.95410097100100

View full report

devin-ai-integration Bot and others added 2 commits November 11, 2026 22:20
Co-Authored-By: Mason <masonbatchelor81@gmail.com>
…listing)

Co-Authored-By: Mason <masonbatchelor81@gmail.com>

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Devin Review found 2 findings. Devin automatically fixed all 2 findings.

Fixed by Devin (2)
  • Plain-text notification logs lose event details — impact, candidateNumber, bookingId, sessionId, previous/new status and eventId are now message placeholders (StructuredArguments), so plain-logs shows them as key=value. JSON logs still carry every field.
  • Unauthenticated bulk access to candidate notifications — candidateNumber is now required: 400 when missing or blank, so there is no bulk listing (IT asserts this). The endpoint stays off the gateway (/internal is not routed) and out of the public OpenAPI spec, like /internal/reconciliation.

View findings in Devin Review · Follow Devin's work

Devin Review

devin-ai-integration Bot and others added 3 commits November 11, 2026 22:22
Co-Authored-By: Mason <masonbatchelor81@gmail.com>
…mismatches, 0 drift)

Co-Authored-By: Mason <masonbatchelor81@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

Test results on merged head a1be7db (estate/legacy-baseline 192a423 merged in, M5 included)

  • JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64 SCHEDULING_IT_SQL_URL='jdbc:sqlserver://localhost:1433;encrypt=true;trustServerCertificate=true' ./mvnw -B clean verify (services/scheduling-service): 70 unit + 60 IT tests, 0 failures/errors, BUILD SUCCESS.
  • CI: verify (API contract job) and the other 5 checks are green. Devin Review on a1be7db reports 0 findings, including flag severity.

Runtime (services rebuilt from a1be7db, real SQL Server, [REDACTED SECRET] /app through gateway :8000)

Session 155 (DUB01): capacity 16 to 1 with 3 BOOKED. The two newest bookings were demoted to WAITLISTED, and 3 notifications were queued:

  • 1616 / NW00000763: STATUS_CHANGED, BOOKED to WAITLISTED
  • 1618 / NW00000700: STATUS_CHANGED, BOOKED to WAITLISTED
  • 3334 / NW00000610: SEAT_CONFIRMED

Raising capacity 1 to 16 returned notifiedCandidates: 0. It added no notifications and did not promote anyone from the waitlist.

Confirm hint Queued toast
hint toast
STATUS_CHANGED payload SEAT_CONFIRMED payload
status changed seat confirmed
Missing candidateNumber returns 400 Reconcile = 0
400 reconcile
  • Outbox (SQL): all 3 notification rows have relayed_at set. There are 0 duplicate event_ids and 0 notification events in legacy dbo.RelayCheckpoint.
  • Reconciliation: 462 sessions and 3,587 bookings compared; 0 session mismatches, 0 booking mismatches, 0 seat-drift rows.
  • M5 sanity: the retired My Bookings URL redirects to the /app candidate page, and direct booking-api writes return 410 LEGACY_WRITE_RETIRED.

Recording:

recording

Not exercised at runtime: a forced duplicate replay of the same event. CapacityImpactNotificationIT and RelayIT cover that case.

Written by Devin

…-3831; notify SEAT_OFFERED / OFFER_WITHDRAWN on capacity changes

Co-Authored-By: Mason <masonbatchelor81@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

Runtime check on merged head 8af1a0b (base 8cc35d8, A4 included)

Setup: real SQL Server, a fresh Scheduling DB (Flyway V1→V4), and the relay running, driven through the gateway at :8000/app/. Results:

Session #158

  • Capacity 11→2 queued 4 notifications and demoted 2 bookings.
  • Capacity 2→3 made one held offer (SEAT_OFFERED); the booking stayed WAITLISTED.
  • Capacity 3→1 withdrew that offer and the candidate kept their waitlist place. It queued OFFER_WITHDRAWN, STATUS_CHANGED and SEAT_CONFIRMED.
  • Accepting a re-created offer through My bookings on :8000 worked.

Other checks

  • Increasing session #218, which has no waitlist, emitted 0 notifications.
  • A missing or blank candidateNumber returns 400.

Relay and reconciliation

  • All 9 notification events were relayed, with unique IDs.
  • None of them appeared in legacy RelayCheckpoint.
  • SeatOffered and SeatOfferWithdrawn were projected to legacy.
  • Reconcile before and after the offer acceptance: 462 sessions / 3,587 bookings, 0 mismatches / 0 seat drift.

Recording

Reduction hint Queued toast
hint toast
Pending offer Withdrawn, waitlist kept
offer withdrawn
STATUS_CHANGED SEAT_CONFIRMED
sc conf
SEAT_OFFERED / OFFER_WITHDRAWN Missing filter → 400
offer json 400
Offer accepted Reconcile = 0
accepted reconcile

Not exercised at runtime: forcing a duplicate replay of the same event. CapacityImpactNotificationIT and RelayIT cover that case.

Written by Devin

@devin-ai-integration
devin-ai-integration Bot merged commit 1864c97 into estate/legacy-baseline Nov 11, 2026
6 checks passed
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.

0 participants