Repository navigation
Give a retried sign-up back the spot it already took - #396
Conversation
A sign-up whose answer was lost (a phone dropping its connection after the server saved it) could be sent again with the same details. Without an email that took a second spot, and the first one's link was nowhere; with an email it was refused as a duplicate, losing the link the same way. The sign-up form now sends an idempotencyKey with each sign-up, and the same key again when Confirm is pressed again with the same details. commitToSlot finds an active commitment on the slot made with that key in the statement that locks the slot, and returns it instead of making another. The route sends no second confirmation for a repeat, but answers with the same link and cookie. The key is kept hashed in the new commitments.idempotency_key_hash column. Part of #387. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SSB1D4rKHxrax5TQ64DW8X
The idempotency lookup was a join in the statement that locks the slot. Under READ COMMITTED that statement reads the snapshot it started with, before it waited, so a retry queued behind a first try still in progress missed the commitment the first try made, and took a second spot: the very case #387 is about. The lookup is now its own statement after the lock, sent only when a key is. The form always sends a key, so a sign-up sends one more statement to Postgres: budgets.json goes from 14 to 15 with an email and from 12 to 13 without. The new DB test holds a first try open after it takes the place, queues the retry behind its lock, and fails on the joined lookup. Also redacts idempotencyKey from logs, since it brings back the edit link, and adds DB, route, query budget and sign-up form tests. Part of #387. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SSB1D4rKHxrax5TQ64DW8X
The first request reaches the server and saves the sign-up, then the browser is told the connection failed. Pressing Confirm again shows the edit link of the sign-up the first request made. Part of #387. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SSB1D4rKHxrax5TQ64DW8X
Tophat: passedRan 6346b0d locally with Updated for 6944d81, the review fixes:
To make a response go missing, I wrapped
No browser console errors on any page. No errors in the web or worker logs, apart from the dev server's existing Not UX: no screen, wording, email or step changes. The only difference people see is that a retry after a network error ends at "You're in." with their link, instead of a second spot or a "you already committed" error. Screenshots are in https://claude.ai/code/session_01SSB1D4rKHxrax5TQ64DW8X. Generated by Claude Code |
…ailed try From the code review of this change: - Closing the sign-up sheet after a network error threw the key away, so opening it again and pressing Confirm with the same details took a second spot, the bug this fixes. The row still says Sign up then, so that is another way of trying again. The form now forgets the key only once a sign-up goes through. - The server matched on the key alone, so a client that picked guessable keys would hand one person's edit link to anyone who sent the same key. The key is now stored and looked up as an HMAC, keyed with AUTH_SECRET, of the key and the request as parsed: it finds an earlier sign-up only when sent with the same name, email, notes and spots, and a copy of the database can't be checked against guessed keys. - The lookup is scoped to the slot's workspace, as CLAUDE.md asks of every tenant-table query. Part of #387. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SSB1D4rKHxrax5TQ64DW8X
Fixes #387.
The problem
A phone can lose its connection after the server saves a sign-up but before the answer arrives. The form then says "network error", and the person presses Confirm again.
The fix
idempotencyKey(128 random bits) with each sign-up.POST /api/slots/[id]/commitmentslooks for an active commitment on that slot made with the same key and the same details. If it finds one, it hands it back with the same edit link and cookie, instead of making another. It writes nothing and sends no second confirmation email.Things worth a look
0012adds a nullablecommitments.idempotency_key_hash. It holds an HMAC, keyed withAUTH_SECRET, of the key and the request as parsed (name, email, notes, spots). It never holds the key itself, since the key brings back the edit link.gives the first sign-up back to a retry that queued behind itholds a first try open, queues a retry behind its lock, and fails if the lookup is moved into the locking query.budgets.jsongoes 14 → 15 with an email and 12 → 13 without. The form always sends a key, so every sign-up from it pays for the lookup. The lookup can't share a statement that waits on the lock, for the reason above.idempotencyKeyis added to the log redaction list.src/db/migrations/meta/0012_snapshot.json. Drizzle generates that file with every migration, as it did for0010and0011.Testing
pnpm lint,pnpm typecheck,pnpm knip,pnpm test,pnpm budgetspnpm test:db, all of it. The new tests cover:🤖 Generated with Claude Code
https://claude.ai/code/session_01SSB1D4rKHxrax5TQ64DW8X