Skip to main content

max / makenotwork

payments: document idempotency storage is consumed by the global middleware The idempotency.rs functions are the storage layer for metrics::idempotency_middleware (the global POST/PUT replay guard) and are exercised by tests/workflows/idempotency.rs (6 adversarial tests). The audit twice misread the module as unwired/untested because the consumer lives in the middleware layer, not the payment routes; name it in the module doc so the wiring is discoverable and additive to the structural checkout dedup index. ultra-fuzz Run 5 M-Pay1 (deep). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Author: Max Johnson <me@maxj.phd> · 2026-06-24 02:12 UTC
Commit: 5a31ce3a38b6fb14a38ed05efee97d5e66183a1c
Parent: f562a1f
1 file changed, +11 insertions, -0 deletions
@@ -1,4 +1,15 @@
1 1 //! Idempotency key storage for safe POST retries.
2 + //!
3 + //! These functions are the storage layer for [`crate::metrics::idempotency_middleware`],
4 + //! the global POST/PUT replay guard mounted on the router: it reads
5 + //! [`get_cached_response`] before running a handler and writes [`store_response`]
6 + //! (fire-and-forget, via the background pool) on a successful 2xx/3xx response,
7 + //! scoped to `(key, user_id, method, path)`. The scheduler calls
8 + //! [`cleanup_expired`] on its daily tick. This is distinct from — and additive
9 + //! to — the structural checkout dedup (the `(buyer_id, item_id) WHERE
10 + //! status='pending'` partial unique index): the index makes a double checkout
11 + //! unrepresentable; this cache replays the *response* of any retried POST/PUT.
12 + //! Exercised end-to-end by `tests/workflows/idempotency.rs`.
2 13
3 14 use sqlx::PgPool;
4 15 use crate::db::UserId;