- The paper introduces TRIM, a trajectory-guided counterfactual search that removes unnecessary edit sequences, files, and actions while preserving test-passing repairs.
- TRIM-G removes 17.9%–32.9% of CodeSlop across four coding-agent scaffolds, with negligible correctness loss and up to 32.9% reduction on CrashFixer.
- TRIM matches Delta Debugging’s minimization quality while using about half as many validations, and generalizes to SWE-Bench-Verified with 99.1% hidden-oracle correctness.
Motivation and problem
Coding agents produce patches that pass their tests but are systematically larger than necessary. The authors observe that the root cause lies in the agent's own search process: while iterating toward a passing repair, an agent accumulates speculative edits, abandoned hypotheses, and temporary changes that persist into the final patch because the agent has no incentive to remove them once validation succeeds. In a motivating Linux kernel memory-leak fix, SWE Agent produces 21 changed lines across three feedback cycles, yet only three lines—coinciding exactly with the developer-written fix—are required.
The paper formalizes this phenomenon as CodeSlop: the residual, functionally unnecessary edits in an agent-generated patch. Crucially, the definition is behavioral rather than static: CodeSlop is the set of modifications removable while preserving the successful repair, i.e., len(AP)−len(AP∗), where AP∗ is the minimal behavior-preserving patch derivable from AP. This distinguishes it from prior "slop" characterizations based on verbosity, duplication, or complexity of surviving code—a removable edit may be perfectly clean code, and eroded but irreducible code is not slop under this definition. Patch Minimization is then posed as recovering AP∗, an exponential (2n) subset-search problem approximated via test-suite execution.
A notable negative result motivates the algorithmic approach: prompting agents to minimize their own patches fails outright or inflates the patch in 3.8%–44.9% of cases, indicating that minimization is not something current agents can reliably do by generation alone.
The TRIM algorithm
TRIM (Trajectory-guided Redundancy Identification and Minimization) shifts the search space from the final patch to the agent's repair trajectory. The trajectory is reduced to pairs (Ei,FRi) of edit sequences and feedback requests; edits later reverted or overwritten are removed by replaying the trajectory in temporal order, and heterogeneous editing primitives are normalized into file/before/after representations.
Minimization proceeds as a hierarchical counterfactual search over three granularities: edit sequence → file → individual edit action. At each level, candidate units are traversed in reverse trajectory order and temporarily removed; a removal is accepted only if the counterfactual patch still passes the task-specific test suite TF and strictly shrinks the patch. Because each accepted removal preserves validity, the algorithm maintains a correct patch throughout, exposing a natural cost–quality trade-off: users may stop after sequence-level (~0.9k validations, 11.3% Slop on CrashFixer), hybrid, or full edit-level search (~2.6k validations, 32.9% Slop).
Two variants are analyzed. TRIM-G repeats each phase to a fixpoint, guaranteeing one-minimality at worst-case quadratic cost in the number of edits; TRIM-NG performs a single pass per granularity with linear cost. Empirically the gap is small: TRIM-NG achieves nearly identical Slop (32.0% vs. 32.9%), identical average edits per patch (1.35), and identical output for 96.4% of trajectories, at ~8% lower cost.
The key efficiency claim relative to Delta Debugging is structural: trajectories group dependent edits according to the agent's exploratory hypotheses, so eliminating whole groups first prunes large portions of the search space without rediscovering dependencies through exhaustive hunk-subset testing.
Evaluation
The evaluation spans four scaffolds (CrashFixer, SWE Agent, MiniSWE Agent, OpenHands) over Live-kBench (534 recent Linux kernel vulnerabilities; 293 non-trivially-minimal repairs) and SWE-Bench-Verified (333 verified SWE Agent trajectories), totaling 4,544 repair trajectories generated with models including Gemini-3-Pro and Claude-Opus-4.5.
Effectiveness (RQ1). Full edit-level TRIM-G removes 17.9%–32.9% of CodeSlop across scaffolds (CrashFixer 32.9%, MiniSWE Agent 26%, OpenHands 26.6%, SWE Agent 17.9%), with negligible oracle regression—at most ~1% drop for OpenHands—and a 1.0–2.6% improvement for CrashFixer. The hierarchy is validated empirically: sequence-level < hybrid < edit-level reduction consistently.
Against agentic baselines (RQ2). Prompting Gemini-3-Flash (or Sonnet 4.6) to minimize its own patch yields only 2.1%–13.4% Slop across configurations, and agentic runs fail in 3.8%–44.9% of cases due to anomalies, file mismatches, bug reintroduction, or patch inflation. Even counting failures conservatively as zero minimization, TRIM achieves a 1.6×–3.1× improvement. The authors draw a strong conclusion from this: patch minimization is fundamentally a search problem rather than a generation problem.
Against deterministic baselines (RQ3). A hunk-adapted Delta Debugging baseline (DD-Hunk) reaches statistically equivalent Slop (31.5% vs. 32.9%; difference of +0.24 lines, 95% CI [−0.4, +0.9], p=0.50) but requires ~5.2k kernel validations versus TRIM's ~2.6k—a 1.9× cost reduction. TRIM also bounds worst-case cost far more tightly: at most 16 validations per bug versus DD-Hunk's 43, which matters when each kernel validation takes ~30 minutes.
Generalization (RQ4). On SWE-Bench-Verified, with only trajectory preprocessing adapted, TRIM removes 20.0% of modified-file lines (23.6% of edit actions, 17.8% of hunks), preserving hidden-oracle correctness for 327/330 (99.1%) repairs and transforming 18 patches into exact agreement with the developer-written solution. Minimization also reduces static slop metrics: 66% of AP-introduced verbosity is removed overall, including 100% of scratch reproduction scripts and 51% of test-file verbosity. Notably, scratch repro scripts and build/config files account for 85.4% of removed lines, indicating that much agent slop consists of scaffolding artifacts rather than source-code churn.
Limitations and open questions
The paper is candid about several constraints. TRIM's smallest removable unit is the atomic edit action, so redundancy within an edit cannot be eliminated, making reported Slop a conservative lower bound. Correctness rests entirely on AP∗0 as a proxy for behavior preservation; untested regressions may pass undetected, though observed oracle regressions are rare (3/330 on SWE-Bench, ≤~1% on Live-kBench). On Live-kBench, semantic equivalence is judged by an LLM (Gemini-3-Flash with nine-vote majority), whose bias may affect absolute numbers. Externally, both benchmarks involve well-defined test suites; domains with different trajectory structures or weaker validation signals remain untested. An open question the results raise but do not answer is whether trajectory structure remains informative for agents whose editing patterns differ substantially from the four scaffolds studied, and whether minimization could be integrated into the agent loop itself rather than applied post hoc.
Conclusion
This paper contributes a behavioral formalization of CodeSlop as removable functional redundancy, and demonstrates that the agent's repair trajectory supplies sufficient dependency structure to make patch minimization efficient. TRIM removes up to 32.9% of unnecessary edits across four scaffolds with negligible correctness loss, matches Delta Debugging's quality at roughly half the validation cost, and generalizes from kernel security repair to repository-level repair. Its central empirical claim—that structured counterfactual search over trajectories outperforms both LLM self-revision and unstructured delta debugging for this task—is well supported by the reported evidence.