添加是机器所为,删除是人之所为:大语言模型代码编辑中删除回避的度量与缓解
To Add Is Machine, To Delete Is Human: Measuring and Mitigating Deletion Avoidance in LLM Code Editing
July 30, 2026
作者: Amir M. Ebrahimi, Mohammed Mehedi Hasan, Aaditya Bhatia, Gopi Krishnan Rajbahadur, Ahmed E. Hassan
cs.AI
摘要
大语言模型越来越多地编写和修复生产代码,但越来越多的证据表明,它们通过测试的补丁会让代码库更难维护。我们确定了一个具体来源:删除回避,即在预期编辑需要删除代码时,模型系统性地倾向于保留这些代码。
在官方 SWE-bench Verified 排行榜上的五个领先模型中,即使在所有五个模型都能解决的任务中,这些模型对开发者补丁的删除召回率最高仅为 71.7%;在超过 92% 的必需删除中,模型到达了正确的文件,但只有不到 52% 的情况切除了准确的代码行。相反,29.0% 通过测试的补丁将目标代码包裹在守卫或后备逻辑中,我们将这种模式称为“Guard-and-Go”。
这类补丁之所以能通过测试,是因为原始测试很少检查删除行为:当我们为 34 个 Verified 任务改造测试,使其在目标代码仍然存在时失败时,涵盖闭源和开源权重的四个前沿模型的通过率从 63.2% 下降到 41.9%。
由于真实的代码修复往往同时涉及删除和添加,我们构建了 CanItDelete 基准,包含从真实提交中挖掘的 200 个任务,这些任务所需的全部编辑操作就是删除。即使不再需要添加操作,最好的模型仍然每五个任务就失败一个,而较小的开源模型成功率降至 18.0%。
随后,我们在四种累积提示条件下对 GPT-5.6 Sol 进行消融实验;在提供精确代码行之前,成功率几乎没有变化,而提供精确行后,不完整删除几乎被消除,但成功率仅提高到 80.5%,因为模型随后会删除超出范围的内容,或转而添加代码。
最后,通过一项初步研究,我们展示了一种潜在的解决方案:在后训练阶段教授删除操作可以减少删除回避,并提升更广泛的代码编辑性能,这表明该行为是训练不足导致的,而非无法实现。
English
Large language models increasingly write and repair production code, yet evidence is mounting that their test-passing patches leave codebases harder to maintain. We identify one concrete source: deletion avoidance, the systematic tendency to retain code that an intended edit requires removing. Across the five leading models on the official SWE-bench Verified leaderboard, deletion recall against the developer patch reaches at most 71.7% even on tasks all five solve, and models reach the right file for over 92% of required deletions but cut the exact line in under 52% of cases. Instead, 29.0% of passing patches wrap the targeted code in a guard or fallback, a pattern we call Guard-and-Go. Such patches pass because the original tests rarely check removal: when we retrofit 34 Verified tasks with tests that fail if the targeted code remains, four frontier models spanning closed and open weights fall from 63.2% to 41.9%. Because real repairs mix removal with addition, we curate CanItDelete, a benchmark of 200 tasks mined from real commits whose entire required edit is deletion. Even with the addition work gone, the best model still fails one task in five, and smaller open models fall to 18.0%. We then ablate GPT-5.6 Sol under four cumulative prompts; success moves little until we supply the exact lines, which nearly eliminate incomplete deletion yet raise success only to 80.5% because the model then deletes beyond the spans or adds code instead. Finally, through a pilot study we show one potential fix: teaching deletion during post-training reduces deletion avoidance and improves broader code-editing performance, suggesting the behavior is undertrained rather than beyond reach.