FM-018 Time, State, and API Lifecycle

Idempotency and Duplicate-Operation Failures

A retry after a timeout causes the same payment or order to be processed twice because idempotency keys are absent or mishandled.

Failure explanation

A client repeats a request after a timeout, lost response, or uncertain network outcome, and the server performs the business action more than once. Idempotency is particularly important for payments, order creation, bookings, and other non-repeatable operations. A key may be ignored, stored for too short a period, scoped incorrectly, or reused with a different payload without detection.

Example

The client sends POST /payments with Idempotency-Key: pay-789. The server creates the payment but the response is lost. The retry creates a second charge because the server did not persist the key with the operation result.

How to test

  • Repeat identical requests sequentially and concurrently with the same key.
  • Retry after simulated response loss and after server commit.
  • Reuse a key with a different payload and test key expiration and scope.
  • Verify the same logical result is returned without repeating side effects.

Expected behavior

The API documents key scope and retention, prevents duplicate effects within that policy, and rejects or clearly handles conflicting reuse.

Runnable examples

Each example includes a broken server, a fixed server, an OpenAPI spec, and a clrsig scenario that detects the failure.