TL;DR
Bigger agent patches are mostly not bloated code: on SWE-bench Verified, the extra lines are mainly tests (61%) and docs (13%), and agent code is on average at least as necessary as developer code under the task tests (0.887 vs 0.864). The residue that remains, about 11% of an agent patch's code units, is written during the fix itself (not left over from debugging), changes behavior 89% of the time, varies a lot by model, and does not track resolve rate. Post-hoc pruning with the agent's own tests removes about two thirds of it but drops needed code more often than not (46% precision).
Source. Aakash Goel, Benjamin Steenhoek and Yu Hu (Microsoft), "How Much Do Coding Agents Over-Edit, and Why? An Empirical Study of Unneeded Edits in Repository-Level Agent Patches", arXiv 2611.34875, submitted 25 Nov 2026. Found via DAIR.AI's LinkedIn post, 26 Nov 2026.
Data. 7,660 resolved GitHub Copilot CLI trajectories from 18 models across four providers: 6,728 on SWE-bench Verified (500 Python tasks) and 932 on DeepSWE (113 long-horizon tasks in Go, TypeScript, Python, Rust and JavaScript). Developer patches graded with the same method as the baseline.
Method: Delta Residue Attribution (DRA)
DRA measures necessity by counterfactual removal, delta-debugging style, instead of by patch size or distance to a reference fix. It runs in four steps.
Replay. Re-apply the trajectory's file-edit calls to the base files with line-level blame after every step. Keep only trajectories whose replay reproduces the submitted patch exactly (96.7% on SWE-bench Verified).
Units and provenance. Split the final patch into units: contiguous changed blocks in one file (gaps of at most one unchanged line merged; a new or deleted file is one unit). Attribute each unit to the latest step that wrote or deleted any of its lines. Classify it as code, test, docs, config or nonsemantic.
Step roles. Label the introducing step debug (explore, reproduce, probe), fix (fix, refine) or cleanup. Two deterministic rules first, then an LLM judge (GPT-6.1 Sol). A second judge (Claude Opus 5.5) agreed on 84.4% of role labels (kappa 0.69) over 10,000 sampled steps.
Necessity oracle. Revert each unit alone, rerun the task tests (FAIL_TO_PASS plus PASS_TO_PASS). If the tests still pass, the unit is unneeded. Unappliable reversions count as needed.
Metric. Necessity precision NP = needed units / all units; NP_code restricts it to code units and is the headline measure. NP = 1 means the patch is 1-minimal: no single unit can be removed. Test-file edits are reported separately as ungraded, because SWE-bench resets test files before grading.
Two oracles. The plain test oracle (O_test) is weak: it calls 33% of developer code units unneeded. So every unit it calls unneeded also gets LLM-written behavioral probes (PatchDiff-style differential calls run against the agent patch, the reverted state and the developer patch). The strengthened oracle O+ also counts a unit as needed if its reversion matches the developer's behavior change; under O+ only 3% of developer code is unneeded.
Findings
Patch size overstates over-editing, but code residue is real, behavioral, model-specific and invisible to resolve rate.
| Question | Finding | Key numbers |
|---|---|---|
| RQ1: how much do agents over-edit? | By lines, a lot; by code necessity, no more than developers on average | Median model changes 2.33x the developer's lines, 1.09x outside tests, 0.86x on code units. SWE-bench Verified NP_code 0.887 vs 0.864 (developer); 11 of 18 models significantly better, 4 no difference, 3 worse (Gemini 3.6, 3.7, 3.8 Flash). DeepSWE 0.797 vs 0.785, no model significantly better than developers |
| RQ2: what are the extra edits? | On SWE-bench Verified mostly tests; on DeepSWE mostly code | SWE-bench Verified: 61% test, 21% code, 13% docs, 5% comment/format. DeepSWE: 58% code, 26% tests. 89% of unneeded code units change behavior on probes; 11% are inert guards or duplicate checks |
| RQ2: are agent tests useful? | Yes, partly | Mutation testing (1,962 mutants, 271 instances): agent-added tests catch 68.1% vs 45.6% for existing regression tests and 77.1% for task tests. They catch 22.7% of mutants the task tests miss (5.2% of all mutants). Most are written after the fix |
| RQ3: where does residue come from? | The fix, not debugging leftovers | Only 154 of 3,987 unneeded code units come from debug steps (rho_code 0.039). Fix steps write 83%, revisions 11%. Revision code is unneeded only slightly more often (0.29 vs 0.25) |
| RQ4: which models over-edit? | Strongly model-dependent, unrelated to resolve rate | SWE-bench Verified Spearman -0.10 (p 0.69). Sonnet 5 (80.6% resolve) NP_code 0.922 vs Gemini 3.7 Flash (81.4%) 0.789: 3.6x as many unneeded code units per task (1.23 vs 0.34). DeepSWE: -0.59 (p 0.01), so stronger models leave more residue |
| RQ5: can it be removed automatically? | Partly; precision and recall trade off | See the next table |
Post-generation cleanup on SWE-bench Verified (paper's Table 1, under O+; units are code units):
| Strategy | Patches graded | Precision | Recall | NP_code before to after | Still resolving |
|---|---|---|---|---|---|
| Stop at the agent's first green test run | 3,031 | n/a | n/a | 0.700 to 0.710 | 97.3% |
| Self-audit: model justifies each hunk, drops the rest | 6,345 (17 models) | 65.7% | 35.5% | 0.924 to 0.944 | 98.2% |
| DRA pruning with the agent's own test command | 2,495 | 39.6% | 66.5% | 0.936 to 0.974 | 86.6% |
| DRA pruning with agent tests plus repo PASS_TO_PASS | 2,495 | 46.3% | 67.3% | 0.936 to 0.975 | 89.1% |
Pruning applies to only 2,495 of 6,724 patches: the rest have no standalone test command or fail the baseline check. Early stopping does little because most residue is already in the patch when the agent's tests first pass. Most false drops are code implementing behavior no test exercises.
Checking the post against the paper
Every number in DAIR.AI's post matches the paper, and the Microsoft attribution is correct. Three omissions change how the result should be read.
The headline depends on the oracle. "At least as necessary as developer code" holds under the plain test oracle. Under the strengthened oracle O+, the agent-minus-developer gap on SWE-bench Verified flips from +2.3 to -4.5 percentage points, meaning agents leave more unneeded code than developers. The paper states this in RQ1; the post does not.
Pruning removes needed code too. The post says pruning with visible tests "removed most of the unneeded code" and 89% of patches still resolved. True, but precision is 46.3%: more than half of what it drops was needed. It also only applied to 2,495 of 6,724 patches. Self-audit is the opposite trade (65.7% precision, 35.5% recall).
One harness, resolved patches only. All main results come from GitHub Copilot CLI and only from trajectories that resolved the task. Over-editing in failed attempts is not studied.
The post also leaves out the most actionable finding: debug scaffolding almost never survives into the patch (3.9% of code residue), so in-loop cleanup has little to remove.
Tradeoffs, failure modes and limits
Necessity is only as good as the oracle. Tests that don't exercise a behavior make the code for it look unneeded. That is why O_test flags 33% of developer code. Treat "unneeded" as an upper bound on true excess, not a delete list.
One-at-a-time reversion misses joint dependencies. Two units that are each removable alone may not be removable together, and mixed blocks (part needed, part not) are graded as one.
LLM-built judgment in the loop. Role labels and behavioral probes are both GPT-6.1 Sol, validated only against a second LLM judge, with no human audit yet.
Provenance needs exact replay. 3.3% of SWE-bench Verified trajectories and 14.9% of DeepSWE units lack provenance. Harnesses that edit files through shell commands rather than structured edit calls would be harder to replay.
Contamination and scope. SWE-bench Verified is Python-only and may be in training data. DeepSWE results carry wider uncertainty (17 models with at least 10 graded tasks).
Validity check is moderate. The DRA unneeded flag predicts code outside every function the developer touched with AUROC 0.718, against 0.478 for unit size, but fewer than half of flagged units (precision 0.43) fall outside the developer's functions. Whether a reviewer would delete flagged code is untested.
Cost. DRA reruns the task tests once per unit, plus probe scripts per unneeded code unit. That is cheap on unit-test suites and expensive on slow integration suites.
What to do with it
The residue is written into the fix, so the lever is model choice, training and post-generation checks, not a "clean up your debug prints" prompt.
For harness builders
Measure code necessity per model on your own tasks, next to resolve rate. Model choice moved unneeded code 3.6x at equal resolve rates.
Grade test edits and code edits separately. Counting tests as bloat punishes the behavior you want.
If you prune, prune against agent tests plus existing regression tests, and surface drops as suggestions to a reviewer rather than applying them silently (46% precision).
Use self-audit ("justify every hunk") as a cheap, safe first pass: it rarely breaks a patch (1.8%) but finds only about a third.
Keep agent-written tests: they caught 22.7% of the mutants the task tests missed. Ask for them before the fix, since most were written after.
For fine-tuning on your own trajectories, drop units the tests don't need before training (the paper's "debloating" recommendation).
For reviewers of agent PRs
Don't skim the extra code: 89% of unneeded code units change behavior on nearby inputs (swallowed or newly raised exceptions are the cited example).
Look for changes outside the functions the issue names; that is the signal DRA tracks best.
Ask which hunks the tests require. A hunk no test needs either lacks a test or should go.
Related entries and sources
R270 shrink-anything: the same keep-the-cut-only-if-tests-pass loop, applied to dead code. This paper measures how often that kind of cut is wrong (46% precision with agent tests).
R266 small-change (Will Larson): a build-owned check for small diffs. DRA's necessity is a sharper signal than size, which this paper shows misleads.
R182 How the Claude Code team verifies agent-written code: reviewer-side verification; this paper says what to look for in the extra code.
R224 BuggyMLE: injected-bug evaluation, the same mutation idea used here to grade agent-written tests.
R113 TokenEconomizer (Microsoft Research): another measure of agent waste beyond resolve rate.
Sources: arXiv abstract · arXiv HTML · DAIR.AI LinkedIn post