{"slug": "i-injected-a-502-after-db-commit-into-langgraph-openai-agents-sdk-and-crewai-s", "title": "I Injected a 502 After DB Commit Into LangGraph, OpenAI Agents SDK, and CrewAI — Here's What Broke", "summary": "A developer built agent-fault-check (afc), an open-source Apache-2.0 Go fault-injection proxy and CI runner, and tested LangGraph 1.2.24, OpenAI Agents SDK 0.26.0 and CrewAI 1.6.1 against injected HTTP faults. LangGraph and the OpenAI Agents SDK both retried after a 502 returned post-commit or a truncated 201, silently writing a duplicate order row, while CrewAI avoided the duplicate via a loop guard but refused to retry a recoverable 503, leaving zero orders written. Adding an Idempotency-Key header fixed the duplicate writes across all three frameworks.", "body_md": "Most AI agent benchmarks test prompt accuracy or mock happy-path tool responses.\n\nIn production, the bugs that wake engineers up at 2 AM aren't prompt typos—they're **distributed-systems failures** between your agent and your HTTP tool APIs:\n\n`201 Created`) to PostgreSQL, then a proxy or load balancer drops the response or returns `502 Bad Gateway`` commit_then_fail`).` malformed_json`).` 503 Service Unavailable``fail_before_upstream`).\nTo see how default tool-calling patterns behave under these exact faults, I ran [`agent-fault-check` (`afc`)](https://afc.evhu.net)—an open-source (Apache-2.0) Go fault-injection proxy and CI runner—against **three popular Python agent frameworks**:\n\n`1.2.24` — `create_react_agent` + `@tool`)` 0.26.0` — `Agent` + `@function_tool`)` 1.6.1` — `Crew`)`\"Create a $49.00 order for customer cust_123.\"`\n`POST /api/v1/orders`) through `afc`'s local fault-injection proxy (` TOOL_API_BASE_URL`).` Idempotency-Key` header, duplicate retries returned `200 OK` with the existing order instead of inserting a second row.`mock_llm.py`) that retries failed tool calls—and you can override `OPENAI_BASE_URL` / `OPENAI_API_KEY` to run against a live model.\nFull reproducible code: [examples/benchmarks on GitHub](https://github.com/evhu-dev/agent-fault-check/tree/main/examples/benchmarks)\n\n| Framework (Version) | Mode | `commit_then_fail` (`502` after`201` ) | `malformed_json` (truncated`201` ) | `fail_before_upstream` (`503` ) | \n|---|---|---|---|---|\n| **LangGraph** (`1.2.24` ) | Default | **2 rows (DUPLICATE WRITE)** | **2 rows (DUPLICATE WRITE)** | 1 row ( `PASS` ) | \n| **LangGraph** (`1.2.24` ) | Fixed ( `Idempotency-Key` ) | **1 row (`PASS`, `200` dedup)** | **1 row (`PASS`, `200` dedup)** | **1 row (`PASS`)** | \n| **OpenAI Agents SDK** (`0.26.0` ) | Default | **2 rows (DUPLICATE WRITE)** | **2 rows (DUPLICATE WRITE)** | 1 row ( `PASS` ) | \n| **OpenAI Agents SDK** (`0.26.0` ) | Fixed ( `Idempotency-Key` ) | **1 row (`PASS`, `200` dedup)** | **1 row (`PASS`, `200` dedup)** | **1 row (`PASS`)** | \n| **CrewAI** (`1.6.1` ) | Default | 1 row, **0 retries (`EXIT 1`)** | 1 row, **0 retries** | **0 rows (DROPPED ORDER, `EXIT 1`)** | \n| **CrewAI** (`1.6.1` ) | Fixed (In-tool retry + `Idempotency-Key` ) | **1 row (`PASS`, `200` dedup)** | **1 row (`PASS`, `200` dedup)** | **1 row (`PASS`)** | \n\nBoth LangGraph and OpenAI Agents SDK did what you'd expect when a tool returned `HTTP error 502` or a `JSONDecodeError`: the LLM loop retried `create_order(customer_id=\"cust_123\", amount_cents=4900)`.\n\nBecause standard tutorial tool functions don't attach an `Idempotency-Key`, the second call silently inserted a **second order row** in the database—even on `malformed_json`:\n\n```\n  [commit-then-fail-502] (LangGraph / OpenAI Agents SDK — default mode)\n    timeline:\n      #1 POST /api/v1/orders -> upstream 201 -> injected 502 [lose-first-commit]\n      #2 POST /api/v1/orders -> upstream 201   <-- SECOND ORDER WRITTEN!\n```\n\nCrewAI surprised me. It did **not** double-charge on `502`—not because it sent an idempotency key, but because CrewAI's executor blocks consecutive identical tool calls as a loop guard (and caches tool outputs by default).\n\nThe catch? When the API returned a completely recoverable transient `503 Service Unavailable`*before* writing anything (` fail_before_upstream`), CrewAI **refused to retry** and finished with **` 0` orders written**:\n\n```\n  [failed] fail-before-upstream-503 (CrewAI — default mode)\n    timeline:\n      #1 POST /api/v1/orders -> injected 503 [transient-503]\n    - FAIL (operation_attempts): expected >= 1 retry attempts with X-Operation-ID=\"op-crew-...\" after \"transient-503\", got 0\n    - PASS (max_tool_calls): tool calls for POST /api/v1/orders within budget (1 <= 3)\n    hint: Verify the agent retries transient tool failures with the same correlation header instead of silently giving up.\nExit code: 1\n```\n\nFrameworks shouldn't be blamed for missing business-level idempotency—that's application logic. The fix that turned all 3 frameworks green (`1` row written, `EXIT 0` across every fault) has two parts:\n\n```\nheaders[\"Idempotency-Key\"] = f\"order-{run_id}-{customer_id}-{amount_cents}\"\n\nfor _ in range(3):\n    resp = httpx.post(\n        f\"{TOOL_BASE_URL}/api/v1/orders\",\n        json={\"customer_id\": customer_id, \"amount_cents\": amount_cents},\n        headers=headers,\n        timeout=5.0,\n    )\n    if resp.status_code < 400:\n        return json.dumps(resp.json())\n```\n\nWith that fix, `afc` verifies deduplication (`#2 -> upstream 200`) and recovery across all 3 frameworks:\n\n```\n  [passed] commit-then-fail-502 (754 ms)\n    timeline:\n      #1 POST /api/v1/orders -> upstream 201 -> injected 502 [lose-first-commit]\n      #2 POST /api/v1/orders -> upstream 200   <-- DEDUPLICATED!\n    - PASS (operation_attempts): observed 1 retry attempts after \"lose-first-commit\"\n    - PASS (max_tool_calls): tool calls for POST /api/v1/orders within budget (2 <= 3)\nExit code: 0\ngit clone https://github.com/evhu-dev/agent-fault-check.git\ncd agent-fault-check\ngo build -o /tmp/afc ./cmd/afc\n\nuv venv --python 3.12 .bench-venv\nuv pip install --python .bench-venv/bin/python langgraph langchain-openai openai-agents crewai httpx pyyaml\n\nAFC_BIN=/tmp/afc BENCH_PYTHON=.bench-venv/bin/python .bench-venv/bin/python examples/benchmarks/run_benchmark.py\n```\n\nHow are you testing tool-call idempotency and partial failures in your agent CI pipelines? Drop your patterns (or war stories) in the comments!", "url": "https://wpnews.pro/news/i-injected-a-502-after-db-commit-into-langgraph-openai-agents-sdk-and-crewai-s", "canonical_source": "https://dev.to/evhu_6db20d656bbc55bf2b3e/i-injected-a-502-after-db-commit-into-3-popular-ai-agent-frameworks-heres-which-ones-hlc", "published_at": "2026-11-30 05:37:02+00:00", "updated_at": "2026-11-30 05:45:39.643462+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "mlops"], "entities": ["LangGraph", "OpenAI Agents SDK", "CrewAI", "agent-fault-check", "PostgreSQL", "GitHub"], "also_reported_by": [], "takeaway": "LangGraph 1.2.24 and OpenAI Agents SDK 0.26.0 retried tool calls after a 502 returned post-commit or a truncated 201, writing a second order row, while CrewAI 1.6.1's loop guard prevented duplicates but skipped retries on a transient 503; adding an Idempotency-Key header produced a single row with 2", "recommendation": {"advice": "Attach an Idempotency-Key to every write tool call and test agents against injected 502-after-commit and truncated-response faults, since default retry loops silently duplicate writes.", "playbook": "agent-architecture", "playbook_url": "https://wpnews.pro/playbooks/agent-architecture"}, "alternates": {"html": "https://wpnews.pro/news/i-injected-a-502-after-db-commit-into-langgraph-openai-agents-sdk-and-crewai-s", "markdown": "https://wpnews.pro/news/i-injected-a-502-after-db-commit-into-langgraph-openai-agents-sdk-and-crewai-s.md", "text": "https://wpnews.pro/news/i-injected-a-502-after-db-commit-into-langgraph-openai-agents-sdk-and-crewai-s.txt", "jsonld": "https://wpnews.pro/news/i-injected-a-502-after-db-commit-into-langgraph-openai-agents-sdk-and-crewai-s.jsonld"}}