When Models Edit Too Much: On the Fidelity of Minimal Code Edits

TL;DR

This study introduces a framework to evaluate over-editing in code repair models, showing prompt and RL training reduce unnecessary changes, with detailed metrics and analysis.

cs.SE 🔴 Advanced 2026-09-04 71 views
Tongyao Zhu Wei Hern Lim Min-Yen Kan
code repair model editing fidelity reinforcement learning model scaling

Key Findings

Methodology

The authors constructed a benchmark with 400 BigCodeBench problems, injecting controlled AST corruptions to generate known minimal patches. They evaluated multiple frontier LLMs (e.g., GPT-5.5) using metrics like Pass@1, normalized Levenshtein distance, and cognitive complexity. Prompting with preservation instructions significantly reduced over-editing, and reinforcement learning was employed to train models to favor minimal edits, demonstrating improved out-of-domain fidelity. The framework isolates over-editing as a failure mode, enabling precise measurement and mitigation strategies.

Key Results

  • Models like GPT-5.5, without prompts, had an average excess Levenshtein distance of 0.195; with preservation prompts, this dropped to 0.131, cognitive complexity decreased by 26.6%, and Pass@1 increased by 2.3 percentage points.
  • Model scale alone did not guarantee smaller edits; larger models still exhibited considerable over-editing, especially on complex corruption types like boundary and control flow bugs.
  • Reinforcement learning outperformed supervised fine-tuning in out-of-domain settings, achieving higher fidelity and better performance retention, with minimal edit distances around 0.05 and Pass@1 above 78%.

Significance

This research highlights edit fidelity as a distinct axis of code repair quality, emphasizing that models can be guided to produce minimal, faithful patches. It addresses the critical challenge of balancing repair success with simplicity, crucial for maintainability and reviewability in real-world software engineering. The findings inform future development of automated repair tools, advocating for prompt engineering and RL-based training to enhance practical usability.

Technical Contribution

The paper introduces a controlled evaluation framework based on AST corruption, defines quantitative metrics for over-editing, and demonstrates that prompt-based and RL training strategies can effectively teach models to favor minimal, faithful edits. It also reveals the complex relationship between model size, reasoning, and editing behavior, offering insights into how to optimize models for code fidelity.

Novelty

This is the first comprehensive quantification of over-editing in large language models for code repair, combining a controlled benchmark with novel metrics and training approaches. It advances understanding of how to measure and learn edit fidelity, setting a new standard for evaluating code repair models beyond mere correctness.

Limitations

  • The evaluation primarily targets local, function-level repairs; applicability to large-scale refactoring or architectural changes remains untested.
  • Corruption types like boundary and control flow bugs are more prone to over-editing, but other complex or ambiguous corruptions need further analysis.
  • RL training incurs high computational costs, and generalization to highly novel or complex corruptions needs further validation.

Future Work

Future directions include extending the framework to encompass broader code transformations, integrating human preferences for repair granularity, and developing more efficient RL algorithms to scale training. Additionally, exploring multi-task learning and unsupervised methods could further enhance model fidelity and robustness in diverse repair scenarios.

AI Executive Summary

Large language models (LLMs) have revolutionized automatic code repair, yet a persistent challenge remains: models often make excessive changes beyond what is minimally necessary. Traditional metrics like Pass@1 focus solely on whether the bug is fixed, neglecting the size and complexity of the edits, which impacts code maintainability and reviewability. This study introduces a novel evaluation framework based on injecting controlled AST corruptions into reference solutions, enabling precise measurement of over-editing through metrics like excess Levenshtein distance and cognitive complexity.

The authors evaluate state-of-the-art models such as GPT-5.5, revealing that even top-tier models frequently perform unnecessary modifications, with average excess Levenshtein distances around 0.195. Interestingly, adding explicit preservation prompts significantly reduces over-editing, lowering the excess distance to 0.131 and improving Pass@1 by 2.3 percentage points. These results demonstrate that prompt engineering alone can steer models toward more faithful repairs.

