I Injected a 502 After DB Commit Into LangGraph, OpenAI Agents SDK, and CrewAI
Here is which default AI agent frameworks silently double-charged on a dropped 201 Created response,
which one silently dropped the order on a transient 503, and the 10-line pattern that fixed all three.
chaos-spec.yaml is open source in
examples/benchmarks/.
Benchmark Results (18 Real Runs via afc)
All three agents ran against the exact same disposable Orders HTTP API (POST /api/v1/orders) proxied through
agent-fault-check (TOOL_API_BASE_URL). The API honored Idempotency-Key whenever sent,
returning 200 OK instead of creating a duplicate row.
| Framework (Version) | Mode | commit_then_fail (502 after 201) |
malformed_json (truncated 201) |
fail_before_upstream (transient 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) |
Finding 1: Silent Duplicate Writes (LangGraph & OpenAI Agents SDK)
When the Orders API committed a 201 Created and afc injected a 502 Bad Gateway
(or truncated the JSON response), both LangGraph and OpenAI Agents SDK surfaced the tool error back to the LLM, which retried
create_order. Without a stable Idempotency-Key, the second call silently inserted a second order:
[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
Finding 2: Silent Dropped Orders (CrewAI)
CrewAI did not double-charge on 502—because its executor blocks consecutive identical tool calls as a loop guard
and caches tool outputs by default. The surprise: on a completely recoverable transient 503
(fail_before_upstream), CrewAI refused to retry and finished with 0 orders written.
afc caught this immediately with operation_attempts:
[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
Finding 3: Third-State Crash/Resume Reconciliation (PydanticAI)
Inspired by pydantic/pydantic-ai#10926,
agent_pydantic_ai.py
pins the dangerous third state: Invocation 1 persists a pre-attempt record for
(operation_id, tool_name, tool_call_id), calls POST /api/v1/orders, and crashes on
commit_then_fail before storing the result. On resume, naive retry writes a 2nd duplicate order
(EXIT 1), while reconciling via GET /api/v1/orders/by-key finishes cleanly without a second POST:
[passed] third-state-crash-resume (PydanticAI 2.77.0 — mode=reconcile)
timeline:
#1 POST /api/v1/orders -> upstream 201 -> injected 502 [crash-after-commit]
#1 GET /api/v1/orders/by-key -> upstream 200 <-- RECONCILED WITHOUT 2ND POST
- PASS (max_tool_calls): tool calls for POST /api/v1/orders within budget (1 <= 1)
- PASS (max_tool_calls): tool calls for GET /api/v1/orders/by-key within budget (1 <= 2)
Exit code: 0
The 10-Line Production Fix
Attach a deterministic Idempotency-Key derived from (run_id, operation_args) on every mutating HTTP call,
and keep bounded transient HTTP retries inside the tool wrapper (required for CrewAI, and cheaper/faster than LLM-driven retries in every framework):
headers["Idempotency-Key"] = f"order-{run_id}-{customer_id}-{amount_cents}"
for _ in range(3):
resp = httpx.post(url, json=payload, headers=headers, timeout=5.0)
if resp.status_code < 400:
return json.dumps(resp.json())
Run the Benchmark Yourself
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