TRIM: Reducing AI-Generated CodeSlop via Agent Trajectory Minimization

2026-07-21

Authors: Alex Mathai, Shobini Iyer, Aleksandr Nogikh, Petros Maniatis

ArXiv: 2607.18161v1

PDF: Download PDF

If you've ever used a coding agent to fix a bug or build a feature, you may have noticed something odd: the diff it produces is often huge. Where a human might change 10 lines, the agent changes 80 — with extra helper functions, defensive try/except blocks, logging statements, and comments explaining what the code obviously does. The tests pass, but the pull request looks bloated. The authors of TRIM call this "CodeSlop", and this paper is about where it comes from and how to get rid of it.

Their key insight is that CodeSlop isn't really a problem with how the agent writes code — it's a problem with how it searches for a solution. When a coding agent is grinding toward a passing test, it makes lots of speculative edits along the way: it adds a helper it thinks it might need, tries a defensive check, guesses at an edge case, changes its mind, tries something else. When a test finally passes, the agent stops. But all those speculative additions from earlier in the trajectory are still sitting in the final diff, even though many of them aren't actually necessary for the fix.

TRIM's approach is refreshingly direct: after the agent finishes, take the final diff and try to remove pieces of it. For each addition, ask, "Do the tests still pass without this?" If yes, drop it. If no, keep it. It's essentially delta debugging applied to agent output — the same technique used to minimize failing test cases, but pointed at the reverse problem of minimizing succeeding ones.

The results, per the abstract, show meaningful reductions in diff size while preserving correctness. A few things this unlocks:

The broader lesson is that agent outputs shouldn't be treated as final products. There's a post-processing step available — verify-then-shrink — that most agent frameworks skip because they stop as soon as the green checkmark appears. TRIM argues that's exactly the wrong stopping point.

Why it matters: As coding agents ship more real PRs, the difference between "tests pass" and "code is actually good" becomes a first-class engineering problem — and post-hoc minimization is a surprisingly cheap fix.

All newsletters