A workflow can fail after an external system has accepted an action but before the caller receives confirmation. Retrying the whole task may then send a second message or create a duplicate record. AI adds more stages, but it does not change this basic distributed-systems problem. Design retries around observable outcomes and stable operation identities, with special care at the points where the workflow changes external state.
Classify failures before retrying
Distinguish temporary service problems from invalid input, missing permission and unresolved business questions. A timeout may justify another attempt; a rejected identifier usually needs correction. Repeating a model call because the source information is missing will not reliably produce a better-supported answer. Make the retry decision depend on the failure category and the operation's consequences.
Use bounded attempts and increasing delays for appropriate transient errors. AWS Step Functions documents retry and catch mechanisms that support this pattern. Set an overall time budget as well as a count, so a task cannot remain active indefinitely. After the budget is exhausted, route it to a visible state with enough context for recovery.
Give consequential operations stable identities
Create an operation identifier before performing a write and reuse it when the same intended action is retried. Where the destination supports idempotency keys, use its documented mechanism. Where it does not, design an application-level record of intent and completion that can prevent obvious duplicates. The exact strategy depends on the destination's guarantees and available queries.
Keep the operation identity tied to the intended payload. A materially changed request should not accidentally reuse a key associated with an earlier action. Conversely, a network retry of the same action should not receive a new identity. Document this distinction because it is easy for generic retry wrappers to create a fresh request each time.
Treat unknown outcomes explicitly
If a write times out, determine whether the destination accepted it before issuing another. Query by a known operation or record identifier when possible. If the state cannot be established, mark the outcome as uncertain and escalate according to the task's consequences. Calling it failed merely because the response was missing can be dangerously misleading.
Separate preparation from execution. It may be safe to regenerate a draft, but not safe to resend a previously approved message. Store the concrete approved payload and execution state. This also prevents a retry from generating different content under an earlier approval, which would turn a technical recovery into an unreviewed business change.
Test recovery paths deliberately
Simulate failure before a request, during the call and after the destination accepts it. Verify that the workflow reaches the correct state in each case. Include worker restarts and duplicate input events, because real systems can deliver the same work more than once. Test the full business result rather than only whether the retry function eventually returns.
Monitor repeated attempts, uncertain outcomes and duplicate prevention events after launch. A sudden increase may indicate a service problem or a design mismatch. Keep recovery instructions concise and connected to the audit trail. Reliable automation does not depend on every call succeeding; it depends on knowing what happened and continuing without creating unintended additional actions.
The key decisions.
- Retry only failure types that another attempt can resolve.
- Reuse stable operation identities for the same intended write.
- Investigate uncertain outcomes before repeating consequential actions.
Sources & further reading
Primary references for the concepts discussed. Check the applicable documentation when planning implementation.







