feat(api): idempotency keys for payment and callback endpoints (#24) #92

Merged
amiryahaya merged 2 commits from feat/24-idempotency into main 2026-10-25 04:55:31 +01:00
Owner

Part of #24: the idempotency mechanism. No route uses it yet.

What

  • Migration 0012: idempotency_keys with UNIQUE (scope, operation_key), payload SHA-256, saved response, created_at index.
  • pgstore.Store.Run: reserve the key, run the work and save the 2xx response in one transaction. Retries on any node replay the first response.
  • idempotency.Handle: HTTP wrapper for the Idempotency-Key header. Missing key 400, key reused with different bytes 409, duplicate still running 503 + Retry-After, business Rejection returned as its own problem and left retryable.
  • Store.Purge(cutoff) for retention.
  • ADR 0008 records the decisions.

Review

Dual pass per CLAUDE.md: ponytail (no Must fix left) and a superpowers reviewer (no Critical; Important items fixed).

Not in this PR

  • Retention job (worker mode does not exist yet).
  • A route that uses Handle, with the Idempotency-Key header and 400/409/503 in openapi.yaml.
  • Policy for provider callbacks that re-send with different bytes (currently 409, see ADR 0008).

Checks run locally

make lint, make cover (94.4%), make contract.

🤖 Generated with Claude Code

Part of #24: the idempotency mechanism. No route uses it yet. ## What - Migration 0012: `idempotency_keys` with `UNIQUE (scope, operation_key)`, payload SHA-256, saved response, `created_at` index. - `pgstore.Store.Run`: reserve the key, run the work and save the 2xx response in one transaction. Retries on any node replay the first response. - `idempotency.Handle`: HTTP wrapper for the `Idempotency-Key` header. Missing key 400, key reused with different bytes 409, duplicate still running 503 + `Retry-After`, business `Rejection` returned as its own problem and left retryable. - `Store.Purge(cutoff)` for retention. - ADR 0008 records the decisions. ## Review Dual pass per CLAUDE.md: ponytail (no Must fix left) and a superpowers reviewer (no Critical; Important items fixed). ## Not in this PR - Retention job (worker mode does not exist yet). - A route that uses `Handle`, with the `Idempotency-Key` header and 400/409/503 in `openapi.yaml`. - Policy for provider callbacks that re-send with different bytes (currently 409, see ADR 0008). ## Checks run locally `make lint`, `make cover` (94.4%), `make contract`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
feat(api): idempotency keys for payment and callback endpoints (#24)
All checks were successful
ci / changes (pull_request) Successful in 14s
ci / clients (pull_request) Has been skipped
ci / api (pull_request) Successful in 7m33s
ci / ci-gate (pull_request) Successful in 2s
14cb4037d7
Reserve (scope, key), run the work and save the 2xx response in one
transaction, so retries on any node replay the first response. A key reused
with different bytes is a 409; a duplicate that waits too long is a 503;
business rejections roll back and leave the key free. Adds Store.Purge for
retention and ADR 0008. No route uses it yet.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
primatekuntech/kws!92
No description provided.