Further, the study explores training strategies, showing that supervised fine-tuning tends to overfit to seen corruption patterns, whereas reinforcement learning (RL) effectively teaches models to prefer minimal edits, with out-of-domain fidelity and performance retention markedly improved. RL-trained models maintain high repair success rates while reducing unnecessary changes, even at larger scales.

Importantly, the findings challenge the assumption that larger models or more reasoning inherently lead to better fidelity. Instead, they highlight the importance of explicit prompts and learning objectives focused on minimal editing. This work positions edit fidelity as a crucial, measurable dimension of code repair quality, with significant implications for developing more reliable, maintainable automated repair systems.

Looking ahead, future research should extend this framework to more complex code transformations, incorporate human preferences, and optimize training efficiency. Overall, this study advances our understanding of how to produce more faithful, less intrusive code repairs, paving the way for smarter, more trustworthy AI-assisted programming tools.

Deep Analysis

Background

The evolution of automated code repair has transitioned from rule-based systems like GenProg to deep learning models such as CodeX and GPT variants, which leverage large-scale training data for high success rates. Prior works primarily evaluate whether the bug is fixed, using metrics like Pass@k, but neglect the extent of code changes. As models grow larger, their capacity to generate complex modifications increases, raising concerns about over-editing and maintainability. Recent efforts focus on improving patch quality, but lack systematic quantification of unnecessary edits. This gap limits the practical deployment of AI-based repair tools, especially in maintenance scenarios where minimal, faithful patches are preferred. The need for metrics and training strategies that explicitly address edit fidelity remains pressing, motivating the current study.

Core Problem

Despite high functional success, large language models often produce repairs that involve excessive modifications, complicating review and risking regressions. This over-editing phenomenon is especially problematic in real-world maintenance, where minimal, faithful patches are crucial. Existing benchmarks do not quantify the size or complexity of edits, making it difficult to evaluate and improve models' fidelity. The core challenge is to develop metrics that measure unnecessary changes and training methods that teach models to prefer minimal edits, balancing repair success with simplicity. Addressing this problem requires a controlled evaluation framework, precise metrics, and effective training strategies to mitigate over-editing while maintaining repair effectiveness.

Innovation

This work introduces a controlled benchmark based on injecting AST corruptions into reference solutions, enabling precise measurement of over-editing via excess Levenshtein distance and cognitive complexity. It proposes a preservation prompt that guides models to make minimal, faithful edits, significantly reducing unnecessary changes. Additionally, it employs reinforcement learning to train models to learn minimal editing preferences, demonstrating improved out-of-domain fidelity without sacrificing repair success. These innovations collectively establish a new paradigm for quantifying and learning edit fidelity, moving beyond traditional correctness metrics. The combination of controlled corruption, explicit prompting, and RL training offers a comprehensive approach to enhancing repair quality.

Methodology

  • �� Construct a benchmark from 400 BigCodeBench problems, injecting localized AST corruptions to generate known minimal repairs.
  • �� Use multiple models (GPT-5.5, Claude Opus 4.7) with different prompting strategies (generic vs. preservation) to perform repairs.
  • �� Measure repair quality using Pass@1, normalized token Levenshtein distance, and added cognitive complexity, validated by human annotation.
  • �� Introduce a preservation prompt that explicitly instructs models to minimize unnecessary changes.
  • �� Employ reinforcement learning (PRIME-RL) to fine-tune models, optimizing a reward function combining execution success and minimal edits.
  • �� Conduct ablation studies across model sizes, corruption types, and training methods to analyze effects on edit fidelity.
  • �� Evaluate out-of-domain generalization and the impact of prompt and training strategies on over-editing behavior.

Experiments

The experiments use 400 Python repair tasks from BigCodeBench with injected AST corruptions, ensuring each task's minimal fix is known. Models include GPT-5.5, DeepSeek, Gemini, and open-weight models of varying sizes. They compare generic prompts with preservation prompts, and supervised fine-tuning versus reinforcement learning training. Metrics include Pass@1, normalized Levenshtein distance, and cognitive complexity, with human validation for metric reliability. Ablation studies analyze prompt effects, model size, and training methods, focusing on out-of-domain generalization. The training involves applying corruptions, optimizing reward functions, and evaluating repairs across multiple settings to assess fidelity improvements.

