The Production Learning Signal Hidden Between the Stack Trace and the Architectural Layer That Actually Failed
Tracing a failure back to its real source takes more than a stack trace.

AI agent failure attribution by harness layer means tracing backward from a visible failure to the specific step where its cause entered the run, then identifying the responsible prompt, tool, workflow, or memory component. The decisive step is not necessarily the first mistake or the final failed action. Reliable repair requires separating error introduction from propagation, fixing the layer the evidence identifies, and validating the change against historical production traces before shipping.
Why the step where an agent fails is rarely the step that broke it
A failed tool call can look like a model error even when the agent was following a flawed instruction supplied much earlier. A wrong final answer can likewise trace back to a constraint that entered the run at step 1 and was never resolved. The stack trace clearly shows where the visible failure occurred. The attribution gap is the distance between the visible symptom recorded in the stack trace and the earlier decision that made the failure inevitable.
ErrorProbe, by Li et al., describes a recognizable cascade in which an architect introduces a subtle specification error, an engineer faithfully implements it, and a tester verifies the wrong behavior. The run may fail only many turns later, after those dependencies have obscured the original error. A locally faithful implementation is therefore not evidence that the underlying specification was correct. Inspecting only the engineer or tester can misassign responsibility for introducing the problem to the agent that inherited it.
LongRCA Bench measures how far this separation can extend. Its reference root-cause steps precede completion by a median of 48 recorded steps, and more than a quarter of trajectories contain over 100 subsequent steps after the decisive error. ErrorProbe describes multi-agent runs that last dozens to over a hundred turns and often grow beyond practical context windows. This makes the attribution gap structural. Long histories, inter-agent dependencies, and delayed symptoms create a debugging problem that cannot be resolved by inspecting the final exception alone.
Why automated judges and replays read the smoke, not the fire
An automated judge can correctly identify a bad result without correctly identifying its cause. The distinction is between detection and localization. ErrorProbe finds that judge-style methods struggle to pinpoint decisive error steps in long traces with delayed failures. The TelemetrySuffBench 2026 paper describes competitive agent-level attribution but substantially weaker step-level attribution on TracerTraj and Who&When. On Who&When’s handcrafted cases, step-level accuracy falls below 10% for smaller models.
Replay exposes the history, but exposure is not explanation. AgentDebugX, by Zhu et al., identifies the remaining work as determining which earlier decision made the run unsuccessful, explaining why it was decisive, and translating that diagnosis into a correction. A replay can show an agent repeatedly using a wrong value. It does not, by itself, establish whether the agent invented that value, inherited it from an instruction, or retrieved it from stale context. Those possibilities imply different repairs despite producing similar downstream behavior.
TRAJDEBUG, by Qi et al., sharpens this distinction by tracking the different consequences of local errors. Some mistakes are repaired, some remain harmless, and some contribute to the terminal failure. The first wrong step is not automatically the root cause. Nor is the mistake nearest the final failure. LongRCA Bench similarly separates finding failure-relevant activity from identifying where the decisive error originated, with RCTA’s improvement specifically in the former.
On the full LongRCA Bench, the best evaluated baseline achieves exact root-step accuracy well below a quarter, and even the best proposed method recovers fewer than one quarter of reference roots exactly. These results establish the boundary between narrowing a search and proving an attribution. Good tooling supplies evidence, while structured reasoning distinguishes evidence of an origin from evidence of another point of propagation.
How to pinpoint which of the three harness layers caused the failure
Prompt and perception failures often cause wrong output or a tool choice that was not expected. The underlying instruction may omit a critical edge case, leaving the agent to make a locally reasonable but globally wrong decision. AgentFixer often finds that instructions leave out what to do with empty or missing inputs, invalid data formats, and cases where the right action is unclear. The output alone can disguise that omission. Comparing the decision with the instructions actually available reveals whether the harness gave the agent enough guidance to handle the case.
Tool and execution failures can be just as misleading at execution. A harness may have been built against a particular database column, table, or API response structure that subsequently changed without signaling the change to the harness. The visible failure then occurs at execution. Its origin is the mismatch between the tool’s current structure and the harness’s assumptions. Attribution therefore depends on comparing the tool definition, arguments, and response rather than treating every unsuccessful call as a reasoning failure.
Planning and control-flow failures emerge when an agent loops without resolving the problem or stops too early on a weak signal. LongRCA Bench gives an example in which repeated checks retain a nightly lodging price as a two-night total, despite correcting a separate arithmetic error. A correction occurred, but the original constraint remained unresolved. Planning diagnosis checks whether the workflow registered and resolved the outstanding constraint before committing to an answer.
Memory and retrieval can also bring errors into these layers. A stale retrieval or incorrect handoff can corrupt a later step’s input without changing either the prompt template or the tool schema. The three-layer map is a starting point, and the diagnosis must also account for context provenance. A sound diagnosis identifies both the component executing the wrong action and the source of the information it acted on. Otherwise, a memory problem can be mislabeled as prompt ambiguity, just as a flawed instruction can be mislabeled as broken execution.
What systematic backward tracing actually looks like in practice
The practical method begins with the visible symptom and works backward through its dependencies. Tracing first identifies the earlier decisions that supplied the wrong value, interpretation, or unresolved constraint. ErrorProbe structures this work by detecting local anomalies with a failure taxonomy, then using symptom-driven backward tracing to prune irrelevant context. Not every earlier step deserves equal attention. Leaving out unrelated activity and telling downstream effects apart from possible causes makes it easier to check the remaining hypotheses.
A candidate origin then needs validation. ErrorProbe uses a specialized team comprising a Strategist, Investigator, and Arbiter to test error hypotheses through tool-grounded execution. This stage asks whether executable evidence supports the proposed cause. It separates a plausible account of the failure from a diagnosis that can justify a repair. Without that distinction, backward tracing can simply replace an obvious symptom with an untested story about an earlier step.
Paired comparison provides another way to narrow the search when a structurally similar successful trace is available. HPFA, by Zhu et al., presented at COLM 2026, compares failed and successful reasoning paths through a hypergraph that represents non-linear logical dependencies. The comparison is not merely chronological. A later conclusion may depend on parallel derivations that are far apart in the recorded sequence. Mapping those links helps find where the paths diverge in ways that matter, without full step-by-step counterfactual re-execution, which becomes harder to scale as trajectories grow.
Once a candidate error is found, its lifecycle becomes the next object of investigation. TRAJDEBUG separates error trigger detection, error state classification, and critical attribution. Its states include Clean Resolution, Costly Resolution, Manifest Active, and Latent Active. A step can be wrong without causing the final failure if later activity corrected it or made it irrelevant, so attribution must follow the error’s consequences beyond its discovery.
The final localization check compares execution with the upstream instructions that reached the candidate step. RCTA uses this comparison to tell whether a step inherited an error or introduced a new one. An inherited mistake points toward prompt or handoff design, while a new mistake points toward the executing agent or tool. AgentDebugX’s DeepDebug complements this approach through multi-turn diagnosis, global trajectory understanding, structure-guided investigation, and cross-examination. Together, these methods turn trace inspection into a sequence of answerable questions about origin, propagation, responsibility, and evidence.
Why the harness — not the model — is the right layer to fix first
The harness includes everything around the model that governs its work, including prompts, tool definitions, control flow, memory, retrieval, and context management. Once attribution identifies one of those components as the origin, changing that component is generally faster, cheaper, and more reversible than changing the model. The intervention follows the evidence. A schema mismatch calls for a schema repair, while a missing edge-case instruction calls for a prompt change. Neither diagnosis, on its own, establishes a need to alter model weights.
The things that keep needing repair are often ordinary engineering defects. They include fragile setup and build procedures, wasteful polling loops, short shell timeouts, unsafe cleanup behavior, unpinned dependency versions, incorrect data-format assumptions, and destructive inspection of state that must be preserved. These are harness problems with concrete boundaries. A model swap or fine-tuning effort does not directly repair the boundary that failed when the actual cause is an outdated tool contract or unsafe workflow. It can also cause regressions while leaving the original defect in place.
That said, harness changes can overfit too. A prompt rewrite may fix one failure mode and break another, while a tool addition may improve an evaluation and degrade the conversation. A successful repair of one trace is insufficient. This objection changes the validation requirement while preserving the sequencing of the intervention. The candidate change needs testing across a broad set of historical traces, including cases that passed before the repair.
Shopify’s GraphQL agent illustrates the distinction between harness-first and harness-only. Its flywheel explicitly exhausts harness improvements before mining production traffic for training signal and moving to supervised fine-tuning followed by reinforcement learning. Model-level work remains part of the process. It comes after the surrounding system has been improved, rather than serving as a substitute for diagnosing it. Attribution guides the first repair to the responsible layer, and subsequent evidence establishes whether model changes are warranted.
Why replay validation against production traces must precede shipping any harness change
Replay validation tests a proposed repair with the same inputs and tool observations found in historical production traces. A changed prompt, fixed tool schema, or updated workflow must work better on more than the one case that led to the change. Previously passing traces are part of that test. The comparison tests whether the proposed configuration would have performed better or worse across the production work actually encountered. Without this comparison, a plausible repair remains an unmeasured deployment risk.
Useful replay requires more than a terminal pass or fail. The necessary record includes the reasoning trace, tools considered, tools invoked, arguments passed, responses returned, tokens spent at each step, and latency at each hop, stitched into one hierarchical trace. Those details preserve the evidence needed for attribution. They also allow a rerun to be examined at the step where the repair was intended to act. A healthier result does not by itself explain whether the diagnosed defect was corrected.
AgentDebugX operationalizes this distinction through its Detect, Attribute, Recover, and Rerun loop. Recovery turns the diagnosis into a rerunnable fix, and rerunning tests the proposed fix for correctness. ErrorProbe applies the same evidentiary standard to its verified episodic memory, updating it only when executable evidence confirms an error pattern. Confirmed failure-diagnosis-repair bundles then become reusable debugging memory. AgentDebugX’s Error Hub also keeps diagnosed failures available so later work can build on each investigation.
Observability platforms support parts of this loop without replacing causal attribution. Braintrust runs inline scorers and LLM-as-a-judge checks on live traces, then lets production failures become evaluation cases in one click. Langfuse has a data-warehouse-native stack for managing prompts, storing traces, and running evaluations. Live scoring helps expose regressions, while managed traces, prompts, and evaluations provide infrastructure for investigating and testing changes.
Engineers trace the symptom backward, attribute the surviving error to its layer of origin, make a targeted repair, and replay historical cases before shipping. Failed replays send the change back into diagnosis. Successful validation supports deployment and adds a confirmed case to the debugging record.
Sources
- Towards Self-Improving Error Diagnosis in Multi-Agent Systems
- AgentDebugX: An Open-Source Toolkit for Failure Observability, Attribution, and Recovery in LLM Agents
- LongRCA Bench: Root-Cause Localization in Long-Horizon Agent Trajectories
- TRAJDEBUG: Tracing Error Lifecycle to Identify Critical Failures in Long-Horizon Agent Trajectories
- Published as a conference paper at COLM 2026
- TelemetrySuffBench: Is Agent Telemetry Sufficient for Failure-Origin Diagnosis?
- What Is Agent Observability? A 2026 Developer Guide


