Coherence Collapse: Diagnosing Why Code Agents Fail After Reaching the Right Code

Myeongsoo Kim, Dingmin Wang, Siwei Cui, Farima Farmahinifarahani, Terry Yue Zhuo, Shweta Garg, Baishakhi Ray, Rajdeep Mukherjee, Varun KumararXiv 2026

TL;DR

AI code agents often fail not because they can't find the buggy code, but because they find it, fix it (or get incredibly close), and then completely ruin it later in their execution trace—a phenomenon termed Coherence Collapse. By introducing TRAJEVAL, a framework that breaks down agent trajectories into distinct stages, this paper reveals that 60–69% of capable model failures are due to edit-quality issues rather than localization errors, opening up new avenues for process-based interventions.

What Problem Does This Paper Address?

While state-of-the-art AI code agents can now resolve 65–70% of software engineering issues on benchmarks like SWE-bench, our evaluation toolkit remains almost entirely outcome-based (e.g., Pass@1). This binary success/failure metric acts as a black box: it conceals exactly where and why an agent's reasoning derailed.

The prevailing assumption has been that agents fail primarily because they get lost in large codebases (localization errors). However, without analyzing the step-by-step tool-use trajectories, these failures are systematically misdiagnosed. This paper addresses this gap by providing a process-level diagnostic lens to pinpoint exactly when an agent loses its way.

Methods

The authors introduce TRAJEVAL, a training-free, architecture-agnostic diagnostic framework. It automatically decomposes an agent's unstructured execution trace into three reference-patch-aligned stages:

  1. Search (File-Level): Quantifies the agent's ability to locate the correct files.
  2. Read (Function-Level): Measures whether the agent actually inspects the buggy function bodies within those files.
  3. Edit (Function-Level): Evaluates the precision and recall of the agent's code modifications against the ground-truth "gold" reference patch.
Figure 1: Overview of TRAJEVAL. Each agent execution trace is automatically decomposed into three stages— search (file-level), read (function-level), and edit (function-level)—and compared against the reference patch to yield stage-wise precision and recall.

By comparing the agent's actions against the precise specification of the reference patch, TRAJEVAL calculates stage-wise precision and recall.

The authors also test two actionable interventions derived from their findings:

  • Edit-Commit Checkpointing: Freezing intermediate code states if they pass the existing test suite to prevent subsequent corruption.
  • Parallel-Sample Consensus: A reference-free method that aggregates file-viewing agreements across multiple independent model runs to simulate confirmatory feedback.

Datasets

The framework was evaluated at scale across 16,758 trajectories spanning three agent architectures (SWE-Agent, OpenHands, and LiveSWEAgent) and seven language models (including the GPT-5 family and Qwen3 variants). The benchmarks used were:

  • SWE-bench Verified: 500 human-verified real-world GitHub issues from 12 Python repositories.
  • PolyBench Verified: A newly introduced multilingual benchmark containing 382 instances across Python, Java, JavaScript, and TypeScript from 20 repositories.

Key Insights and Ideas

  • Localization is Not the Bottleneck: For capable models, the primary failure mode is not finding the code. Instead, 60–69% of failures fall into the "Edit-Quality" residual—meaning the agent successfully navigated to and edited the correct functions but still produced an incorrect final patch.
  • Coherence Collapse Defined: Within these edit-quality failures, the dominant pattern is Coherence Collapse. The agent successfully reaches the correct code region but later abandons, overwrites, or thrashes its own progress.
Taxonomy of Edit-Quality failures
  • Not Just Long-Context Fatigue: While one sub-type ("Confused Thrashing") scales with trajectory length, another major sub-type ("Near-Correct Corrupted") is entirely length-independent. This proves that Coherence Collapse is a fundamental reasoning or overconfidence issue, not simply context-window degradation.

Key Results

  • Dominance of Edit-Quality Failures: Across five capable models on SWE-Agent and OpenHands, 64–69% of failures occurred in the Edit-Quality stage. Conversely, weaker models (like Qwen3-8B) remained heavily bottlenecked by upstream Search and localization.
Table 1: Failure-mode distribution among failed trajec- tories (Pass@1 = 0), SWE-Agent. Buckets are mutually exclusive and exhaustive; each row sums to 100%. n counts failed trajectories for which all six stage features could be extracted; trajectories where the agent termi- nated before producing parseable observations or edits are excluded, most strongly affecting weaker models.
  • The "Tragic" 5 Cases: In 5 distinct trajectories, the agent generated a patch bit-identical to the gold reference mid-trajectory, only to delete or overwrite it later. Implementing an edit-commit checkpoint successfully recovered all 5 cases against the SWE-bench Docker harness.
  • Cross-Language Replication: Coherence Collapse isn't a Python quirk. It represented the largest failure theme on the multilingual PolyBench Verified dataset (32.3% overall), peaking at 42.1% in JavaScript and 36.3% in Java.
  • Consensus-Driven Boost: Using the reference-free parallel-sample consensus (CONS3) to provide feedback yielded a directional +3.0 percentage point lift in Pass@1 on GPT-5 (moving from 66.0% to 69.0%).

Limitations and Future Work

  • Reference-Patch Dependence: For evaluation, TRAJEVAL requires a ground-truth reference patch, meaning it cannot be used as a real-time metric during live deployment.
  • Localization-Only Focus: TRAJEVAL captures where an agent operates, not the semantic correctness of the code logic itself. Two completely different patches to the same function receive identical metrics.
  • Scaffold Constraints: The detailed sub-type taxonomy for Edit-Quality failures was computed exclusively on the SWE-Agent scaffold; replicating this taxonomy on OpenHands and LiveSWEAgent remains future work.

Summary updated

BibTeX
@misc{kim2026coherence,
  author = {Myeongsoo Kim and Dingmin Wang and Siwei Cui and Farima Farmahinifarahani and Terry Yue Zhuo and Shweta Garg and Baishakhi Ray and Rajdeep Mukherjee and Varun Kumar},
  title = {{Coherence Collapse: Diagnosing Why Code Agents Fail After Reaching the Right Code}},
  year = {2026},
  eprint = {2603.24631},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2603.24631},
}
Figure