Delta Residue Attribution (DRA)
- Delta Residue Attribution (DRA) is a method to determine the necessity of units in AI-generated software patches, focusing on necessity rather than patch size, comparing to developer patches for evaluation.
- DRA utilizes a counterfactual method to trace back and revert each patch component, noting when and by which agent step the patch unit was introduced, offering insights into patch provenance and necessity
- Applications demonstrate the ability of DRA to improve patch minimalization and quality by comparing model-generated and developer patches from datasets such as SWE-bench and DeepSWE
Delta Residue Attribution (DRA) is a counterfactual method for determining which units of an agent-generated software patch are necessary for satisfying a task oracle and which units constitute unnecessary residue. It replays an agent trajectory, traces final patch units to the trajectory steps that wrote them, reverts each unit independently, and reruns task tests to determine whether the unit is required. DRA consequently measures necessity and provenance rather than patch size or similarity to a developer patch. It was introduced for empirical analysis of over-editing in coding-agent patches (Goel et al., 25 Nov 2026).
1. Conceptual basis and scope
DRA addresses the distinction between edit volume and edit necessity. A large patch may contain useful tests, documentation, or behaviorally necessary code, whereas a small patch may introduce an unnecessary behavioral change. Likewise, disagreement with a developer patch does not imply that an agent patch is incorrect, because multiple valid implementations may exist.
The method separates three questions:
- Patch composition: what did the agent change?
- Counterfactual necessity: which changes are required by the selected task oracle?
- Trajectory provenance: when, and during which type of agent step, was each change introduced?
DRA is inspired by delta debugging. Each independently revertible unit is removed from the final patch, and the resulting repository state is tested against an oracle. A unit is therefore classified as unnecessary only when its removal preserves oracle acceptance. The method does not define unnecessary code as code absent from the developer patch, nor does it equate unnecessary code with dead text.
The principal application studies GitHub Copilot CLI trajectories from 18 frontier models on SWE-bench Verified and DeepSWE. The dataset contains 7,660 resolved trajectories: 6,728 from SWE-bench Verified and 932 from DeepSWE. Developer patches are graded using the same unitization and task-test methodology, providing a comparative baseline (Goel et al., 25 Nov 2026).
DRA is an instance of a broader family of delta-based attribution methods, but its defining object is patch-unit necessity under a specified oracle. This distinguishes it from attribution of prediction changes, hidden-state residuals, predicate-level Shapley deltas, or finite response-score differences. For example, predicate-level SHAPLEY_DELTA computes the change in an aggregate attribution between consecutive windows, while DRA evaluates whether removing a patch unit changes task-test behavior (Khani et al., 27 Aug 2026). Similarly, finite signed attribution methods such as DeltaTrace distribute a measured output difference across input tokens, whereas DRA assigns a binary necessity judgment to repository modifications (Liang et al., 19 Oct 2026).
2. Formal definitions
An agent trajectory is represented as a sequence of actions and observations,
Executing the first actions on the task’s base repository produces a working-tree state . The final submitted patch is
where is the base state and is the final state.
DRA decomposes the final patch into independently revertible units,
A unit is normally a contiguous block of changed lines within one file. Blocks separated by at most one unchanged line are merged. A created or deleted file is treated as one unit. Units are classified as code, test, documentation, configuration, or nonsemantic changes such as comments, docstrings, or formatting.
For a repository state , an oracle is a binary function
The principal oracle is the task-test oracle , which runs the SWE-bench FAIL_TO_PASS and PASS_TO_PASS tests, or the task’s own tests on DeepSWE. All analyzed final patches satisfy
Let denote the final state with unit reverted to its base-state contents. Unit necessity is defined as
Thus, means that reverting causes oracle failure, while means that the reverted patch still passes.
Patch-level necessity precision is
The principal code-level measure is
Consequently, is the fraction of code units that the task-test oracle does not require. The paper calls 1-minimality: no individual unit can be removed without causing oracle rejection. This is not global minimality, because combinations of units may still be jointly removable.
The units that remain removable under the selected oracle form the patch residue. If is the set of unneeded units and is the subset whose introducing steps were debugging steps, the debug share is
For code units, the corresponding quantity is
These quantities are oracle-relative. A unit can be unneeded with respect to task tests while still changing behavior on inputs not covered by those tests.
3. Replay, provenance, and unit construction
DRA first reconstructs the agent’s intermediate repository states. Agent logs generally record tool calls but do not provide every intermediate working-tree state. The method therefore replays structured file-editing operations on the base repository and records line-level provenance, including which step last wrote each surviving line, which step deleted each base line, and the repository state after each step.
The replayed final repository must match the submitted patch exactly. On SWE-bench Verified, 96.7% of resolved trajectories replayed successfully. The excluded cases included 228 replay mismatches, six self-check failures, and five binary patches.
For shell-based edits such as sed commands or heredocs, DRA attributes the resulting file to the last shell command that wrote it and reconstructs later structured edits where possible. Units without recoverable provenance can still receive necessity grades, but cannot receive step attribution.
After replay, DRA diffs the base and final repositories and constructs the units. The line-block representation is language-independent and exactly revertible. It also introduces limitations: a block may contain several semantically distinct edits, while a single-unit patch receives by definition.
Each final unit is assigned to its latest writing step:
The latest-writer rule means that a line initially introduced during debugging but subsequently modified during the final fix is attributed to the later fix or refinement step. DRA consequently distinguishes the final state from the process that produced it.
Trajectory steps are assigned one of six fine-grained roles:
- Explore: reads, searches, or lists code without modifying tracked files.
- Reproduce: creates or edits a script or test to reproduce or check the issue.
- Probe: adds instrumentation or tries a change to test a hypothesis.
- Fix: applies the change presented as the solution.
- Refine: modifies an existing fix after testing or self-review.
- Cleanup: reverts or deletes earlier changes.
These roles are grouped into debug steps—Explore, Reproduce, and Probe—fix steps—Fix and Refine—and cleanup steps. Deterministic rules handle obvious cases, while remaining steps are labeled by a GPT-6.1 Sol judge using the issue, condensed history, action, observation, working-tree delta, later narration, and final explanation.
A second judge, Claude Opus 5.5, agreed with the primary judge on 84.4% of complete role labels, with , and on 89.1% of debug versus non-debug labels, with . No human audit of role labels was conducted.
4. Necessity grading and strengthened oracles
For each unit, DRA restores the base-state lines, removes a newly created file, or restores a deleted file. It then reruns the task tests. If the reverted patch fails, the unit is needed; if it passes, the unit is unneeded under the task-test oracle. Reversions that cannot be applied, leave the base state, fail to parse, or repeatedly hang are conservatively counted as needed.
The procedure reverts units one at a time. This avoids the combinatorial cost of testing all subsets but cannot detect every interaction among units. In particular, jointly necessary pairs may be misclassified when each unit is individually removable.
Because benchmark tests are incomplete, the study also defines a strengthened oracle . For each code unit that is unneeded under , GPT-6.1 Sol generates differential probe scripts from the issue and the difference between the full and reverted patches. The probes are run under the full agent patch, the reverted patch, and the developer patch.
A unit is needed under if either its reversion fails the task tests or its reversion fails to reproduce the behavioral change made by the developer patch. This distinguishes an untested but developer-aligned implementation from an unrequested behavioral change.
Among 3,559 test-unneeded agent code units:
- 3,151, or 88.5%, changed behavior when reverted.
- 1,263, or 35.5%, were developer-aligned and were rescued as needed under .
- 1,586, or 44.6%, matched the behavior of the patch without the unit and represented unrequested behavior.
- 133, or 3.7%, had mixed evidence.
- 169, or 4.7%, matched neither version.
- 408, or 11.5%, were behaviorally inert.
Under , the remaining unneeded agent units consisted of 1,888 live behavioral divergences, or 82%, and 408 inert edits, or 18%.
The oracle materially changes the headline comparison. Under , mean agent is 0.887 and developer is 0.864. Under , agent necessity rises to 0.925 and developer necessity to 0.970, reversing the gap from to percentage points. Under a live-behavior oracle in which any behavioral change counts as needed, agents score 0.978 and developers 0.970.
Thus, test-based unneededness is an upper bound on true excess rather than an unconditional semantic judgment. The definition of necessity must always be reported together with the oracle.
5. Empirical findings
On SWE-bench Verified, the median model changes 2.33 times as many lines as the developer patch. Outside test files, the ratio is 1.09. Code-unit counts give a different result: the overall code-unit ratio is 0.86, and the per-task median is 1.00.
The additional edits are distributed as follows:
| Edit category | Share of extra edits on SWE-bench Verified |
|---|---|
| Test-file edits | 61% |
| Code | 21% |
| Documentation | 13% |
| Comments or formatting | 5% |
Tests are pervasive: 81.5% of agent patches edit a test file. Because SWE-bench resets test files during grading, these edits are reported separately from code residue. DeepSWE differs: 58% of extra edits are code, 26% are tests, and 12% are documentation.
Under the task-test oracle, mean code necessity is:
| Dataset and patch source | Mean |
|---|---|
| SWE-bench agents | 0.887 |
| SWE-bench developers | 0.864 |
| DeepSWE agents | 0.797 |
| DeepSWE developers | 0.785 |
On SWE-bench Verified, 11 of 18 models leave significantly less unneeded code than developers, four show no significant difference, and three models—Gemini 3.6 Flash, 3.7 Flash, and 3.8 Flash—leave significantly more unneeded code. The average agent patch contains about 11% unneeded code units under the task-test oracle.
Among 3,987 unneeded SWE-bench agent code units for which probes were available, approximately 89% changed behavior when reverted. The remaining 11% were inert guards or duplicate checks. Hence, “unneeded” usually does not mean semantically inactive; much of the residue changes behavior that the benchmark task does not require or that diverges from the developer solution.
The source of residue is concentrated in intended solution construction rather than debugging. The pooled debug share across all residue is
However, 4,676 of the 4,898 debug-residue units are test-file hunks. For code only, 154 of 3,987 unneeded code units came from debug steps, yielding
For SWE-bench code residue, Fix steps contributed 83%, Refine steps 11%, Probe steps 3%, Reproduce steps 1%, and Cleanup steps 2%. On DeepSWE, Fix steps contributed 72% and Refine steps 22%. The unneeded rate was 0.25 for first Fix steps and 0.29 for Refine steps.
Necessity and resolve rate are distinct dimensions. On SWE-bench Verified, the Spearman correlation between model resolve rate and is
On DeepSWE, the relationship is negative:
These results indicate that solving more benchmark tasks does not necessarily imply producing more minimal patches.
Added tests require separate interpretation. Mutation testing on 271 valid SWE-bench instances with 1,962 mutants found that agent-added tests detected 68.1% of mutants, compared with 45.6% for existing regression tests and 77.1% for task tests. The strengthened oracle detected 84.7%. Agent tests detected 73.2% of mutants in needed code and 31.2% in unneeded code. Thus, test additions that are unnecessary under the task-test oracle may still improve test-suite coverage.
6. Applications, pruning, and limitations
DRA can be used diagnostically and as a post-generation pruning method. Early stopping at the first all-green run of the agent’s own tests had little effect: code units decreased from 7,419 to 7,269, while increased from 0.700 to 0.710. Most unnecessary code had already been written when the agent’s own tests first passed.
A self-audit procedure asked the agent to justify every final-diff hunk and remove units it could not justify. Under , it achieved 65.7% precision and 35.5% recall, increasing from 0.924 to 0.944 while 98.2% of patches still passed the strengthened oracle.
Visible-test DRA pruning uses cumulative leave-one-out removal and tests units with the agent’s own tests, optionally supplemented by existing PASS_TO_PASS tests:
| Method | Precision | Recall | before after | Patches still resolving |
|---|---|---|---|---|
| Self-audit | 65.7% | 35.5% | 0.924 0.944 | 98.2% |
| DRA + agent tests | 39.6% | 66.5% | 0.936 0.974 | 86.6% |
DRA + agent tests + PASS_TO_PASS |
46.3% | 67.3% | 0.936 0.975 | 89.1% |
Visible-test pruning removes substantially more residue than self-audit but at lower precision. False drops primarily involve code implementing behavior that neither the agent’s tests nor existing regression tests exercise. Oracle-guided pruning with the full strengthened oracle reaches approximately 99.5% recall and 100% patch retention, but that oracle is unavailable during deployment.
Several limitations constrain interpretation. Necessity depends on the chosen tests and behavioral probes; test-passing does not establish semantic minimality. One-at-a-time removal cannot identify jointly necessary combinations. Contiguous line blocks can combine semantically different changes, and single-unit patches are necessarily scored as 1-minimal. Provenance requires replayable trajectories: on DeepSWE, 33.4% of patches had at least one unit without provenance, covering 14.9% of units and 12.7% of code units. The analysis is restricted to resolved trajectories and one agent harness, GitHub Copilot CLI. Role labels rely partly on LLM judgment, and behavioral probes cover only a subset of units.
DRA is therefore best regarded as an oracle-relative empirical measure of patch-unit necessity and trajectory provenance. Its principal recommendation is to report code necessity alongside resolve rate, patch composition, the selected oracle, and a developer-patch baseline. The method also supports training and harness-level interventions: debloated trajectories can be used for training, while post-generation pruning can reduce residue. Because most unneeded code is introduced during Fix and Refine steps rather than Debug steps, cleanup prompts aimed solely at removing debugging artifacts are unlikely to address the dominant source of over-editing.