Skip to content

Publish, close and archive check the status without a lock, so an archive racing a publish leaves the signup open #437

Closed

Description

@richshaw

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 with conflict. 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 two signup.closed activity rows in 40 of 40 runs.
  • Publish vs deleting the last slot. The slot count runs outside any lock too, so a deleteSlot landing 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 readLiveSignup only to find the workspace and run requireWorkspaceWrite, as updateSignup does.
  • Then, in one transaction: lockSignupForWrite(tx, signupId, workspaceId), re-check row.status against from on the locked row, run the publish slot count with tx, and do the UPDATE and recordActivity with payload.from taken from the locked row.
  • The second of two racing calls then sees the new status and gets the same conflict it would get if the calls had run one after the other.

Watch for

  • The lock order. lockSignupForWrite documents the order signup writes take locks in; the transition only needs the signup row, so it fits, but check deleteSlot takes the signup lock before the slot lock so publish-vs-delete-slot serializes rather than deadlocks.
  • archiveSignup passes from: 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.ts caps 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, in createSignup/updateSignup. Whichever lands second has a small merge.

Done when

  • A DB test in src/services/signups.db.test.ts races archiveSignup against publishSignup on 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 on main today.
  • A DB test races two closeSignup calls and asserts exactly one succeeds and exactly one signup.closed activity row exists.
  • pnpm lint && pnpm typecheck && pnpm knip && pnpm test && pnpm test:db pass.

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

  1. added
    bug
    pipeline:working
    and removed
    pipeline:working
    on Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions