feat(idempotency): durable, payload-bound idempotency for postage mutations - #1903
Merged
kryputh merged 3 commits intoJul 29, 2026
Merged
Conversation
…e keys by method/route Idempotency records already persisted durably via Durable Object storage (surviving restarts and shared across Worker instances), but the same raw key was only hashed with the actor, not the method/route, and carried no binding to the request payload. A reused key with a different payload silently replayed (or blocked behind) the wrong response instead of failing closed. - Store a canonical request-body digest on every idempotency record and compare it on acquire; a mismatch now returns 409 idempotency_mismatch instead of an incorrect replay or block. - Scope the key hash by actor + HTTP method + route template, not actor alone, so the same client key can't collide across endpoints. - Add withIdempotency(), a single entry point that acquires the lease, replays completed records, and releases the lease on uncached (transient) failures so an immediate retry isn't blocked for the full lease TTL. - Wire the postage submit and settle routes onto the new helper, and add the same idempotency support to postage refund, which previously had none. - Bump the idempotencyRecord schema to v2 with a migration for legacy records predating requestDigest.
4 tasks
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.
Summary
Idempotency records were already persisted durably (Durable Object storage,
surviving restarts and shared across Worker instances), but the key hash
only bound to
actor:rawKey— not the request payload, method, or route.A reused key with a different payload would silently replay the wrong
cached response instead of failing closed, and refund had no idempotency
support at all despite being as payment-critical as settle.
a reused key with a different payload now returns
409 idempotency_mismatchinstead of an incorrect replay or block
withIdempotency(), a single entry point that acquires the lease,replays completed records, records terminal outcomes, and — critically —
releases the lease on an uncached transient failure, so a legitimate
retry isn't blocked for the full lease TTL
idempotency support to postage refund, which previously had none
idempotencyRecordschema to v2 with a migration for legacyrecords predating
requestDigestCloses #1498
Acceptance criteria
verified with two independent coordinator instances sharing storage)
Test plan
npx vitest run tests/unit— 1688 passing, 3 pre-existing expected-failnpx tsc --noEmit— cleannpx eslinton all changed files — cleantransient-failure lease release, and route-level tests for settle/refund