TRIM: Reducing AI-Generated CodeSlop via Agent Trajectory Minimization
Alex Mathai, Shobini Iyer, Aleksandr Nogikh, Petros Maniatis, Franjo Ivancic, Junfeng Yang, Baishakhi Ray
Abstract
Coding agents are increasingly used to accelerate code generation in many downstream tasks, such as fixing bugs, building applications, and prototyping. However, despite their value as coding assistants, agent-generated code tends to be larger and more verbose than the corresponding human-written implementation. In this work, we show that the cause lies in the agent's own search process: while iterating toward a passing solution, an agent accumulates speculative edits, abandoned hypotheses, and temporary changes that persist into the final patch. This may seem harmless for a single patch, but the problem compounds as agents take responsibility for ever-larger portions of a codebase-a codebase that was once minimal and well-maintained slowly accumulates redundancy faster than it can be cleaned up, drifting to a state that is harder to maintain. Given the magnitude of this problem, we take a step towards alleviating this issue. First, we formally define this phenomenon as CodeSlop-the residual and functionally unnecessary edits commonly seen in AI-generated code. We then introduce our algorithm TRIM (Trajectory-guided Redundancy Identification and Minimization). Rather than minimizing CodeSlop directly, TRIM instead minimizes agent trajectories. As we show empirically, this indirect technique of minimizing CodeSlop is highly effective: TRIM cuts CodeSlop by 17.9%-32.9% across agentic scaffolds, with negligible performance regression. TRIM is also highly efficient, requiring roughly half the validation cost of algorithmic baselines such as Delta Debugging.
Create a lesson
Metadata
- Categories
- cs.SE, cs.AI, cs.OS
Related papers
AI-Generated Code Issues: A Taxonomy from Repository Histories, AI Conversations, and Developer Interviews
Shared title terminologycs.SERosalia Tufano, Nargiz Humbatova, Daniele Bifolco et al.
Validating Multi-Model AI-Generated Acceptance Criteria in Requirements Engineering
Shared title terminologycs.SEMateen Ahmed Abbasi, Petri Ihantola, Tommi Mikkonen et al.
Agent Trajectories as Evidence for Software Quality Assurance
Shared title terminologycs.SEJonathan Ullrich, Julien Siebert, Michael Kläs et al.
How Do Developers Edit AI-Generated Code, and How Well Do LLMs Infer Their Edits? Insights from 53.6K Developer Edits
Shared title terminologycs.SEJenny T. Liang, Mihika Bairathi, Wayne Chi et al.
The Influence of Fraudulent AI-Generated Responses on Software Engineering Surveys
Shared title terminologycs.SERonnie de Souza Santos, Italo Santos, Maria Teresa Baldassarre et al.
CAM: A Causality-based Analysis Framework for Multi-Agent Code Generation Systems
Shared title terminologycs.SEZongyi Lyu, Zhenlan Ji, Songqiang Chen et al.