Skip to content

TRIM: Reducing AI-Generated CodeSlop via Agent Trajectory Minimization

🕒 Published (v1): 2026-07-20 17:06 UTC · Source: Arxiv · link

Why this paper was selected

Google team; agent trajectory minimization to cut codeslop; novel objective for coding agent harnesses

Ask a follow-up

Open an assistant pre-loaded with this paper's context.

💬 Ask ChatGPT✦ Ask Claude

TL;DR

TRIM introduces CodeSlop—a formal, behavioral definition of functionally removable residual edits in agent-generated patches—and an algorithm that minimizes agent repair trajectories rather than the patch itself to efficiently prune this redundancy. Evaluated across four coding-agent scaffolds, TRIM cuts CodeSlop by 17.8%–32.9% with negligible correctness regression and roughly half the validation cost of Delta Debugging.

Problem

Coding agents iteratively explore a repair space; once a passing solution is found, speculative edits, abandoned hypotheses, and temporary changes persist in the final patch because the agent has no incentive to remove them. Existing code-quality metrics (verbosity, duplication, structural complexity) use static properties, but a change may be stylistically clean and still be removable without affecting behavior. No prior work formally defined this redundancy or provided a trajectory-aware method to eliminate it at scale.

Method

TRIM reformulates patch minimization as hierarchical counterfactual search over the agent's repair trajectory rather than the final patch. Given an execution trajectory \(\text{Traj}\), TRIM first reduces it to \(\text{TrajR} = \langle (E_1, \text{FR}_1), \ldots, (E_k, \text{FR}_k) \rangle\), retaining only atomic edit actions \(e_{ij}\) and feedback requests (test executions); all repository navigation and non-modifying actions are discarded. It then searches coarse-to-fine across three granularities—edit sequences \(E_i\), per-file edits within sequences, and individual atomic actions \(e_{ij}\)—removing a group and validating via test execution; the removal is accepted only if the resulting candidate patch still passes and \(\text{len}(\text{MP}) \leq \text{len}(\text{AP})\). The measure of reduction is \(\Delta\text{SLOP} = \text{len}(\text{AP}) - \text{len}(\text{MP})\), approximating the ideal \(\text{CodeSlop}(\text{AP}) = \text{len}(\text{AP}) - \text{len}(\text{AP}^*)\) where \(\text{AP}^* = \arg\min_{\text{MP} \in D(\text{AP},T)} \text{len}(\text{MP})\). A TRIM-G variant enforces 1-minimality; TRIM-NG omits that guarantee for speed.

Key Contributions

  • First functional (behavioral) definition of CodeSlop as \(\text{len}(\text{AP}) - \text{len}(\text{AP}^*)\), distinct from static verbosity metrics.
  • TRIM algorithm: trajectory-aware, coarse-to-fine hierarchical counterfactual search that exploits the temporal grouping of edits by feedback cycle.
  • Normalization layer that unifies heterogeneous agent editing primitives (shell sed, structured replace tools, etc.) into a common before/after-text representation for scaffold-agnostic operation.
  • Empirical demonstration across four scaffolds and two benchmarks that substantial CodeSlop is consistently present and reducible.

Results

  • CodeSlop reduction of 17.8%–32.9% across CRASHFIXER, SWEAGENT, MINISWEAGENT, and OPENHANDS on Live-kBench and SWE-Bench.
  • 1.6×–3.1Ă— improvement in CodeSlop reduction over agent-based self-minimization baselines (which fail or inflate 3.8%–44.9% of the time).
  • Requires roughly half the validation calls of Delta Debugging (the primary algorithmic baseline).
  • In some cases, minimized patches reach exact agreement with the developer-written patch.

Limitations

  • Approximates \(\text{AP}^*\) via test-suite validation; true behavioral equivalence is unobservable, so CodeSlop is under-measured when tests are incomplete.
  • Search space is restricted to patches derivable from \(\text{AP}\); TRIM cannot synthesize a shorter correct patch that diverges from the agent's chosen solution.
  • Trajectory availability is assumed; scaffolds that do not expose structured execution logs require additional instrumentation.
  • Coarse-to-fine ordering affects convergence speed; adversarial orderings could increase validation cost beyond the reported averages.
  • Evaluation limited to program-repair tasks; generalization to agentic coding tasks without iterative test-feedback loops (e.g., feature development) is unvalidated.

Relevance to Harnesses / Meta-Harnesses

TRIM is architecturally a post-processing meta-harness: it wraps any agent scaffold, intercepts the execution trajectory and final patch, and applies an independent minimization pass without modifying the underlying agent. This is a canonical meta-harness design pattern—scaffold-agnostic orchestration that improves output quality by operating on the agent's recorded behavior rather than its internals. The trajectory reconstruction stage (filtering, normalizing, and structuring raw agent logs) is directly analogous to the preprocessing layer found in agent harnesses that extract structured signals from unstructured agent telemetry. For researchers tracking harness design, TRIM demonstrates that trajectory-level metadata is a first-class resource for quality control, and that hierarchical counterfactual search is a viable harness-side strategy for reducing artifact bloat produced by iterative agentic loops.