Repository navigation
Let a setup-token retire win over a finish still in flight - #1143
Merged
Merged
Conversation
Deploying mouseterm with
|
| Latest commit: |
4139304
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://b445e437.mouseterm.pages.dev |
| Branch Preview URL: | https://relay-setup-retire-race.mouseterm.pages.dev |
A retire now wins over a setup finish still in flight; previously a failing finish could restore a token the owner had just retired, leaving it redeemable until it expired. `finish` now claims its token in place instead of removing it, so a retire still finds a token a finish holds and kills it (204). The finish re-checks its claim immediately before the registration write and registers nothing without it, and its failure path only clears a claim that is still there, so it can never put a retired token back. - Self-host Relay: `SetupTokenIssuer` tracks live / claimed / committed slots (`claim`, `commit`, `settle`, `restore`, `retire`). - Hosted Relay: migration 006 adds `claimed` to the setup-token table; the passkey transaction re-reads the claim `FOR UPDATE` and deletes the token on registering; restore clears the flag; retire deletes claimed or not. - Specs: a new FAIL IF under security-remote "Trust boundary", the hosted FAIL IF tightened, relay.md and hosted.md updated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
nedtwigg
force-pushed
the
relay-setup-retire-race
branch
from
October 16, 2026 21:14
8d7e297 to
d0fa6dd
Compare
nedtwigg
had a problem deploying
to
hosted-preview
October 16, 2026 21:17 — with
GitHub Actions
Error
dormouse-bot
left a comment
Collaborator
There was a problem hiding this comment.
The Hosted FAIL IF that replaces the restore rule now states the restore and FOR UPDATE requirements as descriptions, not conditions, so the nightly audit would not flag a regression in either. There is a suggested rewording inline.
…as failure conditions Co-Authored-By: Claude Opus 5.5 <[email protected]>
dormouse-bot
approved these changes
Oct 16, 2026
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.
A retire now wins over a setup finish still in flight; previously a failing finish could restore a token the owner had just retired, leaving it redeemable until it expired.
Fix
POST /api/setup/finishnow claims its setup token in place instead of removing it, soPOST /api/setup/retirestill finds a token a finish holds and kills it, answering 204. The finish re-checks its claim immediately before the registration write and registers nothing without it, and its failure path only clears a claim that is still there, so it never puts a retired token back. Single use and the original expiry are unchanged.relay/src/setup-token.ts,relay/src/app.ts):SetupTokenIssuerkeeps each token as a live / claimed / committed slot, withclaim,commit,settle,restore, andretire. A claimed token counts toward the Burrow cap like any other, and one the cap evicts stays dead.hosted/server/relay-api.ts): migration006_relay_setup_token_claim.sqladdsclaimedtodormouse_relay_setup_tokens(the relay role getsUPDATE (claimed)).beginignores claimed rows. The passkey transaction re-reads the claimFOR UPDATEand deletes the token when it registers. Restore just clears the flag, and retire deletes the token whether it is claimed or not.The HTTP contract stays the same shape: retire still answers 204 or 401
SETUP_TOKEN_INVALID_ERROR, so Pocket needs no change.Tests
relay/test/setup-token.test.mjs: two route-level regressions suspend a finish (one failing, one valid) on a deferred promise after it claims the token, retire it, then release the finish. The retire must answer 204, the finish must register nothing, and the token must not be redeemable afterwards. Issuer-level tests cover retire against claimed and committed tokens and cap eviction of a claimed token. Mutation-checked: each new test goes red when the retire skips claimed tokens, when it leaves them for restore, or when the commit check is removed.hosted/server/tests/relay.test.ts: the same interleaving against real Postgres, holding the account's passkey lock so the finish waits with its claim held. Mutation-checked against each of the three fix lines. The restore tests are rewritten for claim-in-place, and the migration and role pins are updated.Specs
docs/specs/security-remote.md→ "Trust boundary": a newFAIL IF, appended so nothing shifts and claimed by theremote-trustdomain. Budget ratcheted.docs/specs/security-hosted.md→ "Relay boundary": the restoreFAIL IFnow fails a retire that misses a claimed token, a refused finish that does more than clear its claim, and a passkey insert that does not first re-read the claimFOR UPDATE.docs/specs/relay.md→ "Setup tokens and the pairing QR" anddocs/specs/hosted.md→ "Relay": updated to match.🤖 Generated with Claude Code