cd /news/ai-agents/i-injected-a-502-after-db-commit-int… · home › topics › ai-agents › article
[ARTICLE · art-178406] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=· neutral

I Injected a 502 After DB Commit Into LangGraph, OpenAI Agents SDK, and CrewAI — Here's What Broke

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.

recommendation

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.

more in playbook: Designing agent systems
by read4 min views5 publishedNov 30, 2026

Most AI agent benchmarks test prompt accuracy or mock happy-path tool responses.

In 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:

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). To see how default tool-calling patterns behave under these exact faults, I ran agent-fault-check (afc)—an open-source (Apache-2.0) Go fault-injection proxy and CI runner—against three popular Python agent frameworks:

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." 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. Full reproducible code: examples/benchmarks on GitHub

Framework (Version) Mode commit_then_fail (502 after201 ) malformed_json (truncated201 ) fail_before_upstream (503 )
LangGraph (1.2.24 ) Default 2 rows (DUPLICATE WRITE) 2 rows (DUPLICATE WRITE) 1 row ( PASS )
LangGraph (1.2.24 ) Fixed ( Idempotency-Key ) 1 row (PASS, 200 dedup) 1 row (PASS, 200 dedup) 1 row (PASS)
OpenAI Agents SDK (0.26.0 ) Default 2 rows (DUPLICATE WRITE) 2 rows (DUPLICATE WRITE) 1 row ( PASS )
OpenAI Agents SDK (0.26.0 ) Fixed ( Idempotency-Key ) 1 row (PASS, 200 dedup) 1 row (PASS, 200 dedup) 1 row (PASS)
CrewAI (1.6.1 ) Default 1 row, 0 retries (EXIT 1) 1 row, 0 retries 0 rows (DROPPED ORDER, EXIT 1)
CrewAI (1.6.1 ) Fixed (In-tool retry + Idempotency-Key ) 1 row (PASS, 200 dedup) 1 row (PASS, 200 dedup) 1 row (PASS)

Both 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).

Because 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:

  [commit-then-fail-502] (LangGraph / OpenAI Agents SDK — default mode)
    timeline:
      #1 POST /api/v1/orders -> upstream 201 -> injected 502 [lose-first-commit]
      #2 POST /api/v1/orders -> upstream 201   <-- SECOND ORDER WRITTEN!

CrewAI 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).

The catch? When the API returned a completely recoverable transient 503 Service Unavailablebefore writing anything ( fail_before_upstream), CrewAI refused to retry and finished with 0 orders written:

  [failed] fail-before-upstream-503 (CrewAI — default mode)
    timeline:
      #1 POST /api/v1/orders -> injected 503 [transient-503]
    - FAIL (operation_attempts): expected >= 1 retry attempts with X-Operation-ID="op-crew-..." after "transient-503", got 0
    - PASS (max_tool_calls): tool calls for POST /api/v1/orders within budget (1 <= 3)
    hint: Verify the agent retries transient tool failures with the same correlation header instead of silently giving up.
Exit code: 1

Frameworks 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:

headers["Idempotency-Key"] = f"order-{run_id}-{customer_id}-{amount_cents}"

for _ in range(3):
    resp = httpx.post(
        f"{TOOL_BASE_URL}/api/v1/orders",
        json={"customer_id": customer_id, "amount_cents": amount_cents},
        headers=headers,
        timeout=5.0,
    )
    if resp.status_code < 400:
        return json.dumps(resp.json())

With that fix, afc verifies deduplication (#2 -> upstream 200) and recovery across all 3 frameworks:

  [passed] commit-then-fail-502 (754 ms)
    timeline:
      #1 POST /api/v1/orders -> upstream 201 -> injected 502 [lose-first-commit]
      #2 POST /api/v1/orders -> upstream 200   <-- DEDUPLICATED!
    - PASS (operation_attempts): observed 1 retry attempts after "lose-first-commit"
    - PASS (max_tool_calls): tool calls for POST /api/v1/orders within budget (2 <= 3)
Exit code: 0
git clone https://github.com/evhu-dev/agent-fault-check.git
cd agent-fault-check
go build -o /tmp/afc ./cmd/afc

uv venv --python 3.12 .bench-venv
uv pip install --python .bench-venv/bin/python langgraph langchain-openai openai-agents crewai httpx pyyaml

AFC_BIN=/tmp/afc BENCH_PYTHON=.bench-venv/bin/python .bench-venv/bin/python examples/benchmarks/run_benchmark.py

How are you testing tool-call idempotency and partial failures in your agent CI pipelines? Drop your patterns (or war stories) in the comments!

── more in #ai-agents 4 stories · sorted by recency
── more on @langgraph 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/i-injected-a-502-aft…] indexed:0 read:4min 2026-11-30 · —