{
  "id": 6555026,
  "title": "What Happens When an AI Agent Runs Longer Than Your HTTP Request?",
  "url": "https://urgent.news/2026/09/10/what-happens-when-an-ai-agent-runs-longer-than-your-http-request",
  "topic": "ai",
  "section": "AI",
  "published": "2026-09-10T07:08:55.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/hosseinhezami/what-happens-when-an-ai-agent-runs-longer-than-your-http-request-288o"
  },
  "original_language": "en",
  "account": "When an AI agent run exceeds the duration of an HTTP request, problems arise. Here's the issue broken down:\n\n1. The Gateway Times Out, but the Agent Keeps Spending Tokens\n- An HTTP request has a timeout set by gateways, load balancers, or clients\n- An AI agent run can continue long after the request times out\n- The request returns a 504 Gateway Timeout error to the user\n- The agent might still be executing, using tokens, calling tools, and generating results\n- The user sees the error, but the agent may have already completed work\n\n2. The Client Retries, and Now You Have Two Agents\n- Users may click \"Run\" again if they don't see a response\n- Automatic retries can happen after network issues\n- Two separate agent runs will occur for the same user request\n- Agents are not pure functions; they may have side effects and tool calls\n- Running the same agent twice may lead to duplicate work and inconsistent results\n\nKey points to address these issues:\n- Create a durable \"run resource\" with a unique run ID\n- Return a 202 Accepted status immediately instead of waiting for completion\n- Execute the agent asynchronously in the background\n- Store agent state in a durable system, not just process memory\n- Use idempotency keys to prevent duplicate runs when retried\n- Handle cancellation explicitly and cooperatively\n- Prefer durable execution patterns for long-running workflows\n- Use progress notifications (SSE/WebSockets) to keep the user informed\n\nConsider these points before implementing long-running AI agents in your system. The mismatch between the HTTP request lifecycle and AI agent runs requires a different architectural approach to ensure reliable execution and avoid duplicate work.",
  "summary": "A user clicks “Run agent” , your backend receives a normal HTTP request, and the agent starts doing what agents do: calling tools, reading documents, querying APIs, waiting for a human approval, retrying a flaky search, and generating a long report. Two minutes later, your load balancer returns 504 Gateway Timeout . The user sees an error. The agent, depending on where it is running, may still be…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}