mech.app

The mech.app newsletter

Agentic AI, minus the noise.

Get practical field notes on AI agents, automation, developer tools and security delivered to your inbox.

No spam. Unsubscribe anytime.

Dev Tools

Delta Residue Attribution: Tracing Every Unneeded Edit in Agent-Generated Code Patches

DRA replays agent trajectories to trace each patch block to its originating tool call, revealing which edits were unnecessary and why agents over-edit c...

Source: arxiv.org
Delta Residue Attribution: Tracing Every Unneeded Edit in Agent-Generated Code Patches

Agent-generated patches are larger than human patches. That much is known. What has not been known is whether the extra lines are necessary, what they do, or which tool calls produced them. Delta Residue Attribution (DRA) answers those questions by replaying agent trajectories, tracing every block of the final patch to the step that wrote it, reverting each unit, and rerunning task tests to determine if the unit was needed.

The technique was applied to 7,660 resolved GitHub Copilot CLI trajectories across 18 frontier models on SWE-bench Verified (6,728 tasks) and DeepSWE (932 tasks). The results expose the plumbing behind agent over-editing: where unnecessary mutations come from, which models produce them, and whether pruning strategies can remove them without breaking patches.

How DRA Works

Delta Residue Attribution is a trajectory-replay technique. It operates at the granularity of code blocks (units), not lines or hunks. The process:

  1. Replay the trajectory: Execute the agent’s recorded sequence of tool calls and state transitions.
  2. Trace each block: Map every block in the final patch to the specific tool call that produced it.
  3. Revert and test: Remove one block at a time, rerun the task tests, and record whether the patch still resolves the issue.
  4. Classify necessity: A block is unneeded if removing it does not break the patch. A block is needed if its removal causes test failure.

The unit of granularity matters. DRA uses blocks (logical code units) rather than lines because lines are too fine-grained (a single line rarely stands alone) and hunks are too coarse (a hunk often contains both needed and unneeded changes). Blocks strike a balance: they align with the semantic structure of code and match the output granularity of most agent tools.

This approach surfaces which tool calls are responsible for unnecessary edits. If a file-write tool produces a block that can be reverted without consequence, the orchestration logic either invoked the tool incorrectly or the tool itself lacks precision.

What the Data Shows

Agent patches do change more lines than developer patches. On SWE-bench Verified, the majority of extra edits add tests (61%) and documentation (13%). On DeepSWE, most extra edits are code (58%).

But when you isolate code edits and measure necessity, agents perform at least as well as developers. Mean code necessity (NP_code) on SWE-bench Verified is 0.887 for agents versus 0.864 for developers. On DeepSWE, it is 0.797 for agents versus 0.785 for developers. Eleven of 18 models leave less unneeded code than developers on SWE-bench Verified.

On average, 11% of an agent patch’s code units on SWE-bench Verified are still unneeded. Of those unneeded units, 89% change program behavior (they are not just formatting or comments). Debug steps write almost none of the unneeded code, which means the problem is not agents iterating too much. The problem is that certain tool calls produce edits that do not contribute to task resolution.

Code necessity differs substantially by model. It is unrelated to resolve rate on SWE-bench Verified (no correlation) and negatively correlated with resolve rate on DeepSWE (Spearman -0.59, p = 0.01). This means some models solve more tasks by making more edits, not by making better edits.

Pruning Strategies

DRA can be used to prune patches. Two strategies were tested:

Automated pruning: Remove blocks that DRA identifies as unneeded using only the tests the agent can see (its own tests and the repository’s existing tests). This removes 67% of unneeded code but also removes some needed code (46% precision). After pruning, 89% of patches still resolve the task.

Agent self-audit: Ask the agent to review its own diff and remove unnecessary edits. This is more precise (66% precision) but less effective (36% recall). The agent is conservative and leaves most edits in place.

The trade-off is clear. Automated pruning is aggressive and risks breaking patches. Agent self-audit is safe but leaves most unneeded code untouched.

StrategyRecallPrecisionPatches Still Resolving
Automated pruning67%46%89%
Agent self-audit36%66%Not reported

Orchestration and Tool Boundaries

DRA exposes where over-editing originates. The fact that debug steps contribute almost no unneeded code suggests that iterative refinement is not the culprit. Instead, the problem is likely one of two things:

  1. Tool precision: File-write tools may not support fine-grained edits. If an agent can only replace an entire function or file, it will over-edit by default.
  2. Orchestration logic: The agent may invoke tools correctly but choose the wrong scope. For example, it might rewrite a function when only a single line needs to change.

The negative correlation between code necessity and resolve rate on DeepSWE suggests that some agents are solving tasks by brute force: making more edits until something works. This is an orchestration problem, not a tool problem.

Integration into Eval Pipelines

DRA can be integrated into agent evaluation pipelines to penalize unnecessary mutations. The feedback loop would look like this:

def evaluate_patch_with_dra(trajectory, final_patch, test_suite):
    """
    Evaluate a patch using Delta Residue Attribution.
    Returns resolve rate and code necessity score.
    """
    blocks = trace_blocks_to_steps(trajectory, final_patch)
    unneeded_blocks = []
    
    for block in blocks:
        reverted_patch = final_patch.without(block)
        if test_suite.passes(reverted_patch):
            unneeded_blocks.append(block)
    
    necessity_score = 1 - (len(unneeded_blocks) / len(blocks))
    
    return {
        "resolves": test_suite.passes(final_patch),
        "necessity": necessity_score,
        "unneeded_blocks": unneeded_blocks
    }

This metric could be used to:

  • Rank models by edit efficiency, not just resolve rate.
  • Identify which tool calls produce the most unneeded edits.
  • Train agents to minimize unnecessary mutations during reinforcement learning.

The challenge is that DRA requires trajectory replay, which is expensive. For large-scale eval, you would need to cache intermediate states or use incremental replay.

Failure Modes

DRA has known failure modes:

Test coverage gaps: If the test suite does not exercise a code path, DRA will classify edits to that path as unneeded even if they are semantically important. The paper uses only the tests the agent can see (its own tests and the repository’s), so coverage is limited.

Block granularity mismatch: If the agent’s tool outputs do not align with block boundaries, DRA will either over-attribute (assign multiple edits to one block) or under-attribute (split one edit across multiple blocks). This is a tooling problem, not a DRA problem.

Non-deterministic tests: If tests are flaky, DRA will produce inconsistent necessity scores. The solution is to run tests multiple times and use majority vote, but this increases cost.

Behavioral equivalence: DRA only checks whether tests pass, not whether the code is semantically equivalent. An edit might be unneeded for task resolution but still improve code quality (e.g., refactoring for readability). DRA does not capture this.

Technical Verdict

Use DRA when you need to understand why agent patches are large and which tool calls are responsible for unnecessary edits. It is especially useful for:

  • Debugging orchestration logic in repository-level agents.
  • Comparing models on edit efficiency, not just resolve rate.
  • Building pruning tools that remove unneeded edits without breaking patches.

Avoid DRA when:

  • You do not have access to agent trajectories (it requires step-by-step replay).
  • Your test suite has low coverage (DRA will misclassify edits as unneeded).
  • You care about code quality beyond task resolution (DRA only checks whether tests pass).

The technique is most valuable during agent development, not production deployment. It is a diagnostic tool, not a runtime guardrail. If you want to prevent over-editing in production, you need to fix the orchestration logic or tool boundaries, not prune patches after the fact.


Tags

agentic-ai orchestration infrastructure

Primary Source

arxiv.org ↗