Repository navigation
Description
What happens
transitionStatus in src/services/signups.ts (behind publishSignup, closeSignup and archiveSignup) checks the signup's status, and for a publish its slot count, on a read taken with no lock (readLiveSignup). It then opens a transaction and runs an UPDATE that filters only on id and deleted_at IS NULL. It never takes lockSignupForWrite, which every other signup write takes, and the UPDATE doesn't re-check status = from.
So two transitions that overlap both pass their checks and both write:
- Archive vs publish. On a draft with one slot,
Promise.all([archiveSignup, publishSignup])ended with the signup open and both calls reporting success in 37 of 40 runs. No serial order gives that result: publish-then-archive ends archived, and archive-then-publish refuses the publish withconflict. The organizer is told it's archived while/s/[slug]is live and taking sign-ups. - Double close.
Promise.all([closeSignup, closeSignup])on an open signup succeeded twice and wrote twosignup.closedactivity rows in 40 of 40 runs. - Publish vs deleting the last slot. The slot count runs outside any lock too, so a
deleteSlotlanding between the count and the UPDATE leaves an open signup with no slots. This one was read from the code, not run.
Who hits it: an organizer acting in one tab while a connected AI assistant (or another tab) acts on the same signup. Rare, but when it happens the result is silent and wrong, and the activity log records a from that was already stale.
deleteSignup, just above it, already guards its own race with a conditional UPDATE.
Fix, in outline
- Keep the unlocked
readLiveSignuponly to find the workspace and runrequireWorkspaceWrite, asupdateSignupdoes. - Then, in one transaction:
lockSignupForWrite(tx, signupId, workspaceId), re-checkrow.statusagainstfromon the locked row, run the publish slot count withtx, and do the UPDATE andrecordActivitywithpayload.fromtaken from the locked row. - The second of two racing calls then sees the new status and gets the same
conflictit would get if the calls had run one after the other.
Watch for
- The lock order.
lockSignupForWritedocuments the order signup writes take locks in; the transition only needs the signup row, so it fits, but checkdeleteSlottakes the signup lock before the slot lock so publish-vs-delete-slot serializes rather than deadlocks. archiveSignuppassesfrom: null(any status), so the status check is skipped for it, but it still has to run under the lock.src/app/query-budget.db.test.tscaps statements on some routes. Publishing isn't one of them, but run it anyway.- A signup can be created or renamed with a blank title #425 (blank titles) also edits
src/services/signups.ts, increateSignup/updateSignup. Whichever lands second has a small merge.
Done when
- A DB test in
src/services/signups.db.test.tsracesarchiveSignupagainstpublishSignupon a draft with one slot and asserts the end state matches one of the two serial orders (archived with publish refused, or archived after a successful publish). It fails onmaintoday. - A DB test races two
closeSignupcalls and asserts exactly one succeeds and exactly onesignup.closedactivity row exists. pnpm lint && pnpm typecheck && pnpm knip && pnpm test && pnpm test:dbpass.
Found by the pipeline's bugs scout in the signup and slot services (src/services/signups.ts, src/services/slots.ts, src/services/slot-fields.ts), at fbf02f9. Checked by an independent DB test: a forced interleave and plain Promise.all races through the services alone both reproduced it. https://claude.ai/code/session_01DnNp2YEziFdBN3uYtSvNNa
Activity