R339 · AI-built software and its verification › Test oracles for agent-written code

How much do coding agents over-edit? Delta Residue Attribution

Read the original

test-oraclesbenchmarkscode-reviewevalsai-built-softwareagent-harness

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.

  1. 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).

  2. 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.

  3. 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.

  4. 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.

QuestionFindingKey numbers
RQ1: how much do agents over-edit?By lines, a lot; by code necessity, no more than developers on averageMedian 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 codeSWE-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, partlyMutation 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 leftoversOnly 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 rateSWE-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 offSee the next table

Post-generation cleanup on SWE-bench Verified (paper's Table 1, under O+; units are code units):

StrategyPatches gradedPrecisionRecallNP_code before to afterStill resolving
Stop at the agent's first green test run3,031n/an/a0.700 to 0.71097.3%
Self-audit: model justifies each hunk, drops the rest6,345 (17 models)65.7%35.5%0.924 to 0.94498.2%
DRA pruning with the agent's own test command2,49539.6%66.5%0.936 to 0.97486.6%
DRA pruning with agent tests plus repo PASS_TO_PASS2,49546.3%67.3%0.936 to 0.97589.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 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

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

For reviewers of agent PRs

Sources: arXiv abstract · arXiv HTML · DAIR.AI LinkedIn post

Connections

See R339 on the knowledge map

Part of the Research notes on nowucca.com. Figures and claims are the source's own unless the summary says otherwise.