AI Agent Failure Recovery After a Tool Call Times Out

Updated
8 min read
A timed-out request reconnects to the same ticket in an AI agent failure recovery diagram.
TL;DR

A timed-out write may already have worked. Learn how to check the receiving system, retry with the same operation key, and test that your agent never creates a second ticket.

An agent asks a support system to open a ticket. The request times out. The support system might already have created the ticket and lost the reply. If the agent tries again with a fresh request, someone may end up with two tickets for the same incident.

AI agent failure recovery starts by giving that timeout its own state: outcome unknown. The worker has something to investigate, and the user can see that confirmation is pending. This guide uses a support ticket to show how to recover a single write. The wider design is covered in our guide to durable state for production agents.

Write down the intended action first

When the application accepts a request to open a ticket, assign it an operation ID. Store the ID, relevant request parameters, and a pending state before making the external call. The ID should represent this one authorised ticket, independent of the agent session or retry count. A second, distinct ticket should get its own ID even if it has the same subject.

If the support API accepts an idempotency key, map the operation ID to that key. A retry must reuse it with the original parameters. Check the provider’s rules for key scope, expiry, and the response to repeated requests. Stripe’s idempotent requests documentation is a concrete example of how a service can define that contract. Apply your own provider’s rules to its endpoint.

On success, store the external ticket ID and mark the operation confirmed. If the worker dies between those two steps, you still have the original ID and can recover the result. AWS’s guide to idempotency and retries explains why the same concern applies when an execution engine replays a step.

Decide what the worker should do after a timeout

The decision belongs in the tool wrapper or workflow runner. Feed the model the verified result or the pending state after the runner has worked out what happened.

Click any column to sort
4 rows
A read timed out and the dependency is likely to recoverRetry within the time budget. Use backoff so many workers do not hit the service together.
The write timed out and the destination has a documented replay contractReuse the same key and parameters within the permitted window, then save the confirmed ticket ID.
The write timed out and the destination supports lookup by operation IDLook up the existing request. Save the confirmed result, or follow the provider’s rules for items that may still be in flight.
The write timed out and the outcome remains ambiguousKeep the operation pending and route it to a person or a reconciliation queue.

A lookup that returns zero records can be misleading when search is eventually consistent. Give the receiving service time to finish and use its documented status endpoint if it has one. For other calls, set retry limits in one layer. The Amazon Builders’ Library article on timeouts and backoff explains how stacked retries can amplify trouble in a slow dependency.

Test the response that never arrives

In a test environment, have the fake support service create the ticket and then drop the response. Restart the worker before it can record a result. Run recovery and check the receiving system directly. You want one ticket, one confirmed operation in your own store, and the same ticket ID in both. Checking only the worker’s final message can miss a duplicate.

Run the test again with the service timing out before it creates a ticket. Test a slow confirmation and a provider that cannot tell you the outcome. For the ambiguous case, assert that the worker stops with the state pending. This is a good candidate for the same regression-first workflow used in our Codex pull request checklist.

Log the operation ID, tool name, attempt count, and verified outcome so a reviewer can trace a real incident. Keep customer text and raw credentials out of logs. Track unresolved operations and their age alongside timeouts. Our production AI agent guide covers the broader monitoring setup.

Put recovery on both sides of the tool boundary

The component that calls the support API needs somewhere to store the operation before sending it. The component that receives the write needs a way to relate a repeated request to the original action. Those two records serve different purposes. Your operation row says a worker attempted an authorized task. The external record says the destination actually created a ticket.

Write down which system is authoritative for each question. For the sample workflow, the application is authoritative about who asked to open a ticket and why. The support platform is authoritative about whether a ticket now exists. A model’s summary can carry that result back to the user once the workflow has the ticket ID. When the systems disagree, inspect their records before changing the agent prompt.

A small operation ledger might contain an operation ID, an input reference, a destination, state, timestamps and the confirmed external ID if one exists. A worker can then distinguish three operations that often get lumped together:

  • Confirmed sends can return the stored result.
  • Pending sends with a trustworthy lookup can be checked before sending again.
  • Pending sends with no available evidence can be left for a person or a scheduled reconciliation job.

Protect the operation ledger against concurrent claims. If the queue delivers one message to two workers, only one should acquire the operation at a time. The receiving service’s idempotency contract still matters because a worker can lose its claim or crash while the remote request is in flight.

