keepcalculator

06 Numbers and Powers

AI Agent Timeouts: Verify What Actually Happened

Card No. 06·30100 · Updated · Standard formula, shown below

When an AI agent (a script, bot, or automated workflow) times out, you need to determine whether it completed its task, partially completed it, or did nothing at all. This article explains how to verify the actual outcome by checking logs, side effects, and system state, and how to prevent ambiguity in future runs.

Why Timeouts Are Ambiguous

A timeout means the agent exceeded its allotted execution time and was terminated. But termination is not the same as failure. The agent may have:

  • Finished the task just before the timeout, but the response was lost.
  • Completed part of the work (e.g., sent an email, wrote a file) and then stalled.
  • Done nothing because it was waiting on an external call.

You cannot infer which case occurred from the timeout message alone. You must inspect evidence left behind.

Step 1: Check Application Logs

Most AI agents log their actions. Look for the last log entry before the timeout. Typical entries include:

  • INFO: Calling API endpoint /orders
  • INFO: Received response 200 OK
  • ERROR: Retry 3/5 failed

If the last entry is an outgoing call with no matching response, the agent likely hung waiting for a response. If the last entry says “Task completed� but the process still timed out, the work was done and only the shutdown was slow.

Step 2: Inspect Side Effects

Logs can be incomplete. Check the actual systems the agent was supposed to modify:

  • Files: Does the output file exist? Check its modification time and content.
  • Databases: Run a query to see if rows were inserted or updated.
  • APIs: Did the downstream service receive a request? Many APIs have audit trails.
  • Email: Check the sent folder or the recipient’s inbox.

For example, if your agent was supposed to generate a PDF and upload it, verify the PDF exists and the upload endpoint shows a successful PUT. A partial write (file exists but is truncated) indicates the agent was interrupted mid-task.

Step 3: Check Process Exit Code and Signals

When a process times out, it is usually killed with a signal. In Unix-like systems, SIGTERM (exit code 143) means a graceful termination request; SIGKILL (exit code 137) means forced termination. If your agent handles SIGTERM, it may have run cleanup code that logged a final status. For example:

trap 'echo "cleanup done" >> agent.log; exit 0' TERM

If the exit code is 137, no cleanup happened, so the last state is whatever was written before the kill.

Step 4: Replay or Re-run in Debug Mode

If you cannot determine what happened, re-run the agent with verbose logging and a shorter timeout. This often reveals where it gets stuck. Common culprits include:

  • Waiting for a network call that never returns (no timeout on the HTTP client).
  • An infinite loop due to a malformed input.
  • Deadlock when multiple agents share a resource.

Set a timeout on every external call (e.g., 10 seconds) so the agent fails fast instead of hanging indefinitely.

Step 5: Use Idempotency Keys

The best way to verify is to design the agent to be idempotent. That means each task has a unique key, and the agent records progress (e.g., “step 3 of 5 completed�) in a persistent store. After a timeout, you can query the store to see exactly how far it got. Many API clients support idempotency keys; use them so re-running the agent does not duplicate side effects.

Common Pitfalls and Misconceptions

  • Misconception: A timeout always means the agent failed. Reality: It may have completed the task and only the final status message was lost.
  • Pitfall: Relying on logs that are buffered. If the process is killed, buffered logs may not be flushed. Force flush after every log write.
  • Pitfall: Checking only the exit code. The exit code tells you how it ended, not what it did.

Frequently Asked Questions

What if the agent writes to a database but the transaction wasn’t committed?

If the agent was killed before commit, the database will not show the change. Check the database’s transaction log or the agent’s own record of “commit� events. If the agent logs “committed� but the data is missing, the commit may have failed silently.

How can I distinguish between a network hang and a slow computation?

Look at CPU usage during the run. If CPU is near 100%, it is likely computing. If CPU is near 0% and the process is still alive, it is probably waiting for I/O or a network response. Add per-request timing logs to confirm.

Should I always re-run the agent after a timeout?

Only if the agent is idempotent. Otherwise, re-running could duplicate side effects (e.g., sending two emails). First verify what happened; if you cannot, design the agent to be idempotent before re-running.

What is the best way to log progress for later verification?

Write a structured log (JSON lines) to a file or a database, with a timestamp and a step name. Include a unique run ID so you can filter logs for that specific execution.

Can I use a timeout as a signal to retry automatically?

Yes, but only if you have verified that the previous run had no side effects, or if the operation is idempotent. Otherwise, you risk duplicate actions. A safer pattern is to mark the run as “unknown� and have a human or a separate process inspect it.

Why does my agent time out even though the task is simple?

Often because an external dependency is slow or unresponsive. For example, a third-party API might take 30 seconds to respond, and your timeout is 20 seconds. Increase the timeout, or better, set a per-call timeout and retry with backoff.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →