Est.

Automated Regression Tests Generated From Production Failures

Production failures become release-gating tests that catch silent agent errors.

· 9 min read
Cover illustration for “Automated Regression Tests Generated From Production Failures”
Agent Debugging · October 28, 2026 · 9 min read · 1,927 words

Traditional error monitoring fails for AI agents because an agent can run without errors and still behave wrongly. An agent can complete its tool calls and return a polished answer while violating its instructions or misleading the user. Automated regression tests generated from production failures close that gap by turning captured failures into behavioral checks that gate releases, so a known silent failure cannot ship again unnoticed.

Why handwritten test suites cannot keep pace with agents in production

Synthetic tests reflect what an engineer imagined a user might do. Production exposes what users actually do instead. Arthur's ADLC guide describes a billing agent that passes a unit test by calling the right tool when asked “where is my refund,” then fails during a real conversation. When the customer pushes back, it loops for eight turns, forgets the order number from turn one, and invents a refund policy on turn five. The unit test never exercised the whole conversation.

That gap comes from the interaction of non-determinism, multi-step execution, and a production input space larger than a synthetic suite can cover. An agent can pass a case today and fail it tomorrow, while mistakes in retrieval, planning, or tool use can escape checks applied only to the final answer. Unit tests still have a clear role. They catch deterministic decision logic quickly and cheaply, but they cannot establish that a probabilistic agent will handle an extended conversation correctly. Production failures give those tests the cases they lack, so teams can keep using them.

What makes a production trace more valuable than a crafted test case

A production trace preserves an authentic edge case, its execution context, and evidence of what broke in that particular system. A confidently wrong response might follow from selecting the wrong tool, passing a malformed argument, or retrieving unsuitable context. Those causes require different fixes even when their visible outputs look similar.

The useful record includes the request and full conversation history, system prompts and the active prompt version, and tool calls with their inputs, outputs, and latency. Retrieval evidence shows which documents were pulled and which were not, while intermediate reasoning state and key decision points help show where the agent went wrong. Application metadata supplies the session ID, user ID, model version, and timestamp. Structure is as important as field coverage. A span hierarchy connects the agent session, reasoning steps, and nested tool invocations so that the failing path can later be isolated and replayed.

The destination is a golden dataset. This is a curated, versioned set of high-signal cases that grows over time and is treated as production infrastructure. Its value comes from preserving authentic failure patterns together with a concrete definition of correct behavior. Silent failures are especially useful cases to add because their output can look right without raising an error. Checking what the user actually gets can reveal evidence that execution logs alone may miss.

Classifying the failure before it becomes a test case

An unlabeled incident log does not yet form a useful regression dataset. Classification gives each failure a place in the testing strategy and exposes concentrations of weakness. A practical intake taxonomy can use five categories, namely planning errors, tool errors, retrieval errors, reasoning errors, and safety/policy violations. Each incident gets one primary mode when it enters the pipeline. That tag supports clustering, prioritization, and coverage audits without making classification an end in itself.

This practitioner grouping is distinct from a research taxonomy. MAST, published at NeurIPS 2025, identifies 14 named modes across three categories, which are system design issues, inter-agent misalignment, and task verification. Its design-time concerns include ambiguous prompts, role mis-specification, and inadequate verification. Runtime silent failures can also arise from language-based decision-making in a correctly designed system. Both can occur in the same system, so correcting a design weakness does not eliminate the need to test runtime behavior.

Tool-connected and multi-agent systems also need tags for the risks they face. The Microsoft AI Red Team's June 2026 taxonomy adds seven failure mode categories, including Goal Hijacking, Inter-Agent Trust Escalation, Session Context Contamination, and MCP/Plugin Abuse. These distinctions help teams select the appropriate fix workflow. The operational requirement remains modest, however. A primary label must make the incident actionable and keep the dataset from becoming a collection dominated by happy paths or repeated versions of one failure.

Sanitizing traces so they can become permanent test infrastructure

Names, emails, account numbers, medical information, and financial data must be stripped or replaced, while credentials, API keys, and secrets must be removed. Live database IDs and server URLs need deterministic placeholders or mocks. Any external state on which the failure depended must also be captured in a form that testing can mock. Otherwise, retaining the trace risks exposing sensitive data, while discarding it loses the regression case.

OpenTelemetry Collector processors can remove attributes, filter records, redact attributes, and change values before the context of the failure reaches the agent or test store. A model should not be the privacy boundary. When the original content is too sensitive to retain, a synthetic equivalent can preserve the failure structure instead. The guide illustrates this with an agent that books Portland, Maine when the user means Oregon. The test can be kept to check whether the agent asks a clarifying question when the destination is unclear, without keeping the customer's record.

Sanitization must be followed by reduction to the context needed for reproduction. ReProAgent's 2026 design uses a small slice that has the failing application frames, the request shape, the downstream interactions that matter, and nearby tests that show how tests in that code are written. Raw telemetry is too broad for this purpose. The incident must also resolve to the commit, image digest, or equivalent immutable revision that produced it. Generating against current source alone can target code that has already moved away from the deployed state, undermining the test before its assertion is written.

