TRIM: Reducing AI-Generated CodeSlop via Agent Trajectory Minimization

Alex Mathai, Shobini Iyer, Aleksandr Nogikh, Petros Maniatis, Franjo Ivancic, Junfeng Yang, Baishakhi RayarXiv 2026

TL;DR

AI coding agents are highly effective at fixing bugs, but they often leave behind a messy trail of speculative, redundant edits—a phenomenon the authors term "CodeSlop." This paper introduces TRIM, an algorithm that leverages an agent's historical repair trajectory to efficiently prune away these unnecessary changes. TRIM reduces CodeSlop by up to 33% across various agent frameworks while cutting the computational validation cost of traditional debugging baselines in half.

What Problem Does This Paper Address?

When AI coding agents work on a software bug, they rarely write the perfect fix on the first try. Instead, they iterate: they add temporary print statements, test speculative hypotheses, and make exploratory modifications. Once the test suite finally passes, the agent stops. Crucially, however, it often retains all those intermediate, exploratory edits in the final patch because it has no incentive to clean them up.

The authors formalize this residual, functionally useless code as CODESLOP (removable functional redundancy). While a bloated patch might technically pass tests, it introduces significant cognitive overhead for human developers reviewing the pull request and degrades long-term codebase maintainability.

Existing program-minimization tools (like Delta Debugging) treat the final patch as an unstructured collection of changes, making the search for redundant code computationally expensive. Meanwhile, simply prompting an LLM to "clean up its own code" is unreliable, frequently breaking functionality or even inflating the patch size further.

Fig. 2: The task of minimizing CODESLOP. The horizontal line measures patch length. On the left is the minimal behavior- preserving patch (AP∗) and on the right is the original verbose agent patch (AP). In the middle is the minimized patch (MP). To minimize CODESLOP and patch length, we move MP closer to AP∗and further away from AP.

Methods

The core insight of this paper is that an agent's repair trajectory—the chronological history of its edits and test feedbacks—contains implicit structural information about code dependencies.

Instead of searching blindly across all possible subsets of a final patch, the authors introduce TRIM (Trajectory-guided Redundancy Identification and Minimization). TRIM executes a hierarchical counterfactual search that progressively refines its focus from coarse to fine granularities:

  1. Edit Sequences: TRIM groups edits made between consecutive test runs and checks if an entire sequence can be safely removed.
  2. Files: It groups remaining edits by file, testing if all changes to a specific file are redundant.
  3. Atomic Edit Actions: Finally, it evaluates individual edit actions one by one.
Overview of the TRIM framework, from trajectory preprocessing to hierarchical minimization and final evaluation.

By eliminating large groups of exploratory edits early in the process, TRIM rapidly shrinks the search space. The authors evaluate two variants: TRIM-G, which guarantees a "one-minimal" patch by repeating the search until no more edits can be removed, and TRIM-NG, a faster version that completes the search in a single pass.

Datasets

The authors evaluated TRIM across two major benchmarks using four state-of-the-art agent scaffolds (CRASHFIXER, SWE AGENT, MINISWE AGENT, and OPENHANDS):

  • Live-kBench: A benchmark consisting of 534 recent Linux kernel vulnerabilities. This dataset focuses on security-critical C code, where keeping patches minimal is vital to reducing the software's attack surface.
  • SWE-Bench-Verified: A subset of 500 manually verified real-world GitHub issues from popular Python repositories, representing general-purpose software engineering tasks.

Key Insights and Ideas

  • Slop is Behavioral, Not Just Static: Traditional definitions of code slop rely on static metrics like verbosity or duplication. The authors redefine CodeSlop functionally: code can be perfectly clean and readable, but if it isn't strictly necessary to solve the problem, it's slop.
  • Trajectories as a Search Map: An agent's history isn't just junk data; it's a map of its reasoning. Exploiting the temporal order of edits allows TRIM to bypass the exponential search space that makes standard delta-debugging tools slow.
  • Minimization is a Search Problem, Not a Generation Problem: LLMs fail to minimize their own patches via prompting in 3.8% to 44.9% of cases. Stripping away redundancy is far more reliably handled by structured, deterministic counterfactual execution than by generative rewriting.

Key Results

  • Substantial CodeSlop Reduction: TRIM successfully reduced CODESLOP by 17.9% to 32.9% across all evaluated agent frameworks.
  • Twice as Fast as Delta Debugging: TRIM achieved identical minimization quality to Delta Debugging (DD-Hunk) but required 1.9× fewer validation executions, drastically bounding the worst-case compute time.
  • Maintained (or Improved) Correctness: TRIM introduced negligible regressions against hidden oracle tests. Remarkably, for the CRASHFIXER agent, TRIM actually improved oracle correctness by 1.0%–2.6% because removing the agent's messy exploration brought the final patches into exact agreement with clean, human-written developer fixes.

Limitations and Future Work

  • Atomic Edit Granularity: TRIM's smallest unit of removal is an individual edit action. If an agent introduces redundancy within a single multi-line edit command, TRIM cannot dissect it further.
  • Test Suite Gaps: TRIM relies on the agent's test suite as its correctness signal. If the test suite lacks coverage, TRIM might inadvertently prune code designed to handle untested edge cases.
  • Post-Processing Bottleneck: Currently, TRIM operates as a post-processing step after a successful repair. A promising future direction is integrating trajectory minimization directly into the agent's execution loop, preventing agents from getting bogged down by their own accumulated slop during long-horizon tasks.

Summary updated

BibTeX
@misc{mathai2026trim,
  author = {Alex Mathai and Shobini Iyer and Aleksandr Nogikh and Petros Maniatis and Franjo Ivancic and Junfeng Yang and Baishakhi Ray},
  title = {{TRIM: Reducing AI-Generated CodeSlop via Agent Trajectory Minimization}},
  year = {2026},
  eprint = {2607.18161},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2607.18161},
}
Figure