BlogIntegrations

Integrations

Making AI Actions Safe to Retry

An AI request may be repeated after a timeout or duplicate event. Design idempotent actions so retries do not create duplicate records or repeat external work.

When an AI assistant changes another system, a network failure can leave the application unsure whether the action succeeded. Repeating the request may create a duplicate. Idempotency gives a logical operation a stable identity so retries can reuse or reconcile its result. Stripe documents one concrete implementation using idempotency keys; your own workflow needs a policy suited to its action and storage model.

Separate intent from execution attempts

Create an operation identifier when the user or workflow authorizes an action. Carry it through tool calls, queue messages, and retries. Store the normalized action parameters with the operation record so the same identifier cannot silently refer to a different request.

Choose the scope deliberately. Two intentional tasks with identical titles may be separate operations, while two network attempts to create the same authorized task are not. A hash of the prompt alone rarely captures this distinction. Preserve the relationship between the user’s intent, the exact target, and the resulting external record.

Resolve the uncertain outcome

Imagine a hypothetical project assistant creating a ticket. The external service accepts it, but the response is lost. On retry, the integration should use the same supported idempotency key or consult its operation record and the remote system. Generating a new key for every attempt defeats the purpose.

If the provider offers no idempotency facility, design reconciliation using durable references or a controlled lookup when feasible. Be honest about the limits: a local database lock alone cannot guarantee that an external action happened exactly once across every failure window. Decide how ambiguous operations are surfaced for review rather than blindly repeated.

Test the failure windows

Test a duplicate queue message, simultaneous retries, a process crash after the external action, and a response timeout before local persistence. Verify both the resulting external state and the status the user sees. A test that only asserts the HTTP response misses the essential risk.

Define retention for operation records and know the provider’s key lifetime where relevant. Reject reuse with conflicting parameters. Keep retry counts, reconciliation attempts, and final external identifiers observable. For multi-step actions, assign identities at the appropriate stage and record partial completion so a retry does not repeat successful earlier effects.

Sources & further reading