Four Idempotency Anti-Patterns in Agent Tool Calls

2026-12-03来源 dev.toEnglish

A useful review question for an idempotency design is “which counterexample would break it?” Use a stub that appends an expense to a list and can withhold its receipt. Give each fixture its own durable operation store and record the downstream call count alongside the expense count.

Four counterexamples

1. An identifier minted per HTTP attempt. Submit expense A, withhold the first reply and resume the same operation. The attempt identifiers may differ. The logical operation identifier must remain A. If the provider offers documented deduplication within a retention window, a permitted retry carries A and the same effect-bearing parameters. Otherwise leave the result pending reconciliation.

2. Identical fields treated as one intent forever. Submit two separately authorized expenses with identical amounts and descriptions. Give them distinct operation identifiers. Two created expenses is the correct outcome. Deduplicating by body hash alone would discard the second.

3. Reusing one identifier with changed parameters. Submit A again with another payee. Reject the conflict before it reaches the tool and retain the original receipt. A hash can help compare parameters if its normalization rules preserve the fields that define the effect.

4. Treating a claim as a completed write. Pause one worker immediately after it wins an atomic insert. A second worker should report “in progress” and make zero additional calls. Resume the winner and record the actual result. If the winner disappears after dispatch, a new worker cannot infer the outcome from the expired lease.

Keep all four assertions. Checking only for duplicate writes can reward a handler that never dispatches anything. Checking only the happy-path receipt misses lost replies, and checking only a timestamp says nothing about which expense the provider actually recorded.

HTTP semantics, §9.2.2 · Stripe API idempotency

Test that the stub distinguishes dispatch from effect

For each of the four cases record the distinct operation IDs, downstream call count and created expense IDs. An uninterrupted first submission should produce one call and one effect. A lost reply with supported provider deduplication can produce two calls yet one effect. A second authorized expense should add a distinct expense. These assertions catch both an over-eager resender and a handler that never dispatches.

This article was created with AI assistance.

原文:https://www.a8q9.cn/en/article/four-idempotency-anti-patterns-in-agent-tool-calls-4a7352.html

相关文章