Tutorials

We converted a single AI agent failure into a regression test.

Decoding AI describes converting a rare Claude Haiku failure, where an agent charged six orders twice, into a deterministic regression test. Rerunning the original task eight times passed, but that weak evidence could not prove the bug was gone because the failure occurred rarely. The real problem was a harmful tool call used as verification. A payment tool guard that refuses duplicate charges made the run harmless, even when the agent repeated the mistake. The durable fix is replaying the harmful tool call directly, creating a test that catches dangerous AI agent behavior without depending on stochastic task reruns.

We converted a single AI agent failure into a regression test.

Key Takeaways

  • A single harmful AI agent action, such as a double charge, can be turned into a deterministic regression test by replaying the dangerous tool call directly.
  • Passing repeated task runs is weak evidence of a fix, because rare agent failures can disappear by chance rather than being truly resolved.
  • The effective safeguard was a tool-level idempotency guard that rejected duplicate charges, not a better final answer from the agent.
  • The stable regression test uses real order IDs to repeat the harmful charge loop, ensuring the bug is caught without relying on the agent making the same mistake.
  • The method does not prove the underlying agent failure rate is fixed, and it mainly applies when harm comes from tool calls rather than faulty reasoning.

Meta description: Decoding AI turns one Claude Haiku double-charge failure into a regression test after 12 runs; replaying the harmful tool call, not the task, catches it.

We converted a single AI agent failure into a regression test.

Tags: AI agent testing, regression test, Claude Haiku, tool calls, idempotency

Featured image: Abstract, friendly illustration of a small agent passing a payment token into a ledger, with a guard blocking a second token; no real people, no logos, no text.

For teams that test AI agents, the useful lesson is narrower than “make the agent smarter”: one observed harmful action can become a deterministic test. On 10 October 2026, Decoding AI published a method note behind Flagship 4 and Flagship 5 describing 12 agent runs that turned one Claude Haiku failure into a regression test. The failure was a double charge: six orders were charged twice. The team’s first check passed 8 of 8 runs and proved nothing; the test that works replays the harmful tool call directly, without relying on the agent to repeat the mistake.

The harmful action was a second call to the charge tool

The original problem came from a timeout test. In that run, one Claude Haiku agent charged six orders twice because its own verification loop re-ran the payment tool. The final output looked acceptable: the file contained six confirmation codes in the right order. The payment ledger told a different story: it showed 12 charges for 6 orders.

The call log made the failure visible. 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 the result. Instead, it used the charge tool as the verification step.

That distinction matters. The failure was not “the agent gave the wrong answer.” The failure was “the charge tool was called twice for the same order.” In a regression test for an AI agent, that sentence is the test: if this action can harm the ledger, the test should catch it.

Eight clean reruns did not prove the bug was gone

The team rebuilt the exact task: charge six orders exactly once. It ran the task 8 times with no protection: 4 times on Claude Haiku and 4 times on Claude Sonnet through the Claude Agent software development kit. Exact version strings were not shown to the team.

All 8 runs passed. Each produced 6 charges and 0 duplicates. That feels reassuring, but it is not proof.

The original failure happened in 1 of 16 runs. If the bug were still present at that rate, 8 clean runs in a row would happen about 60% of the time by chance. A rare failure can look fixed on most days. Re-running the original task 8 times found nothing because the failure is rare, not because the task is safe.

The practical conclusion is uncomfortable but simple: clean reruns of a rare agent failure are weak evidence. They can be consistent with the bug disappearing, and they can also be consistent with the bug still being there.

A simple ledger guard stopped the duplicate charge

The fix was not a better final answer. It was a guard inside the tool. The team gave the payment stub one rule: if an order is already in the ledger, return “already charged” and charge nothing. This is the same idea behind an idempotency key or a duplicate-charge check: the tool refuses to perform the harmful action twice.

The team then ran the task 4 more times on Claude Haiku with the guard on. One of the four agents 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 the repeat charge. The run ended with 7 charge calls and 6 charges.

The agent noticed the refused action and wrote in its report that someone should check that order for a duplicate. There was not one.

That guarded run is the strongest result in the note. The mistake was not a one-off event. The guard is what made it harmless.

The regression test replays the mistake without an agent

The test the team keeps does not ask the agent to repeat the failure. It replays the harmful action against the tool directly.

The test uses six real order numbers from the failing run: ORD-95247, ORD-29041, ORD-96065, ORD-60052, ORD-14246, and ORD-29417. It calls the charge path once for each order, then repeats the same loop that caused the failure. The wrapper used in the test is charge_once, the same wrapper from the timeout post.

Without the guard, the test fails on every run. With the guard, it passes on every run. It takes milliseconds and never depends on whether today’s agent feels like verifying its work.

This is the shift from a fragile rerun to a stable regression test. A test that hopes the agent will repeat the mistake is weak. A test that performs the mistake against the tool is strong.

What the 12 runs do not show

The note is careful about the limits of the measurement.

It does not show that the agents are fixed. Eight clean runs are consistent with the bug being gone, but they are also consistent with the bug still being there. It does not establish a rate. Twelve runs include one guarded repeat, and that repeat is an incident, not a reliable probability.

It also does not show that every agent failure fits this pattern. Replaying a harmful action works when the harm is a tool call. Wrong reasoning needs different cases, like the ones in the team’s evaluation set.

There is a smaller caveat too. The guarded run that repeated a charge also left out its final status line. The ledger grade passed that run, but a stricter grader would not have.

The follow-up schedule in the note points to related questions: Friday 30 October covers when an agent should recover on its own and when it should hand off to a human; Monday 2 November covers what Model Context Protocol tool definitions cost an agent in context; Tuesday 3 November covers when more context creates another failure surface.

The note was written with AI assistance, and Decoding AI states that every number comes from a measurement it ran and logged with the draft. Its source references include Stripe’s material on idempotent requests, Anthropic’s Building effective agents, the original failure article, and Flagship 5. The underlying point for practitioners is simple: one failure became one test, but only after the team stopped trusting clean reruns and started replaying the harmful action.

Comments (0)

  1. No comments yet. Be the first to share what worked for you.

Leave a comment

Comments are reviewed before they appear. Your email address is not published.