Agent ArchitectureRuntime and effect recoveryPrincipal
How should an agent recover when a retry reuses an idempotency key with changed parameters?
By Amit Kumar2 min readWorked answer includedReviewed 28 Sept 2026
The question
Interview question
A 40-dollar refund times out. On resume, the agent changes the intended total refund to 45 dollars but reuses the key, and the provider rejects it. Explain operation identity and parameter binding, reconcile the first outcome, and decide whether a separately approved adjustment is needed before submitting anything new.
Draft your approach first
Take a few minutes before you read the answer. Name the constraint that matters most, the failure you are designing for and how you would know it worked.
Reveal the worked answerWorked answer
The key is meant to identify one logical operation, not one conversation or one customer. Suppose the agent attempted a $40 refund, the connection failed before it received the response, and it resumed later. Its new reasoning changes the requested refund to $45 but reuses the original key. Many payment APIs reject a key reused with different request parameters. Stripe's idempotency documentation describes parameter comparison, and its error reference identifies an idempotency error for a changed endpoint or parameter set. Provider behavior and retention windows need to be checked for the actual tool.
Do not respond by minting a fresh key and immediately sending $45. The $40 operation might already have committed. The right first question is what happened to the original operation. Persist an action record before sending, containing the target resource, amount and units, provider, key, request-body fingerprint, approval version and state. On resume, retry the same request with the same key only if it is still the same operation and within the provider's supported key window. Otherwise reconcile against provider state and events before proposing a new action.
For a hypothetical desired total refund of $45, confirmation that the original $40 succeeded would leave a $5 adjustment to propose. If the first result is still unknown, that arithmetic does not authorize another submission. Check currency, prior adjustments and the business meaning of the requested total before creating the new action.
If a further adjustment is genuinely needed, make that adjustment a new proposed operation with a new approval and key. Check whether the prior $40 succeeded and calculate the desired remaining adjustment, rather than treating a changed amount as a harmless retry. The exact compensation depends on the provider and business contract. A duplicate-resistant API call cannot decide whether two distinct refunds were intended.
The interviewer might say the agent's summary says the first attempt failed. A network error proves the response was lost, not that the provider failed to execute. The refund succeeded but the agent crashed. What happens next? covers ambiguous commit recovery. This question focuses on a subtler misuse: one key attached to two different payloads. Test that an agent restart cannot silently change the original action record and that a provider mismatch error stops execution instead of triggering a new key automatically.
Stripe’s advanced error handling independently documents the parameter-mismatch error and the need to reconcile an unknown original outcome before starting a different operation. Apply the actual endpoint’s retry window rather than assuming a key remains valid indefinitely.
Related questions
Keep practising agent architecture
Follow another question in this area, or search the complete library.
Get my essays on AI engineering and distributed systems by email. Subscribe to ArchCrux