Generating a test that fails on the bug and passes after the fix

A generated regression test must fail on the pre-fix revision for the reported reason and pass after the correcting patch. The billing case makes this criterion concrete. A test that checks only the initial tool call can pass while the conversation still loses the order number or invents policy. A useful test must distinguish the broken behavior from the corrected behavior across the relevant trajectory. Merely recording what production did does not establish what it should have done.

The oracle for correctness comes from repository evidence, including existing tests, API specifications, exception policies, and the intended contract. The model instantiates an assertion that this evidence supports. It does not invent the contract. ReProAgent identifies the danger of generating a test that asserts a NullPointerException because production emitted one. Such a test passes on the buggy implementation and preserves the defect, so the generation prompt must explicitly prohibit treating observed buggy behavior as correct.

For agent behavior, exact matching of the final response is a poor default because an answer can use different words and still be correct. Assertions should instead ask whether the correct tool was called with valid arguments and in the right order. Required facts must be present and grounded in retrieved context, and forbidden actions must be absent. Completion also needs a behavioral definition. The agent should either finish the task or ask for the clarification it needs, while its output conforms to the expected schema.

ReProAgent separates bug localization, root-cause analysis, test planning, and test generation, combining repository retrieval with runtime interaction. Span-level scoring further distinguishes tool selection accuracy, argument correctness, and planning quality at the step where the failure occurs. Each generated test also needs the originating incident tag so that its purpose remains traceable as the suite grows.

Closing the loop: from golden dataset to CI/CD release gate

Diagram: Four Stages: Production Failure to CI/CD Release Gate. Visualizes: Visualize the four-stage pipeline that converts a production trace into a release-blocking regression test.

The pipeline can be organized into four stages while retaining the guide's six operations, which are capture, classify, sanitize, define assertions, structure and version the dataset, and run experiments that gate CI/CD. Stage one captures the production trace and records its primary failure mode at intake. It also preserves the deployed revision needed for reproduction. Without that anchor, later results cannot reliably be tied to the behavior that failed in production.

Stage two sanitizes and reduces the trace, then defines expected behavior from the system's existing contract. The resulting case is structured, clustered with related cases, and versioned in the golden dataset. Stage three scores and classifies behavior at span level. Its tool selection, argument correctness, and planning checks localize the failure beyond the initial intake label. The fail-to-pass criterion then establishes that the generated test discriminates between the buggy revision and the correcting patch.

Stage four makes that evidence a release gate. The regression suite runs on every prompt change, model swap, retrieval tweak, or tool update, because each can alter the behavior the dataset protects. A three-tier CI strategy keeps different forms of testing in their appropriate roles. Unit tests with WireMock stubs provide fast, deterministic PR gates, while schema contract tests through MCP Inspector CLI catch schema regressions before they reach a model. Eval-gated integration runs exercise the full regression suite for release candidates.

MCP regressions need explicit behavioral checks even when servers still work. Changes to a tool description, schema, or policy can change how a model uses tools without causing an ordinary service failure. Relevant regressions include increased tool-call amplification per user prompt and increased model token consumption caused by verbose tool metadata. Decreased task success due to schema or description drift belongs in the same release decision.

Each production incident that matters adds tests for behavior that pre-release testing missed, while clustering makes related weaknesses easy to see. Unit tests continue to protect deterministic logic.

Where production monitoring connects to the regression pipeline

The regression loop needs instrumentation in place before an incident happens. Missing context cannot be recovered from a failure that was never captured. The session-root hierarchy described earlier must preserve the relationship between reasoning and tool use, with tool invocations nested under the triggering model call span or placed as siblings of the inference span within the reasoning step. That relationship allows the trace to be reduced to the failing path. A flat record of operations that ran successfully cannot be used for replay in the same way.

Wei Wu's When Errors Become Narratives, published on arXiv in June 2026, describes “fail-plausible” failures in which an agent transforms an error into a polished, believable report. The observer is “convincingly lied to by the failure itself.” Most of these failures were caught by people examining what users saw. This explains why apparently healthy logs can coexist with bad outputs. Monitoring must assess adherence to the agent's instructions even when execution raises no error.

A platform that supports this loop must check every trace against those instructions and group repeated failure patterns into clusters so they can be seen together. Its alerts need to reach existing developer workflows such as Slack and CI. Integration with coding agents allows fixes to proceed without context-switching. Support for Vercel AI, OpenAI Agents, LangGraph, and Azure AI Foundry also lets teams instrument the frameworks they use without a rewrite. These capabilities connect behavioral evidence to the workflow that produces and validates a regression test.

Audits serve primarily as regression engines. Their durable contribution is converting a discovered failure into a release-blocking check. A plausible but wrong answer is therefore not the end of the monitoring process. It is the beginning of a test whose assertion, provenance, and release-gating role make the lesson permanent.

Sources

  1. Microsoft Updates Taxonomy of AI System Failure Modes
Filed underAgent Debugging

More in Agent Debugging