CodeTracer: Towards Traceable Agent States

Han Li, Yifan Yao, Letian Zhu, Rili Feng, Hongyi Ye, Jiaming Wang, Yancheng He, Pengyu Zou, Lehan Zhang, Xinping Lei, Haoyang Huang, Ken Deng, Ming Sun, Zhaoxiang Zhang, He Ye, Jiaheng LiuarXiv 2026

TL;DR

CodeTracer introduces a scalable framework to debug autonomous AI coding agents by reconstructing their complex, multi-step execution histories into structured hierarchical trace trees. By automatically pinpointing the exact "failure onset"—the precise step where an agent first goes off track—it enables targeted recovery via reflective replay, significantly boosting agent success rates under matched budgets.

What Problem Does This Paper Address?

Large language models (LLMs) are increasingly deployed as autonomous code agents capable of navigating repositories, editing code, and running tests. However, as these agents tackle longer and more complex engineering tasks, debugging them becomes a nightmare.

When an agent fails, it is rarely due to a single isolated mistake at the very end. Instead, an early misstep (like an incorrect hypothesis or a mislocalized edit) cascades into a hidden chain of errors, trapping the agent in unproductive loops. Current evaluation practices rely on coarse, end-to-end metrics (like pass rate) that collapse entire trajectories into a single success/failure label. Manual inspection of logs doesn't scale, leaving a critical gap: we don't know when or why agents go off track.

Methods

The authors present CodeTracer, an automated framework designed for process-level trajectory analysis and failure onset localization. The pipeline operates in three distinct stages:

  1. Evolving Extraction: Because agent frameworks generate messy, heterogeneous log directories, CodeTracer uses an LLM-driven extraction agent to discover the directory layout, adapt a format-specific parser, and normalize the run into standard step records (containing actions, observations, code diffs, and verification outcomes).
  2. Tree Indexing: A structuring agent converts the flat sequence of normalized steps into a Hierarchical Trace Tree. It separates simple exploration steps (e.g., reading files, running tests) from state-changing steps (e.g., modifying code). State-changing steps induce transitions to child states, making it explicitly clear whether subsequent actions were taken under a modified context.
  3. Diagnosis: A trace agent traverses the tree, ranks candidate stages using signals like verification regression and diff magnitude, and isolates the failure-responsible stage along with specific error-critical steps and supporting evidence.
Figure 1: Overview of the CODETRACER pipeline. Raw trajectories are standardized into hierarchical traces, curated into CODETRACEBENCH with step-level supervision, and diagnosed via failure onset localization with optional reflective replay.

Additionally, CodeTracer supports Reflective Replay. When an agent run fails, CodeTracer's diagnostic signal is injected back into the agent as a prefix hint, prompting it to self-correct and retry from the failure onset point.

Figure 4: Hierarchical trace tree. Exploration steps remain under the current state node, whereas state changing steps induce transitions to child states. CODETRACER builds this structure during tree indexing to provide compressed navigation of execution traces.

Datasets

To evaluate failure localization systematically, the authors constructed CodeTraceBench.

  • Source Pool: Trajectories collected across 5 prominent code generation benchmarks (including SWE-bench Verified, SWE-bench Pro, and TerminalBench).
  • Scale: It aggregates 4,354 standardized trajectories, curated into a full split of 3.32K instances and a high-quality verified split of 1.06K instances.
  • Diversity: Trajectories span 4 agent frameworks (SWE-Agent, MiniSWE-Agent, OpenHands, Terminus 2) paired with 5 frontier model backbones (Claude-3.5-Sonnet, GPT-5, DeepSeek-V3.2, Qwen3-Coder-480B, Kimi-K2-Instruct).
  • Supervision: Every trajectory features step-level annotations detailing stage boundaries, failure-critical stages, and incorrect/unuseful step labels.

Key Insights and Ideas

  • The Evidence-to-Action Gap: Trajectory analysis revealed that agents frequently gather the correct diagnostic evidence through exploration but fail to translate it into effective state-changing actions. This points to a comprehension bottleneck rather than an information-gathering failure.
  • Orchestration Overengineering: Complex agent frameworks (like SWE-Agent and OpenHands) consume up to 2× the tokens of lightweight designs (like MiniSWE-Agent) for only modest success gains (+2.4 to 5.5 percentage points). Success is primarily bounded by the underlying LLM backbone capability, not framework complexity.
  • Iteration Budget Saturation: Agent success saturates rapidly, flattening out around 40 iterations. Providing extra iterations rarely helps an agent recover from an early wrong commitment; instead, it simply amplifies unproductive looping.
  • Stage-Dependent Error Shifts: Error types are highly predictable based on the workflow phase. Environment and dependency errors concentrate early, whereas mislocalized edits and incorrect hypotheses dominate later patching and verification stages.
Figure 3: Distribution of error critical steps across stages, contrasting solved and unsolved runs.

Key Results

  • Localization Accuracy: CodeTracer substantially outperforms direct log prompting (Bare LLM) and lightweight baselines. Across frontier backbones, it achieves a macro F1 score of 46% to 48% for step-level failure localization while significantly reducing token consumption.
  • Search Strategies: Different backbones exhibit distinct diagnostic behaviors. GPT-5 terminates its search early, yielding high precision at a lower token cost, whereas Claude-3.5-Sonnet scans deeper, achieving the highest overall recall.
  • Successful Recovery via Replay: Injecting CodeTracer’s diagnostic signals back into originally failed runs consistently improved Pass@1 rates across all backbones under matched budgets (e.g., Claude improved from 41.6% to 48.3%, and GPT-5 improved from 32.6% to 38.2%).

Limitations and Future Work

  • Design Space Coverage: While the authors included a preliminary analysis of an industrial tool (Claude Code), the benchmark primarily focuses on academic agent frameworks and may not fully capture the nuances of parallel tool execution or complex industrial environments.
  • Subjectivity in Annotation: Defining labels like "incorrect," "unuseful," or "error-critical" still involves human interpretation, which can be challenging in long trajectories with intertwined exploration steps.
  • Offline Budget Constraints: The tracing and replay evaluations are conducted on pre-collected, offline runs. Future work is needed to explore how CodeTracer performs under dynamic, online human intervention or changing interactive environments.

Summary updated

BibTeX
@misc{li2026codetracer,
  author = {Han Li and Yifan Yao and Letian Zhu and Rili Feng and Hongyi Ye and Jiaming Wang and Yancheng He and Pengyu Zou and Lehan Zhang and Xinping Lei and Haoyang Huang and Ken Deng and Ming Sun and Zhaoxiang Zhang and He Ye and Jiaheng Liu},
  title = {{CodeTracer: Towards Traceable Agent States}},
  year = {2026},
  eprint = {2604.11641},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2604.11641},
}
Figure