1. The problem
In one sentence
The same write is sent twice (a retry, a double click), and the server does it twice.
A story
A client submits a payment for order-42. The network is slow. The client does not get an answer, so it sends the same request again, which is what a good client does. The server had received both. It charges the card twice. Or: a client registers alice@example.com, and a second request with the same email answers 201 Created instead of 409 Conflict, so there are now two Alices.
Why it hurts
Retries are normal. Networks fail, timeouts fire, users click twice, queues redeliver. A write that is not safe to repeat turns every retry into a possible duplicate charge, order or account.
- For developers: a write needs either an idempotency key (a unique value the client sends, which the server remembers) or a natural unique constraint (the email). Without one of them, the server cannot tell a retry from a new request.
- For managers: a double charge is a direct cost to customers and a refund and support cost to you. A duplicate account or order creates reconciliation work that never ends.
- For DevOps: retries come from clients, proxies and queues. Run a “send it twice” scenario against every write that matters.
Example
In the sandbox, a write that carries a key order-42 and is sent twice:
POST /idempotent Idempotency-Key: order-42 -> 201
POST /idempotent Idempotency-Key: order-42 -> 201 (the same key: the server should recognise it)
GET /idempotent/records -> total: 2 (should be 1)
In the failure-catalog demos, a payment for order-42 sent twice leaves a count of 2 payments, and a user with the same email created twice answers 201 both times.
How to detect it without clrsig
- Send the same write twice with
curl, then read the records. There must be one. - In the database, look for rows that are identical apart from their id and creation time.
How to fix it
There are two usual causes:
- The code is wrong (more likely). Honour the idempotency key: store it with the result, and return the stored result for a repeat. For things with a natural key (email), add a unique constraint and answer
409for a duplicate. - The spec is silent. Say that the operation takes an idempotency key (a header), what happens on a repeat, and which status a duplicate gets.
To tell which: ask what a client should do after a timeout. If the answer is “retry”, the server must make that safe.
Related problems
AC-043 A stale update overwrites a newer one, AC-044 A write times out, yet it was done, AC-039 HTTP method semantics are broken. Failure-catalog demos: FM-018-01 and FM-018-02. See also the site’s Idempotency and Duplicate-Operation Failures.
Words used on this page are explained once in the glossary.
2. How clrsig helps
Check
No built-in check, and the state is not caught. Each response is valid, so a single request cannot show it. A scenario sends the write twice and then reads the records.
Command
First the sandbox scenario. Save it as idempotency-key.yaml. It sends POST requests to the sandbox, so it writes data:
Safety. Run this against a test server, never production.
clrsig conformsendsPOST,PUTandDELETErequests built from the spec: start with--read-only, and take secrets from the environment (${NAME}), never from files in the repository.
schemaVersion: "1"
title: one record for one idempotency key
steps:
- label: reset
request: { method: POST, url: "{{baseUrl}}/__admin/reset" }
assertions:
- { type: status, operator: eq, expected: 204 }
failPolicy: stop
- label: first request with a key
request:
method: POST
url: "{{baseUrl}}/idempotent"
headers: [{ name: Idempotency-Key, value: "order-42" }]
assertions:
- { type: status, operator: eq, expected: 201 }
failPolicy: stop
- label: same key again
request:
method: POST
url: "{{baseUrl}}/idempotent"
headers: [{ name: Idempotency-Key, value: "order-42" }]
assertions:
- { type: status, operator: eq, expected: 201 }
failPolicy: stop
- label: one record for one key
request: { method: GET, url: "{{baseUrl}}/idempotent/records" }
assertions:
- { type: jsonpath, path: "$.total", operator: eq, expected: "1" }
failPolicy: continue
clrsig run idempotency-key.yaml \
--env clrsig/environments/conform-fail.yaml \
--spec specs/conform-fail.yaml
Exit code: 0 all steps pass, 1 a step failed, 2 the scenario or the setup is broken. Here it is 1.
What you see
Output from clrsig v0.21.0, recorded on 2026-11-30:
Scenario: one record for one idempotency key
PASS reset 204 14ms
✓ status eq 204
PASS first request with a key 201 2ms
✓ status eq 201
PASS same key again 201 2ms
✓ status eq 201
FAIL one record for one key 200 1ms
✗ jsonpath $.total eq 1: expected "1"; got "2"
Spec: 1 of 4 responses were not compared with the spec (no matching operation in the spec: 1)
FAILED 3 passed, 1 failed, 0 skipped (3/4 assertions passed) 24ms
How to read it: both writes pass on their own (201). The fault shows only in the last step: two records for one key. The Spec: line says the reset call is not in the spec, which is expected here.
The failure-catalog demo fm-018-02-duplicate-create shows the other kind (a natural key, the email). From its folder:
cd failures/fm-018-02-duplicate-create
go run broken/main.go &
clrsig run scenarios/detect.yaml --env environments/local.yaml
Output from clrsig v0.21.0, recorded on 2026-11-30:
Scenario: fm-018-02 — Duplicate Create Returns 200 Instead of 409
PASS first POST — create user alice@example.com (must succeed with 201) 201 15ms
✓ status eq 201
FAIL second POST — same email must return 409 Conflict, not 201 201 0ms
✗ status eq 409: expected "409"; got "201"
FAILED 1 passed, 1 failed, 0 skipped (1/2 assertions passed) 16ms
And the payment demo fm-018-01-idempotency (a retry that is processed as a second charge):
Output from clrsig v0.21.0, recorded on 2026-11-30:
Scenario: fm-018-01 — Idempotency and Duplicate-Operation Failures
PASS submit payment for order-42 201 15ms
✓ status eq 201
PASS retry: same payment for order-42 (simulates network retry) 201 0ms
✓ jsonpath $.order_id eq order-42
FAIL only one payment must exist — count of 2 means the retry was processed as a duplicate charge 200 0ms
✗ jsonpath $.count eq 1: expected "1"; got "2"
FAILED 2 passed, 1 failed, 0 skipped (2/3 assertions passed) 15ms
Where to look
- Desktop app: open the scenario and run it; each step shows its assertion result.
- Reports:
--format jsonandjunitonclrsig run. - GitHub Action: use
command: runwith thescenario,envandspecinputs;specreplaces the scenario’sspecFile. Older releases of the Action ignoredspecwithrun; if you use one, addspecFile: specs/conform-fail.yamlto the scenario instead (the path is relative to the scenario file) (setup and upgrading).
How clrsig helps you fix it
It shows the write that was repeated and the count that proves it. It does not know how your server stores keys.
Limits
- Only the writes you list are sent twice.
- Two requests sent at the same moment (a race) are not reproduced by steps that run one after another.
More ways
Nothing yet.
3. Video brief for Google NotebookLM
VIDEO BRIEF — AC-042 · A repeated write creates duplicates
Length: 5 to 7 minutes. Language: English. Audience: developers, with a line each for managers and DevOps.
One idea: retries are normal, so every write that matters must be safe to repeat.
Open with this story: A client submits a payment for an order. The network is slow and the client gets no answer, so it sends the same request again, as a good client should. The server had received both. It charges the card twice. In another system, a second registration with the same email answers 201 Created instead of 409 Conflict, so there are now two accounts.
Say these facts, in this order:
1. Sandbox scenario: the same request with the same idempotency key is sent twice. Both answer 201, and the records count is 2 instead of 1.
2. Each single response is valid; the fault shows only when you read the records.
3. Demo two: the same email created twice answers 201 both times; it must be 409.
4. Demo three: a payment retry is processed as a second charge; the count is 2, it must be 1.
5. A write needs an idempotency key that the server remembers, or a natural unique constraint such as the email.
6. Two usual causes: the code is wrong (honour the key; add a unique constraint and answer 409), or the spec is silent about keys and about what a repeat does.
7. For managers: a double charge is a direct cost to customers plus refunds and support.
8. For DevOps: retries come from clients, proxies and queues; run a send-it-twice scenario against every write that matters.
Show on screen: the three example lines, the scenario YAML, the commands, and the three output blocks, copied exactly from the card.
Name the check: none built in; found by a scenario that sends the write twice and reads the records. Say the clrsig version: v0.21.0.
Explain these words once: idempotent (doing it twice has the same effect as doing it once); idempotency key (a unique value the client sends so the server can recognise a repeat); retry (sending the same request again); 409 (a conflict with the current state); exit code (0 clean, 1 a finding, 2 setup or spec broken).
Say what clrsig does not see here: only the writes you list are sent twice; two requests sent at the same moment are not reproduced.
Safety line (if a write is shown): Run this against a test server, never production. clrsig conform sends POST, PUT and DELETE requests built from the spec: start with --read-only, and take secrets from the environment (${NAME}), never from files in the repository.
Finish with three recap questions:
1. Why are retries normal? (Networks fail, timeouts fire, users click twice.)
2. Name two ways to make a write safe to repeat. (An idempotency key, or a unique constraint.)
3. Which status should a duplicate create answer? (409.)
Tease the next video: AC-043 · A stale update overwrites a newer one.
Do not: say "contract testing" alone; say clrsig "catches everything"; invent flags, IDs or numbers; read tables aloud; use any fact that is not in the card.