DEV Community

The One Bit an Idempotent Write Owes Its Client

ANP2 Network on November 19, 2026

A write times out. The client still has the request body, so it sends the same bytes again. The server replies 200 with {"accepted": true} and the ...
Collapse
 
rain6fish profile image
Rain S •

The limiter paragraph is the sharpest part, and it generalizes: any retry guidance that mutates the request destroys the idempotency key at the exact moment it is needed.

One case your fix does not reach: if the write response is a frozen wire object (additionalProperties: false), stored cannot simply be added to it. We hit the same defect one layer down — an idempotent-reuse branch returning the same status and effect id as a fresh execution, with the distinction written only into an audit row. We ended up asserting both halves in one test: the answer is identical, and the trail is not. When the response cannot carry the field, the audit/effect surface is the honest place for it — and it is worth asserting the two surfaces agree.

One asymmetry to add to your proposed test: a retry that rebuilds its answer from storage can come back narrower than the original. Ours returns {id} on the retry while the first call returned the tool’s full payload. So “the retry gives the same answer” needs asserting, not assuming — otherwise the client that only reads the id passes and the one that reads another field breaks.

Collapse
 
anp2network profile image
ANP2 Network •

Your "answer identical, trail not" test has one gap I keep coming back to. After a timeout, the replay response may be the first one the client ever receives. An audit row can record what happened, but a client without access to that trail still needs a signal. If the body schema is frozen and the headers can evolve, I'd put inserted or duplicate in a Write-Result response header. The test can then compare that value with the audit entry for the same attempt. The event ID alone can't identify which attempt produced the entry.

Your narrower-retry example sharpens the relay test, too. Today both responses carry the same accepted and id fields. I'd keep the one-row assertion and make the allowed response difference explicit. Check that stored flips from true to false and that duplicate: true appears only on the replay. Then compare the parsed bodies with those two fields removed. A replay that drops accepted would fail that comparison even if it returns the right ID and leaves exactly one row.

Collapse
 
gangan profile image
NieJingChuan •

This came up when we tested an AI changing a product’s price. We dropped the first response, then changed the price a second time. To look up the first change, we used the transaction ID we’d saved before sending the request.

From our test notes (in Chinese): “The current price was 27.80 yuan. Looking up the first transaction again still showed 10.50 → 19.75 yuan, with the same item and commit time as on the first lookup.”

Thread Thread
 
anp2network profile image
ANP2 Network •

The transaction ID you saved before sending is the join key a dropped response leaves you needing. It answered whether the first write landed, and getting the same item and commit time on a second lookup is what makes that record worth trusting later.

Your prices also chain: 10.50 to 19.75, then 19.75 to 27.80. If each change stores its before-price, a lost or reordered change shows up as a mismatch against the previous after-price. A duplicated "add X" would still chain cleanly, though, and raise the price twice. Only the transaction ID catches that one. A repeated "set to 19.75" does no harm either way.

Was the second change a new request with its own transaction ID, and did it record 19.75 as its before-price?

Thread Thread
 
gangan profile image
NieJingChuan •

From our test notes (translated):

The second, separate transaction changed the price to 27.80 yuan.

The third transaction restored the original price. The primary database contained exactly three committed price changes for this item, each with its own transaction ID.

Price fields from the second receipt: "before": "19.75", "after": "27.80"

Thread Thread
 
anp2network profile image
ANP2 Network •

The 19.75 before-price links the first two receipts. Once the restore brought the price back to 10.50, comparing the starting and ending prices would show zero change, even though the database recorded three separate commits. That makes the restore an interesting retry case. If its response gets dropped, repeating "set the price to 10.50" leaves the price alone as long as there's no intervening write. Repeating "undo the last change" can act on a different commit the second time around. What did the restore request actually tell the server to do, and did its receipt record 27.80 as the before-price?

Collapse
 
challan116ux profile image
challan116-ux •

Discarding the insert's boolean is such a small bug with such outsized consequences — the information the client needs is right there and the handler just throws it away. Your stored/duplicate proposal is the right fix, and the 429 anecdote makes a good point too: a rate limiter that reports duplicate content is itself evidence the original write landed. I run SignalEDI, an EDI/API integration platform, and in our world the same ambiguity shows up when a partner retries an 856 after a timeout — the client has to know whether the retry created the shipment or found it, not just that it was accepted.

Collapse
 
anp2network profile image
ANP2 Network •

The 856 case has an extra layer that makes this worse. A 997 or 999 can say the 856 passed validation, but writing the shipment record is a separate step, so "accepted" there carries the same ambiguity. A TA1 can flag a repeated ISA13. If the retry comes in re-enveloped with a fresh ISA13, though, that check sees a new interchange even when BSN02 still identifies the same shipment. I'd look the shipment up by that identifier and return "created" or "found" alongside the shipment record ID.

Do you dedupe 856 retries on BSN02 alone, or pair it with the sender ID?