Repository navigation
fix: an idempotency claim token, so a late complete or fail cannot end another run's claim - #33
Merged
Merged
Conversation
ADR-006. A key that expires or fails can be claimed again by the same client, and complete and fail name only the key, so a first run's late call acts on the second run's claim. check returns a claimId on new, and complete and fail apply only to the claim that was issued the ID they carry. The token is optional, so existing clients keep working.
A key that expires or fails is claimed again by the same client, so the record a first run's late complete or fail reaches is the second run's: live, Pending, and its client's. The ttl condition could not tell them apart. Each winning claim now gets a random claimId, written on the record and returned in IdempotencyResult.New. storeResponse and markFailed take it as an option; given one, the DynamoDB write adds claimId = :claimId to its condition, and both in-memory stores compare it the same way. Without one they behave as before (ADR-006).
check answers a claimId with new, and null otherwise: only the caller that won the claim holds its token. complete takes it in its body; fail, which had no body, takes an optional one with the single field, so an empty request still works. A call naming a claim that has since been replaced answers 409 not_pending, and the message says the key was claimed again. A request without a claimId behaves as before, so no existing client breaks (ADR-006). The architecture page also said the breaker lets one probe through at a time; it is up to half-open-max-calls.
The correlation middleware wrapped the routes alone, inside the error handling. A request whose handler raised never produced a response for it to stamp, so the 400, 422 and 500 answers went out without X-Request-Id. Routes.toHttpApp now takes a middleware to apply around the answered routes, and Main passes the correlation one.
GET /dashboard/api/status answered resetAt as the empty string. It is now the store's own value, as on /v1/ratelimit/status, and the current time for a bucket not yet created.
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.
PR 11 of the trust plan: the idempotency claim token, and two small fixes. Five commits.
Changes
docs(adr): fence complete and fail with a claim token. ADR-006. A key that expires or fails can be claimed again by the same client, andcompleteandfailname only the key, so a first run's late call acts on the second run's claim: itscompletestores the wrong response, and itsfailreleases a claim that is still running.fix(storage): complete and fail only the claim that is named. Each winning claim writes a randomclaimIdon the record.storeResponseandmarkFailedtake it as an option; given one, the DynamoDB write addsclaimId = :claimIdto its condition, and both in-memory stores compare it the same way.fix(api): return claimId from check, and accept it on complete and fail.checkanswers aclaimIdwithnew, andnullotherwise.completetakes it in its body;fail, which had no body, takes an optional one. A call naming a claim that has since been replaced answers 409not_pending.fix(api): carry X-Request-Id on body-decoding and 500 answers. The correlation middleware sat inside the error handling, so the 400, 422 and 500 answers went out without the header.fix(api): report the demo bucket's resetAt on dashboard status. It was always the empty string.Compatibility
Nothing breaks.
claimIdis a new field on the check answer, and optional oncompleteandfail: a request without one behaves as before, including an emptyfail.Known limits
claimIdkeeps the gap ADR-006 describes. Requiring the token is a later decision.claimId, so the token is covered by unit and LocalStack tests only.Verified locally
completeanswers 409, a barefailanswers 200, a 400 echoesX-Request-Id, and the dashboard status has a realresetAt.scalafmtCheckAll. Terraform checks not run: nothing in Terraform changed.