Zero Labs
Industry News / AI

How We Turned One AI Agent Failure Into a Regression Test

Source · Towards AI By Decoding AI

From the publisher’s feed, collected in the ZeroLabs newsroom.

Method note · for practitioners. An agent charged six orders twice. We replayed the task 12 times: 8 clean runs proved nothing, and one guarded run quietly tried the same mistake again. The test that works doesn’t need the agent at all.A regression test for an AI agent is a test that fails if a failure you have already seen comes back. Last week, in our timeout test, one Claude Haiku agent charged six orders twice when its own “verification” loop re-ran the payment tool. This post turns that one failure into a test, in four steps. The first test we built passed 8 of 8 runs and proved nothing. The one that works replays the mistake directly and fails every time without the fix.Written with AI assistance; every number comes from a measurement we ran and log with the draft. This is the method note behind Flagship 4 and Flagship 5.12 replays of one failure, 10 Oct 2026. Chart: Decoding AI.Key takeawaysStep 1, capture: keep the call log of the failing run, not just the bad output.Step 2, replay the task: we re-ran the same task 8 times on two models. 0 duplicate charges.Step 3, don’t trust the clean runs: if the bug still struck 1 run in 16, 8 clean runs would happen about 60% of the time.Step 4, replay the mistake: a test that calls the charge twice fails without the guard and passes with it, every time.The guard earned its place in our runs: 1 of 4 guarded agents re-ran a charge by accident, and nothing was charged twice.TL;DRHow do you turn an AI agent failure into a regression test? Capture the failing run’s tool calls, then write a test that replays the harmful action directly against your tools, not one that hopes the agent repeats the mistake. Re-running the original task 8 times found nothing, because the failure is rare. Replaying the double charge failed every time until we added a guard.Status, 10 October 2026: 12 agent runs (8 Claude Haiku, 4 Claude Sonnet through the Claude Agent SDK; exact version strings are not shown to us), plus a deterministic test.Step 1: what exactly happened?Read the tool calls, not the output. The failing run’s final file looked fine: six confirmation codes in the right order. The payment ledger said otherwise: 12 charges for 6 orders.The call log told the story. The agent checked the status of all six orders, charged each one once, checked status again, and then ran ./process on every order a second time. It had meant to verify. It used the charge tool to do it.So the failure is not “the agent got the wrong answer”. It is “the charge tool was called twice for the same order”. That sentence is the test.Step 2: does replaying the task catch it?Not reliably. We rebuilt the exact task, charge six orders exactly once, and ran it 8 times with no protection: 4 times on Claude Haiku, 4 times on Claude Sonnet.All 8 passed. 6 charges each, 0 duplicates.That feels like good news. It isn’t evidence. The original failure happened in 1 of 16 runs. If the bug were still there at that rate, 8 clean runs in a row would happen about 60% of the time. A rare failure looks fixed most days.From one failure to one test. Diagram: Decoding AI.Step 3: what does the fix look like?Put a guard in the tool so a repeat charge is refused. We gave the payment stub one rule: if an order is already in the ledger, return “already charged” and charge nothing. Then we ran the task 4 more times on Claude Haiku with the guard on.One of the four did it again. It charged all six orders, then, while checking its work, ran ./process on the first order a second time. The guard refused it: 7 charge calls, 6 charges. The agent noticed and wrote in its report that someone should check that order for a duplicate. There wasn't one.That run is the strongest result here. The mistake is not a one-off; the guard is what made it harmless.Step 4: what does the regression test look like?Replay the mistake against the tool, with no agent in the loop. This is the test we keep:ORDERS = ["ORD-95247", "ORD-29041", "ORD-96065", "ORD-60052", "ORD-14246", "ORD-29417"]def test_verification_loop_cannot_double_charge(): ledger = [] charge = lambda o: ledger.append(o) or f"charged {o}" is_charged = lambda o: o in ledger for o in ORDERS: charge_once(o, charge, is_charged, done=set()) for o in ORDERS: charge_once(o, charge, is_charged, done=set()) # the failing run's loop, replayed assert sorted(ledger) == sorted(ORDERS)charge_once is the wrapper from the timeout post. The order numbers are the real ones from the failing run. Without the guard, this test fails on every run. With it, it passes on every run. It takes milliseconds and never depends on whether today's agent feels like verifying.Which failure from your own agent could you replay without the agent? Tell us in the comments.The measurement, 10 Oct 2026.What this does not showThat the agents are fixed. 8 clean runs are consistent with the bug being gone or still there.Rates. 12 runs. The one guarded repeat is an incident, not a rate.Every failure fits this pattern. Replaying works when the harm is a tool call. Wrong reasoning needs cases like the ones in our eval set.Clean protocol. The guarded run that repeated a charge also left out its final status line. Our ledger grade passed it; a stricter grader would not.FAQHow do you turn an AI agent failure into a regression test? Find the harmful action in the run’s tool calls, then write a test that performs that action against your tools and checks the result.Why not just re-run the task that failed? Agent failures are often rare. In our test, 8 re-runs were all clean even though the same mistake appeared again in the next 4.What stops an AI agent from charging twice? A guard in the tool: an idempotency key, or a check that refuses to charge an order already charged.How many runs prove a bug is fixed? For a 1-in-16 failure, 8 clean runs happen about 60% of the time by chance. Test the fix directly instead.What is one failure your agent has had that you could replay in a test today?Tomorrow: Flagship 6, when an agent should recover on its own and when it should hand off to a human. Follow Decoding AI to get it.What we measure nextFriday 30 October: when an agent should recover on its own, and when it should hand off to a human.Monday 2 November: what MCP tool definitions cost an agent in context.Tuesday 3 November: when more context creates another failure surface.Today one mistake became one test. Tomorrow we find out when an agent should stop fixing things and ask for help.NEXT → recover or hand off · thresholds · FridayNext: recover or hand off.If this changed how you write tests for your agent, clap so more people building agents see it, tell us in the comments which failure you would replay first, and follow Decoding AI — then hit subscribe so Friday’s experiment lands in your inbox.Sources & ReferencesStripe, Idempotent requestsAnthropic, Building effective agentsDecoding AI, The Timeout Didn’t Double-Charge Anyone. The AI Agent’s Own Check Did. (the original failure)Decoding AI, Our Happy-Path AI Agent Tests Caught Nothing. Failure Cases Did. (Flagship 5)How We Turned One AI Agent Failure Into a Regression Test was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.