跳转至

当模型改动过多:论最小代码编辑的保真度

文章背景与核心概要

在利用大语言模型(LLM)进行代码修复和编辑时,仅实现功能上的正确性往往是不够的——代码修改还必须做到精简、易于Code Review,并且忠于原始实现。本文深入研究了“过度编辑(over-editing)”现象,即模型在修复Bug时倾向于重写超出严格必要范围的代码。

为了评估这一问题,作者基于400个BigCodeBench问题引入了一个框架,利用受控的AST(抽象语法树)级损坏,为每个任务赋予一个已知的最小补丁(minimal patch)。研究结果表明,过度编辑在包括GPT-5.5在内的前沿模型中普遍存在。尽管基于提示词的代码保留指令和强化学习可以成功缓解该问题,并在编辑保真度与性能之间优化权衡,但监督微调(SFT)往往容易过拟合到已见过的损坏模式。该研究最终确立了“编辑保真度(edit fidelity)”作为代码修复质量的一个至关重要且可量化的维度。


arXiv: 2609.04061 [cs.SE]
Authors: Tongyao Zhu, Wei Hern Lim, Min-Yen Kan
Conference: EMNLP 2026 (Main)
Submitted: 3 September 2026


Summary

当大语言模型(LLMs)被用于修复或编辑代码时,实现功能正确性通常是不够的——修复必须同时具备最小化、可审查性(reviewable)以及对原实现的忠实度。本文研究了过度编辑(over-editing),即模型倾向于重写超出解决Bug严格所需范围的代码。

When large language models (LLMs) are used to fix or edit code, achieving functional correctness is often not enough—repairs must also be minimal, reviewable, and faithful to the original implementation. This paper studies over-editing, which is the tendency of models to rewrite code beyond what is strictly necessary to resolve a bug.

为了评估这一点,作者引入了一个基于400个BigCodeBench问题的框架,利用受控的AST级破坏,为每个任务赋予一个已知的最小补丁。研究发现表明,即使在像GPT-5.5这样的前沿模型中,过度编辑也十分普遍。虽然基于提示词的保留指令和强化学习可以成功缓解该问题,并优化编辑保真度与性能之间的权衡,但监督微调往往会对见过的破坏模式产生过拟合。最终,该研究将编辑保真度确立为代码修复质量的一个至关重要的、可量化的维度。

To evaluate this, the authors introduce a framework built from 400 BigCodeBench problems using controlled AST-level corruptions, giving each task a known minimal patch. Their findings reveal that over-editing is widespread even among frontier models like GPT-5.5. While prompt-based preservation instructions and reinforcement learning can successfully mitigate the issue and optimize the trade-off between edit fidelity and performance, supervised fine-tuning tends to overfit to seen corruption patterns. Ultimately, the work establishes edit fidelity as a vital, measurable dimension of code repair quality.



Key Findings

  1. 过度编辑的普遍性: 即使是强大的前沿LLM(例如GPT-5.5)也表现出极高的过度编辑率,其中高成功率(Pass@1)与不必要的大规模代码变动和膨胀的认知复杂度并存。
    1. Prevalence of Over-Editing: Even strong frontier LLMs (such as GPT-5.5) exhibit high rates of over-editing, where high success rates (Pass@1) coexist with unnecessarily massive code alterations and inflated cognitive complexity.
  2. 保留指令的影响: 显式指示模型保留原始代码结构可显著提高编辑保真度:
  3. 将平均超额列文斯坦距离(Levenshtein distance)从 0.195 降低至 0.131
  4. 将新增的认知复杂度降低 26.6%
  5. 将功能正确性(Pass@1)提高 2.3个百分点
    1. Impact of Preservation Instructions: Explicitly instructing the model to preserve original code structure significantly improves edit fidelity:
    2. Lowers average excess Levenshtein distance from 0.195 to 0.131.
    3. Reduces added cognitive complexity by 26.6%.
    4. Increases functional correctness (Pass@1) by 2.3 points.
  6. 后训练策略:
  7. 监督微调(SFT)对特定、已见过的破坏模式产生过拟合。
  8. 强化学习(RL)在编辑保真度和性能保持方面提供了最佳的域外(out-of-domain)权衡。
    1. Post-Training Strategies:
    2. Supervised Fine-Tuning (SFT) overfits to specific, seen corruption patterns.
    3. Reinforcement Learning (RL) delivers the optimal out-of-domain trade-off for both edit fidelity and performance retention.