Results

Models without prompts often exhibit excess Levenshtein distances averaging 0.195, indicating significant over-editing. Incorporating preservation prompts reduces this to 0.131, with a 26.6% decrease in cognitive complexity and a 2.3-point increase in Pass@1. Reinforcement learning further enhances out-of-domain fidelity, achieving minimal edit distances around 0.05 and Pass@1 above 78%. Larger models do not necessarily produce smaller edits; over-editing persists across scales. Corruption types like boundary and control flow bugs are more prone to excessive modifications. The combination of prompts and RL training effectively mitigates over-editing, demonstrating that edit fidelity can be learned and improved systematically.

Applications

The findings support developing automated code repair tools that prioritize minimal, faithful patches, reducing review and maintenance effort. These methods can be integrated into CI/CD pipelines, offering more reliable fixes. In the long term, AI-assisted programming could evolve into a standard component of software engineering, enabling faster, safer development cycles with less manual intervention, especially in legacy system maintenance and large-scale refactoring.

Limitations & Outlook

Current evaluation focuses on local, function-level repairs; applicability to large-scale architectural changes remains untested. Over-editing patterns are more evident in certain corruption types, and the generalization to more ambiguous or complex corruptions needs further validation. RL training incurs high computational costs, limiting scalability. Future work should explore multi-task learning, human-in-the-loop training, and broader corruption scenarios to address these limitations.

Plain Language Accessible to non-experts

想象你在厨房里做菜,厨师(模型)接到任务,只需要修正一道菜中的调味料。理想情况下,他只需少量调整即可完成任务,但有时候厨师会把整盘菜都重新做一遍,加入很多不必要的调料和装饰。这样虽然菜变得更丰富,但也变得复杂难看,甚至可能偏离原本的味道。研究发现,如果你告诉厨师“只修正调味料,不要乱动其他”,他就会变得更专注,只做必要的调整。这就像模型在修代码时,加入“只修一小部分”的提示,能让它只做最重要的改动,保持代码的原始意图,也更容易审查。通过训练厨师学会只做必要的调整,未来可以让厨房变得更整洁、更高效。这项研究帮助我们理解,自动修复代码的AI也可以学会只做最必要的修正,避免乱改,保持代码的稳定和简洁。

ELI14 Explained like you're 14

想象你在学校写作文,老师让你改错,但只要改错别字,不要改太多内容。有时候,你会把整篇文章都改得不一样,虽然也改对了,但变得很难懂。这就像模型在修代码时,不仅修了错,还改了很多不需要改的地方,让代码变得复杂。科学家们发现,如果你告诉模型“只改错的地方,不要乱动其他”,它就能更忠实地修复代码,不会乱动。通过训练和提示,模型学会只做最必要的修正,就像你学会只改错别字,不改别的。这样,修好的代码更容易看懂,也更容易维护。未来,这样的模型可以帮程序员节省很多时间,让软件变得更稳定、更可靠。

Abstract

Large language models (LLMs) are increasingly used to edit existing code, but correctness alone is not enough: useful repairs should also be minimal, reviewable, and faithful to the original implementation. We study over-editing, the tendency of a model to rewrite code beyond what is required to fix a bug. We construct an evaluation framework from 400 BigCodeBench problems by injecting controlled AST-level corruptions into reference solutions, giving each repair task a known minimal patch. Across frontier LLMs, over-editing is widespread even among strong models like GPT-5.5: high Pass@1 can coexist with unnecessarily large edits and added cognitive complexity. A preservation instruction substantially reduces this behavior, lowering average excess Levenshtein distance from 0.195 to 0.131, reducing added cognitive complexity by 26.6%, and increasing Pass@1 by 2.3 points. However, these gains do not simply follow from a larger reasoning budget or larger models. We next ask whether minimal editing can be learned directly during post-training. We observe that supervised fine-tuning overfits to seen corruption patterns, whereas reinforcement learning gives the best out-of-domain edit-fidelity and performance-retention trade-off. These results position edit fidelity as a distinct axis of code-repair quality and show that it can be measured and learned.

cs.SE cs.AI cs.CL