Understanding Code Agent Behaviour: An Empirical Study of Success and Failure Trajectories

Oorja Majgaonkar, Zhiwei Fei, Xiang Li, Federica Sarro, He YearXiv 2025 · DOI

Abstract

While LLM-based code agents are increasingly successful on automated software engineering benchmarks, their internal decision-making processes remain opaque. This study performs an empirical analysis of execution trajectories from three leading agents—OpenHands, SWE-agent, and Prometheus—on the SWE-Bench benchmark. By examining step-by-step traces, we find that failures are rarely due to an inability to locate the relevant files, but rather stem from breakdowns in fine-grained reasoning and implementation. Our results highlight a "doomed" trajectory signature characterized by excessive length and variance, suggesting opportunities for compute efficiency through early stopping mechanisms.

Introduction

The rapid advancement of autonomous code agents like OpenHands and SWE-agent has led to an "arms race" on software engineering leaderboards. However, evaluation remains largely binary: did the agent fix the bug or not? This outcome-centric view ignores the rich data embedded in the agent's problem-solving process. Without understanding the trajectories—the sequence of thoughts, tool calls, and observations—researchers are left with trial-and-error optimization. This paper aims to transform these "black boxes" into "glass boxes" by analyzing why agents succeed or fail at a granular level.

Methodology

The study employs a multi-dimensional empirical approach comparing three state-of-the-art agents: OpenHands, SWE-agent, and Prometheus. The analysis is structured around three core research questions:

  1. Qualitative Deep Dives (RQ1): Manual inspection of "uniquely solved" issues to identify specific strategies across five phases: Diagnosis, Reproduction, Hypothesis, Implementation, and Verification.
  2. Structural Analysis (RQ2): Quantification of trajectory "length" by counting individual steps (Thoughts, Actions, and Results).
  3. Fault Localization Analysis (RQ3): Measurement of how accurately agents identify the "gold patch" (human-written reference fix) at the file, function, and code "hunk" levels.

The evaluation utilizes the SWE-Bench benchmark, specifically the Lite subset (300 real-world GitHub issues) and the Verified version, where human annotators have confirmed the issues are self-contained and solvable.

The "Doomed" Trajectory Signature

A key finding of the structural analysis is that failed trajectories exhibit a distinct signature. Failed attempts are consistently longer—ranging from 12% to 82% more steps than successful ones—and show significantly higher variance. When an agent begins looping or taking an excessive number of steps, it serves as a strong signal that the agent has lost its way.

Comparison of trajectory lengths (number of steps) for successful and failed attempts across three agents on SWE-Bench Lite.

This observation suggests that "early stopping" or trajectory monitoring could be implemented to terminate doomed attempts, saving significant computational resources. Interestingly, SWE-agent tends to fail "faster" than its counterparts, a desirable trait for resource efficiency.

Fault Localization and Reasoning Breakdowns

Contrary to common assumptions, agents are remarkably proficient at finding the correct file to fix, identifying it 72–81% of the time even in failed attempts. The primary bottleneck is not "coarse" navigation but "fine-grained" reasoning within the file.

As the granularity of localization increases, there is a sharp drop-off in accuracy. While approximately 95% of successful agents find the right file, only about 27% target the correct function, and a mere 5% match the exact code hunk of the human reference.

Proportion of agent actions matching the human "gold patch" at varying levels of granularity (file, function, and hunk).

The study also reveals that success does not always require matching the human "gold patch" exactly. Agents often employ "defensive programming," adding robust checks to fix symptoms even without a full architectural understanding. Only 27% of successful agent patches modified the exact same functions as the human reference, highlighting that multiple valid paths to a fix exist.

Conclusion and Future Directions

This empirical study underscores that the primary challenge for autonomous code agents lies in hunk-level localization and complex reasoning once the target file is identified. Future work should focus on building "interpretable" agents with better mechanisms to abandon unproductive paths. Improving repository-aware context gathering—a strength noted in the Prometheus agent—will be critical for understanding broader architectural patterns and moving beyond symptom-level fixes.

Summary updated

BibTeX
@misc{majgaonkar2025understanding,
  author = {Oorja Majgaonkar and Zhiwei Fei and Xiang Li and Federica Sarro and He Ye},
  title = {{Understanding Code Agent Behaviour: An Empirical Study of Success and Failure Trajectories}},
  year = {2025},
  eprint = {2511.00197},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2511.00197},
}
Figure