Repository navigation
feat(issuer-gateway): idempotency keys for lien-freeze and redeem (#46) - #1104
Merged
DevTobis merged 2 commits intoOct 23, 2026
Merged
Conversation
…vTobis#46) Both routes create lasting obligations at the issuer (a lien, a redemption payout), so a caller's timeout-and-retry duplicated them. An Idempotency-Key header now claims (issuer code, route, key) in the new issuer_idempotency table (migration 0010) before the issuer is called and stores its result. A replay with the same parameters returns the stored result with Idempotent-Replayed: true and does not call the issuer; other parameters under the key are 422; a key still in flight is 409; a failed issuer call releases the key. The key is forwarded to the issuer as an Idempotency-Key header. Requests without the header are unchanged.
|
@Hussman256 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Closes #46
lien-freezeandredeemcreate lasting obligations at the issuer (a lien, a redemption payout). Until now, a caller that timed out and retried would create a second one.Behaviour with an
Idempotency-Keyheader(issuer code, route, key)in the newissuer_idempotencytable (migration0010_issuer_idempotency, primary key on all three columns) before calling the issuer, then stores the issuer's result asjsonb.Idempotent-Replayed: true. The issuer is not called and no audit row is written. The parameters are fingerprinted with sha256.unitsis compared as a number, and the issuer code is lowercased, matchinggetAdapter.Idempotency-Keyheader through a new optionalIssuerRequestOptionsargument onrequestLienFreezeandrequestRedemption. That covers the case the gateway can't see: a timeout after the issuer did process the request.idempotencyKey.Without the header, behaviour is unchanged: every request reaches the issuer, and nothing is stored or forwarded. This is documented in the README.
Database failures
in_flightand a retry gets 409, not a second obligation. This is logged at error level.Tests (68 passing, up from 57)
src/idempotency.test.tsdrives both routes through the real adapters, withfetchstubbed and an in-memoryissuer_idempotencytable that honours the primary key and theeq/andfilters. It covers:unitswritten differently count as the same request.I checked the tests can fail: removing the different-parameters check makes one fail.
typecheckandbuildpass.Notes:
drizzle-ormto the gateway's dependencies (same version as the other services) and updates the lockfile by 3 lines.0010, the same as0010_payout_forward_bookingin fix(payout-hop): answer with the hash and repair bookkeeping when post-send writes fail (#49) #1102. Whichever merges second needs to be regenerated as0011.