arXiv:2607.28887cs.SEcs.AI2026-07

大模型写代码时总想留旧代码,反而让维护更难。

To Add Is Machine, To Delete Is Human: Measuring and Mitigating Deletion Avoidance in LLM Code Editing

论文配图:To Add Is Machine, To Delete Is Human: Measuring and Mitigating Deletion Avoidance in LLM Code Editing
图 1 · 摘自论文原文
  • 发现大模型编辑代码时倾向保留原内容,删除准确率不足52%
  • 新测试显示41.9%的通过补丁其实没删该删的代码
  • 教模型专门学删代码可提升表现,适合改进代码生成工具

大型语言模型在编写和修复生产代码时日益常见,但越来越多证据表明,其通过测试的补丁反而使代码库更难维护。我们识别出一个具体原因:删除回避,即系统性地保留本应删除的代码。在SWE-bench Verified官方排行榜上排名前五的模型,即使在全部五款模型都能解决的任务中,删除召回率最高也仅达71.7%;模型能定位到需删除文件的比例超过92%,但实际精准删除对应行的比例不足52%。相反,29.0%的通过补丁将目标代码包裹在保护语句或备用逻辑中,我们称之为“守门而过”(Guard-and-Go)。当我们在34个已验证任务中加入检测是否保留原代码的测试后,四款前沿模型(涵盖闭源与开源权重)通过率从63.2%骤降至41.9%。由于真实修复常涉及删与增并行,我们构建了CanItDelete基准,包含200个源自真实提交的纯删除任务。即便去除了添加部分,最佳模型仍每五次失败一次,小规模开源模型则跌至18.0%。随后对GPT-5.6 Sol进行四阶段提示消融实验,成功率在未提供具体行号时变化极小;只有明确给出行号时,不完整删除才基本消除,但成功率仅升至80.5%,因模型开始过度删除或错误添加代码。最后,初步研究表明,在后训练阶段加入删除教学可减少删除回避行为,并提升整体代码编辑能力,暗示该行为源于训练不足而非不可克服。

原文摘要 · Abstract (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.

代码生成模型缺陷删除回避基准测试

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。