Repository navigation
fix(coverage): make coverage transitions atomic, preserve original requester, and reject canceled shifts - #218
Draft
theosiemensrhodes wants to merge 1 commit into
Conversation
…er, and reject canceled shifts
theosiemensrhodes
marked this pull request as draft
November 23, 2026 20:26
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
Makes coverage and shift attendance transitions atomic per shift, preserves the original requester across coverer unassignment and replacement, and rejects attendance and coverage mutations on canceled shifts. Stacked on top of #216 (
fix/neuron-n04-assignment-history) and consumes its shared effective-assignment contract (isVolunteerEffectivelyAssignedToShiftinsrc/server/services/entity/shiftAssignment.ts).Changes
src/server/services/entity/coverageService.ts):createCoverageRequest,cancelCoverageRequest,fulfillCoverageRequest, andunassignCoverageeach run inside a transaction that locks the targetshiftrow (FOR UPDATE) before inspecting current coverage state or effective roster membership.fulfillCoverageRequestchecks effective shift membership viaisVolunteerEffectivelyAssignedToShift(tx, shiftId, coveredByVolunteerUserId)under the shift lock, prevents self-fulfillment, and updates conditionally (status = 'open' AND covered_by_volunteer_user_id IS NULL), emitting notifications only after commit. This guarantees at most one competing claimant succeeds and prevents a volunteer from occupying multiple coverage slots on the same shift.cancelCoverageRequestupdates conditionally (status = 'open' AND covered_by_volunteer_user_id IS NULL) so withdrawal and fulfillment serialize cleanly.unassignCoveragepreserves the originalrequestingVolunteerUserId(fixingA -> B -> unassign -> CproducingA + Con the roster), verifies the request isresolvedand the outgoing coverer is still effectively assigned (preventing double-roster corruption after an onward handoff), updates conditionally (status = 'resolved' AND covered_by_volunteer_user_id = ...), and withdraws any orphaned open outgoing request from the outgoing coverer.src/server/services/entity/shiftService.ts):checkIn,cancelShift, andassertValidShiftreject canceled shifts and lock theshiftrow (FOR UPDATE) inside a transaction so attendance, cancellation, and coverage mutations serialize per shift.checkInchecks effective roster membership under the shift lock viaisVolunteerEffectivelyAssignedToShift(tx, shiftId, volunteerId)and preserves unpublished-term visibility checks.cancelShiftuses a conditional update (canceled = false) so concurrent cancellations remain idempotent and do not duplicate cancellation notifications.src/test/integration/coverage-transitions.test.ts):A -> B -> unassign -> Coriginal-absence preservation, resulting effective roster, check-in eligibility, requester withdrawal after unassign, and onward-transfer / orphaned-request edge cases.postgrespoolmax: 10) for competing claimants on one open request, single volunteer claiming two open slots on the same shift, fulfill vs. withdraw races, concurrent unassignments, and shift cancellation vs. fulfillment races.checkIn(regular volunteer and admin override),createCoverageRequest,cancelCoverageRequest,fulfillCoverageRequest, andunassignCoverage.Validation
pnpm test:run src/test/integration/coverage-transitions.test.ts src/test/integration/shift-assignment.test.ts src/test/integration/shift-service.test.ts src/test/unit/shift-assignment.test.tson a unique disposable database (neuron_test_n03_coverage, dropped after run): 4 files, 27/27 tests passed.SKIP_ENV_VALIDATION=1 pnpm exec next typegen && pnpm typecheck: passed (0 errors).pnpm exec prettier --checkon all modified/added files: passed.eslintcurrently fails onmaindue to a pre-existing@eslint/eslintrccircular JSON error witheslint-config-next, and existingsrc/test/integration/coverage-service.test.tsuses hardcoded2026-07-15dates that are in the past relative to the local clock.