---
title: "Audit Unneeded Edits with Counterfactual Patch Tests"
term: "Over-Edit Audit"
description: "Audit agent patches by reverting individual code blocks and rerunning tests; treat removable edits as review candidates bounded by the tests you can run."
tags:
  - technique
  - testing-verification
  - code-review
  - tool-agnostic
  - arxiv
last_reviewed: 2026-11-28
maturity: emerging
---

# Audit Unneeded Edits with Counterfactual Patch Tests

> An over-edit audit tests whether individual patch blocks are necessary; use passing reversions as review candidates when your validation covers the intended behavior.

An over-edit audit reverts each independently removable block of an agent patch and reruns a stated test suite. Delta Residue Attribution (DRA) adds trajectory replay to identify which step last wrote or deleted each block. Its necessity verdict is relative to that suite: passing after removal does not establish that the edit is unwanted ([Goel et al., sections 3.1–3.4](https://arxiv.org/abs/2611.34875v1)).

## Apply the audit to a resolved patch

The following is a recommended review procedure adapted from DRA, rather than a validated production rollout:

1. Preserve the submitted patch and confirm that it passes your selected checks before testing removals. DRA excludes patches whose control run fails.
2. Separate code changes from tests and documentation. DRA leaves test edits ungraded because SWE-bench grading resets test files.
3. Split the final diff into independently revertible blocks. DRA merges changed blocks separated by at most one unchanged line; a new file is one unit.
4. Revert one unit against the preserved patch, rerun the checks, and record the result. A passing reversion marks a candidate for review; a failed check marks a unit needed by that suite.
5. If you have a replayable trajectory, verify that replay reproduces the final patch before attributing units to the step that last wrote or deleted them ([DRA, sections 3.2–3.4](https://arxiv.org/abs/2611.34875v1)).

For any accepted removals, validate the combined patch again. DRA's measurement removes units independently; its pruning experiment instead accumulates removals while requiring the available tests to keep passing ([section 5.5](https://arxiv.org/abs/2611.34875v1)).

## Why it works

Counterfactual removal asks whether the checks require an edit, which patch size alone cannot establish. On resolved SWE-bench Verified patches, DRA reports mean code necessity of 0.887 under task tests: about 11% of a patch's code units are unneeded by those tests. This is a mean unit share, not a fraction of all changed lines or a deletion target ([sections 3.1 and 5.1](https://arxiv.org/abs/2611.34875v1)).

Attribution also changes where to look. In this Copilot CLI study, debug steps introduce only 154 of 3,987 unneeded code units. The authors attribute each unit to the step that last wrote or deleted its lines, so an earlier debug edit revised during the fix counts under the fix. Inspect the fix itself when auditing scope ([sections 3.2 and 5.3](https://arxiv.org/abs/2611.34875v1)).

## When this backfires

- Incomplete tests permit false removals. The authors treat test-unneeded code as an upper bound on true excess; code outside test coverage can still serve developer intent.
- Independent removals do not establish a globally minimal patch. Groups of units can interact, and a mixed block can hide removable code.
- Automatically deleting passing candidates loses intended behavior. In the pruning experiment, most false drops implement behavior exercised by neither existing tests nor agent tests ([sections 3.1, 5.5, and 6](https://arxiv.org/abs/2611.34875v1)).

Recommendation: review passing candidates against the task requirements and add behavioral checks for disputed removals. Keep the test command and its coverage limits beside each verdict. DRA itself supplements task tests with differential behavioral probes, while acknowledging that its LLM-written probes have limitations ([sections 3.4 and 6](https://arxiv.org/abs/2611.34875v1)).

## Example

DRA's SWE-bench Verified cleanup experiment cumulatively reverts units using the agent's own test command plus existing PASS_TO_PASS regression tests. On 2,495 eligible patches, this finds 67.3% of unneeded code units at 46.3% precision, measured against the strengthened oracle that also uses behavioral probes. Only 89.1% of the pruned patches still pass the task tests. Self-audit finds 35.5% at 65.7% precision across a different cohort, so these columns are not a paired comparison ([section 5.5, Table 1](https://arxiv.org/abs/2611.34875v1)).

Use this result to justify examining candidate removals. It does not justify trusting the available tests to approve every deletion.

## Key Takeaways

- Label findings with the exact test suite; “unneeded” always has an oracle attached.
- Preserve per-unit results separately from the final combined-patch validation.
- Treat tests and documentation as separate review categories before interpreting patch size.

## Related

- [Bug-Discriminating Validation Evidence](bug-discriminating-validation-evidence.md) — select checks that distinguish a repair from its buggy baseline
- [Execution-Pass Code Review](execution-pass-code-review.md) — inspect behavior by running the application
- [CodeSlop and Trajectory Minimization](../patterns/anti-patterns/codeslop-trajectory-minimization.md) — reduce search residue using the recorded edit hierarchy
- [Minimality Prompts as a Patch-Size Control](../patterns/anti-patterns/minimality-prompt-as-patch-size-control.md) — limits of asking for smaller patches
