Agent ArchitectureRuntime and effect recoveryStaff
When should an agent retry an operation, compensate a confirmed effect or stop for reconciliation?
By Amit Kumar3 min readWorked answer includedReviewed 26 Sept 2026
The question
Interview question
Compare recovery after a pure read, an email submission and a payment. Responses may be lost after provider acceptance, and a later compensating refund may fail or time out. Define safe retry conditions and operation identities, explain what compensation cannot undo, and state how unresolved original and compensating effects appear to the user.
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
I would start with the actual effect, not the workflow engine's label for the step. A retry repeats an attempt to complete the same logical operation. Compensation is a new operation meant to mitigate a confirmed earlier effect. It does not run time backward. Both can fail.
A genuinely side-effect-free read is usually safe to repeat. But the answer it returns may change. If the subsequent decision requires a consistent snapshot, carry a version or transaction boundary, or check the source again before writing. A read of a rate-limited paid API also has cost and may require a retry budget, even if it is safe in the business sense. “Read” describes intent, not necessarily a pure implementation.
An email is externally observable and generally cannot be unsent. If the send call times out, don't assume nobody received it and send again with a new ID. Use a provider-supported deduplication or submission status contract if available, with a stable message operation ID. If none exists, reconcile from the provider's records or mark delivery uncertain. A follow-up correction email is a new effect, not compensation that erases the first. If the email contained sensitive information, an apology cannot undo disclosure. This is why high-impact content needs checks before send.
A payment may be safe to retry under a documented idempotency contract that covers the same amount, recipient, and operation identity during its retention window. It is not safe merely because the HTTP method or workflow activity is retried. If a payment was confirmed and the business wants to reverse it, use the provider's actual refund or void operation, with a separate authorization and ledger entry. A refund can settle later, incur fees, or fail. It does not make the original charge never exist. Temporal's Activity documentation emphasizes idempotence because activity execution can be retried. Stripe's API v1 idempotency contract illustrates why key retention and saved first responses need attention.
I would write the state machine around evidence of effects: not_submitted, submitted_unknown, confirmed, compensation_requested, compensated, compensation_failed, and a path for manual resolution. Names can vary, but the unknown and failed-compensation states cannot collapse into “rolled back.” Each attempted payment and refund needs its own stable identity and provider receipt. The user's final view should say whether they were charged, whether a reversal is pending or failed, and what will happen next.
For a hypothetical confirmed charge of 40 USD, a requested 40 USD refund is another operation with another outcome. If the refund response is lost, its state is compensation-outcome-unknown, rather than confirmed failure or completed reversal. Retrying that refund safely requires its own provider contract and stable refund identity. A new refund ID could return money twice if the first request later completes.
If the provider explicitly rejects the refund, record that known failure and the remaining charged balance. If it merely accepts the refund for asynchronous processing, retain a pending state until the provider confirms settlement or rejection under its contract. The original charge remains a historical fact in either case. A workflow’s compensation step finishing locally does not establish that the customer received the reversal.
The interviewer then makes compensation fail. Retry it only if its own contract makes that safe, possibly after backoff or a transient fault. Otherwise hold the case for reconciliation or an operator. Do not trigger a new charge to “restore” symmetry or mark the saga complete just because a compensating activity ran. Microsoft's saga pattern describes compensating transactions as a coordination approach, but the business has to decide whether the remaining state is tolerable and who owns it.
One more push is an email sent after the payment but before the refund fails. The customer now has an incorrect receipt. The workflow should send a carefully authorized status correction only after it knows what it can truthfully say. This is why I order irreversible communication after confirmation when the product allows it. The design goal is honest, recoverable outcomes, not a neat green chain of steps.
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