feat(compliance): make kyc session initiation idempotent - #286
Merged
Conversation
Add Idempotency-Key support to POST /v1/kyc/sessions, mirroring the payments service. A new compliance.idempotency_keys table keyed on the SHA-256 of the header backs a reserve-or-run store: the first call creates the session and records the key in the same transaction, and a repeat with the same key replays the original session instead of creating a second one. The controller now requires the header (400 if absent), a lost race retries in a fresh transaction and falls back to a 503 after the bounded attempts, and only the key hash is stored, never the raw header value. Closes #277
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.
E-04 #277 (LAST E-04 slice) - Idempotency-Key dedup on POST /v1/kyc/sessions, mirroring the merged payments #211 service-level pattern.
What
v0.1/022-idempotency-keys.sql(idempotent):compliance.idempotency_keys(key_hash VARCHAR(64) PK, kyc_session_id UUID, created_at), wired into the master changelog.DataIntegrityViolationException->KycIdempotencyRaceException.Sha256.hex(key)-> bounded retry (MAX_ATTEMPTS=3) ->KycConcurrencyExceptionon a persistent race. A lost race retries in a fresh transaction, finds the winner's committed key, and replays.Idempotency-Key(400 via a newMissingRequestHeaderExceptionhandler); concurrency -> 503 retryable withRetry-After. Only the SHA-256 hash is stored, never the raw header.Gate chain
retryable(type,detail,request)verbatim; exception keeps its message - all applied).var, callsadapter.toDomainin its store, and returns a bareProblemDetail); the missing-header->400 test ran and passed (7 tests, 0 failures).All local gates green; the replay + screening + round-trip ITs run on CI.
With this merged, epic E-04 Compliance #162 is complete.
Closes #277