Make a sensible choice when the provider cannot tell you

Suppose your support platform cannot look up a request by operation ID. It can search tickets by subject, but subject lines repeat and new tickets can take time to appear. Searching for the subject is still useful to the team doing reconciliation. It gives them a starting point. It is weak evidence for an automatic retry because two incidents can have the same subject.

In that situation, send a short acknowledgement to the user that accurately describes the state. A message such as “The ticket service hasn’t confirmed the request yet” gives them enough information to wait or follow the ordinary support process. A worker should avoid reporting a ticket number until it has received or recovered it from the destination. The team handling unresolved operations should see the expected action, when it was attempted, and the safest route to check.

Decide which cases are worth putting into that queue. If a write produces a new record that another system relies on, record enough evidence to investigate it. If the external operation is a periodic refresh and a later run can safely produce the same result, give it a bounded retry policy. It is reasonable to have different behavior for different operations even when both tools return the same HTTP status.

Run the failure test with two workers

A single-worker test is a good place to begin. Then run another with concurrent delivery. Start two workers with the same operation ID and have the receiving service pause between accepting the first request and returning its response. Let the first worker lose its confirmation. See whether the second one can recover the original ticket without creating another.

A useful test matrix records where the failure happened and what you expect to observe:

Click any column to sort
4 rows
Reject the request before any writeZero until a permitted retry succeedsPending, then confirmed if the provider accepts it
Commit the write and drop the replyExactly oneRecover and confirm the original external ID
Replay the same work message during an in-flight writeAt most one following the provider’s contractThe other worker waits, reconciles, or uses the stored result
Lose lookup access after an ambiguous responseResolve after restoring the evidence sourceKeep a pending record visible to operators

Keep the simulated floor of these tests low. A fake service that logs each attempted write to an array can test the behavior of your worker. When you need to prove your assumptions about a real provider, run a small integration test against an approved test account and inspect the result directly. The two tests catch different mistakes.

Give unresolved operations an owner

Imagine opening the on-call dashboard after a provider outage. “Tool failed 30 times” tells you roughly how widespread the problem was. “Six writes are still unconfirmed, the oldest has been pending for 24 minutes, and here are their operation IDs” tells you where to start. Record the state transition whenever a worker resolves an uncertain result, including whether the resolution came from a provider lookup or manual review.

Decide when an unresolved operation becomes worth somebody’s attention. Track the number of confirmed duplicate writes separately from repeated request attempts. A repeat that correctly returns the same external record can be normal recovery. A repeat that creates a second record is the problem this design is meant to catch.

One practical place to roll this out is the support flow used throughout the article. Preserve the normal path first. Then introduce the pending state, add the fake-service failure test, and rehearse what somebody sees after the first timeout. If the user, the worker and the operator can all tell what is known, you have made the failure easier to handle even before you expand the automation.

Start with the write your team would least like to clean up twice. Force it to succeed once with no reply, then make recovery prove it stayed that way.

Frequently Asked Questions

Should an AI agent retry a tool call that timed out?

Retry a read under a small budget when the error is transient. For a write, check the receiving system or use the provider’s documented idempotency contract before repeating the operation.

What should an agent store before calling a tool that changes data?

Store a stable operation ID, the parameters or a reference to them, and the pending state. Add the receiving system’s record ID when you can confirm the operation.

How do I test for duplicate agent actions?

Have a fake service commit a write and then drop the response. Restart the worker, recover the operation, and assert that exactly one external record exists and the workflow points to it.

#ai-agents#reliability#idempotency#tool-calling#testing

One AI engineering post, weekly

LLM benchmarks, prompt techniques, and token-cost breakdowns, delivered to your inbox.

What should we test or explain next?

Comments

Have a question or something to add? Sign in to join the discussion.

Mahmudul Haque Qudrati — CEO & ML Engineer at Pristren

Mahmudul Haque Qudrati

CEO & ML Engineer

Software architect, full-stack engineer, and machine learning practitioner. Founder & CEO of Pristren, CTO at Venture Kick-backed PIN Sport Application GmbH (Basel, Switzerland), Software Development Lead at DailyFrame GmbH (building Dimetra patient transport software), and creator of Zlyqor. Focused on custom workflow automation, scalable web and mobile applications, and production AI/ML systems.