K-文化的一切——从回归到 K-美妆,发送到您的邮箱订阅邮件

METAL MEDIA

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

arXiv:2607.288872026-07-29

AI编程模型即使被要求删除代码,也常常悄悄把旧代码留下来

研究者分析了SWE-bench Verified排行榜上五个顶尖模型,发现通过测试的补丁仍然保留了开发者本应删除的大部分代码。新推出的纯删除基准CanItDelete显示,即便是最强模型也有五分之一的任务失败。给模型追加少量删除相关训练数据后,这一问题有所缓解,其他代码编辑能力也随之提升。

METAL MEDIA 解读图

揭示删除回避的三阶段研究结构

证据状态已报告实测结果

  1. 1. 真实仓库补丁对比将五个SWE-bench Verified模型的通过补丁与开发者补丁对比,发现删除召回率仅为65%-72%,29%的通过补丁采用了Guard-and-Go策略
  2. 2. 检验测试的盲区给34个任务加入专门检测删除是否完成的测试后,通过率从63.2%降至41.9%,证明原有测试很难捕捉删除遗漏
  3. 3. 纯删除基准测试CanItDelete的200个任务排除了定位和新增代码的干扰,专门测量纯粹的删除能力;最好的模型也只有79.0%,即便给出精确范围仍有19.5%失败
  4. 4. 诊断阶梯逐步提供删除指令、位置提示和精确删除范围,证明失败的根源不是缺乏意图,而是不知道删除边界在哪里
  5. 5. 删除导向的后训练只用相当于7B模型训练token总量0.7%的删除样本,就同时提升了CanItDelete、SWE-bench Verified和CanItEdit的表现
这是 METAL MEDIA 制作的解读图,并非论文作者提供的原图。

他们做了什么

  1. 研究者对比了SWE-bench Verified官方排行榜五个模型(GLM-4.6、GPT-5、Kimi-K2、Opus-4.5、Salesforce SAGE)的补丁与开发者补丁,发现在全部五个模型都通过的197个任务中,平均删除召回率(模型真正删除了开发者删除内容的比例)仅为65.2%到71.7%。
  2. 模型在92%以上的情况下能找到需要删除代码所在的正确文件,但真正删除到精确那一行的比例只有44.6%到51.6%,说明问题不在于找不到代码,而在于找到了也不删。
  3. 一个LLM分类器发现,29.0%的通过补丁属于'Guard-and-Go'模式:模型保留开发者本应删除的逻辑,转而在其外部加一层条件判断或备用路径绕过它。
  4. 研究者给34个任务补充了专门检测删除是否完成的测试后,四个前沿模型的通过率从63.2%骤降到41.9%,说明原有测试很少真正检验删除是否发生。
  5. 在专门只要求删除的新基准CanItDelete的200个任务上,表现最好的模型(Claude Opus 4.8)成功率也只有79.0%;即便直接给出需要删除的精确代码行,GPT-5.6 Sol仍有19.5%的任务失败,原因是删除范围过大或又添加了新代码。给一个7B模型的训练数据中加入1.28万条删除样本(占训练token的0.7%)后,CanItDelete成功率提升13.9个百分点,SWE-bench Verified提升5.3分,CanItEdit提升1.4分。
Figure 1: An example of deletion avoidance in a solved SWE-bench Verified task. The developer patch removes a statement, while the model retains it under an ‘else’ guard.
Figure 1: An example of deletion avoidance in a solved SWE-bench Verified task. The developer patch removes a statement, while the model retains it under an ‘else’ guard.
Table 1: Mean deletion recall on 197 tasks all five models solve and 57 all five fail. δ denotes effect size.
ModelFailed (n=57)Solved (n=197)δ
GLM-4.624.0%67.5%0.532
GPT-529.9%68.5%0.485
Kimi-K219.8%65.2%0.543
Opus-4.530.4%71.7%0.504
Salesforce SAGE27.5%68.0%0.501
Figure 2: Overview of CanItDelete benchmark construction, cumulative diagnostic modes, and the structural outcome taxonomy.
Figure 2: Overview of CanItDelete benchmark construction, cumulative diagnostic modes, and the structural outcome taxonomy.
Table 2: Patch strategies among 2,358 classifier-labeled pairs. Share is overall frequency; pass rate is SWE-bench Verified resolution within each strategy. Table 12 (Appendix B) lists the ten Guard-and-Go forms.
StrategynSharePass rate
Delete-and-Replace1,19750.8%85.2%
Guard-and-Go68429.0%72.2%
Non-reference alternative47720.2%39.6%
Figure 3: Vanilla-mode success and failure composition across 12 models. Success is measured over 200 tasks; failure mechanisms are measured over each model’s failed tasks.
Figure 3: Vanilla-mode success and failure composition across 12 models. Success is measured over 200 tasks; failure mechanisms are measured over each model’s failed tasks.
Table 3: Attempts passing the original suite and, among them, the deletion-sensitive check on 34 tasks per model. Drop is in percentage points (pp); each task is about 2.9 pp.
Passing attempts
ModelTasksOriginal suiteOriginalsuiteWith deletion checkWith deletioncheckDrop (pp)Drop(pp)
Original
suite
With deletion
check
Drop
(pp)
GPT-5.6 Sol3421 (61.8%)15 (44.1%)17.6
Opus 4.83421 (61.8%)14 (41.2%)20.6
GLM-5.23426 (76.5%)18 (52.9%)23.5
DeepSeek-V4-Pro3418 (52.9%)10 (29.4%)23.5
Overall13686 (63.2%)57 (41.9%)21.3
Figure 4: Diagnostic-ladder outcomes under increasingly precise deletion guidance. Four models use 200 tasks; Claude Opus 4.8 uses 173.
Figure 4: Diagnostic-ladder outcomes under increasingly precise deletion guidance. Four models use 200 tasks; Claude Opus 4.8 uses 173.
Table 4: 7B-model performance before and after deletion-augmented post-training. Values are three-run means (%); Δ is absolute percentage-point change. Over-deletion is a subset of complete-but-invalid edits.
CanItDelete outcomeBenchmark success
Succ.Incomp.Complete invalidOver- deletionSWE-b. VerifiedEditBenchCanItEdit
Base6.580.413.110.625.4039.2644.30
+Deletion13.766.519.816.830.7039.0745.70
Δ+7.2−13.9+6.7+6.2+5.30-0.19+1.40
Figure 5: File-, scope-, and exact-line overlap across all required deletions in the 197 tasks solved by all five models
Figure 5: File-, scope-, and exact-line overlap across all required deletions in the 197 tasks solved by all five models
Table 5: Model submissions selected from the official SWE-bench Verified repository. For each model family, we retained the latest submission using the OpenHands scaffold. The submission date is extracted from the leading YYYYMMDD component of the repository directory name.
FamilySelected modelSubmission directorySubmission date
GLMGLM-4.620250930_zai_ glm-4.6September 30, 2025
GPTGPT-520250807_ openhands_gpt5August 7, 2025
KimiKimi K220250716_ openhands_kimi_k2July 16, 2025
ClaudeClaude Opus 4.520251127_ openhands_ claude-opus-4-5November 27, 2025
SAGESalesforce SAGE20251103_ SalesforceAIResearch_ SAGE_OpenHandsNovember 3, 2025
Figure 6: Structural distributions across the 200 CanItDelete tasks.
Figure 6: Structural distributions across the 200 CanItDelete tasks.
Table 6: Mean per-task deletion precision and recall. A match requires the model-generated patch to delete the same base-commit source location as the official human patch.
Failed by all five (n=57)Failed by all five(n=57)Solved by all five (n=197)Solved by all five(n=197)
Failed by all five
(n=57)
Solved by all five
(n=197)
ModelPrecisionRecallPrecisionRecall
GLM-4.634.6%24.0%70.7%67.5%
GPT-535.6%29.9%69.3%68.5%
Kimi-K235.0%19.8%70.6%65.2%
Opus-4.547.0%30.4%74.3%71.7%
Salesforce SAGE36.7%27.5%66.2%68.0%
Table 7: Comparison of deletion recall between all-passed (n=197) and all-failed (n=57) eligible tasks for each evaluated model. Panel A reports the median and interquartile range (IQR). Panel B reports the Mann–Whitney U test with Holm-adjusted p-values and Cliff’s δ effect size.
All-passedAll-failed
ModelMedianIQRMedianIQR
Salesforce SAGE1.000.750.070.50
GLM-4.61.000.750.000.33
GPT-51.000.710.000.50
Kimi-K21.000.800.000.25
Opus-4.51.000.610.170.50
Table 8: Comparison of deletion precision between all-passed (n=197) and all-failed (n=57) eligible tasks for each evaluated model. Panel A reports the median and interquartile range (IQR). Panel B reports the Mann–Whitney U test with Holm-adjusted p-values and Cliff’s δ effect size.
All-passedAll-failed
ModelMedianIQRMedianIQR
Salesforce SAGE1.0000.6840.0380.929
GLM-4.61.0000.6670.0001.000
GPT-51.0000.6840.0001.000
Kimi-K21.0000.6670.0001.000
Opus-4.51.0000.5000.4001.000
Table 9: Model-generated patch size relative to the corresponding developer patch for passing Guard-and-Go pairs. LOC is measured as the sum of added and deleted lines.
ModelPairsModel largerModellargerEqual LOCEqualLOCModel smallerModelsmaller
Model
larger
Equal
LOC
Model
smaller
GLM-4.69189 (97.80%)0 (0.00%)2 (2.20%)
GPT-512058 (48.33%)10 (8.33%)52 (43.33%)
Kimi-K29275 (81.52%)3 (3.26%)14 (15.22%)
Opus-4.59130 (32.97%)20 (21.98%)41 (45.05%)
Salesforce SAGE10050 (50.00%)14 (14.00%)36 (36.00%)
Overall494302 (61.13%)47 (9.51%)145 (29.35%)
Table 10: Categories in the running taxonomy after each axial round. Each round covers five new pairs.
RoundPairs codedAddedRevisedTotal
1512012
2104016
3154020
4203023
5250023
6300023
Table 11: Guard-and-Go structural subtypes identified in model-generated patches.
SubtypeDefinition
Retained Path as Live FallbackGuards the reported case but leaves logic deleted by the official patch as the default path, allowing non-matching inputs to continue executing the retained logic.
Special-Case Carve-Out BypassAdds a branch or relaxes a precondition for one input category while leaving the general resolution mechanism unchanged.
Missing-Element Existence BypassChecks for a required runtime element and returns a default value when it is absent instead of evaluating the retained logic.
Failure-Site Symptom PatchSuppresses or compensates for the symptom at the failure site while leaving the producing control flow unchanged.
Exception Capture BypassCatches exceptions raised by retained logic and returns a default value instead of removing the underlying cause.
Post-Hoc Output CorrectionCorrects an incorrect result after the buggy computation has already completed.
Missing-Functionality InjectionIntroduces new logic or parameters to handle the reported case instead of adopting the restructuring performed by the official patch.
Upstream Reroute Around Retained BranchRedirects problematic inputs away from a retained branch, leaving the obsolete branch as unreachable legacy logic.
Parallel Duplicate-Path RetentionRetains logic that the official patch consolidates while introducing an additional execution path that can also satisfy the behavior.
Value-Compatibility ShimConditionally restores a legacy constant or decoding behavior for a specific input.
Table 12: Distribution of the ten Guard-and-Go structural forms. Of the 684 Guard-and-Go pairs, the closed-source classifier assigned a subtype to 550 and abstained on the remaining 134. Share is computed over the 550 typed pairs, and pass rate is the proportion of pairs that SWE-bench Verified records as resolved.
Structural formnSharePass rate
Retained Path as Live Fallback22140.2%68.3%
Special-Case Carve-Out Bypass9517.3%52.6%
Missing-Element Existence Bypass6010.9%81.7%
Failure-Site Symptom Patch519.3%66.7%
Exception Capture Bypass437.8%53.5%
Missing-Functionality Injection356.4%74.3%
Post-Hoc Output Correction203.6%80.0%
Upstream Reroute Around Retained Branch101.8%90.0%
Parallel Duplicate-Path Retention81.5%87.5%
Value-Compatibility Shim71.3%71.4%
All typed pairs550100.0%67.3%
Table 13: Heuristic used to prioritize behaviorally important deletion units.
SignalScore
Deleted lines are not reintroduced elsewhere+3.0
Complete control block is removed+3.0
Condition guarding existing code is changed or removed+3.0
Control-flow statement is removed+3.0
Complete function or class is removed+2.5
Decorator is removed+2.0
Comparison or Boolean logic is removed+1.5
Function or class signature is changed+1.5
Assignment is removed+1.0
Function or method call is removed+1.0
Deleted code contains problem-statement terms+2.0
Larger multi-line deletion unit+1.5
Import and its dependent code are removed+0.5
Standalone import is removed−4.0
Table 14: Task counts across the deletion-focused F2P construction process.
Selection stageCount
Tasks with at least 25% deletion69
Tasks included in deletion-unit analysis65
Tasks with a meaningful code deletion63
Tasks without a meaningful code deletion2
Deletion units identified166
Targets covered by a listed visible test24
Targets not covered by a listed visible test39
Host-validated deletion-focused F2P tasks34
Table 15: The four cumulative CanItDelete diagnostic modes.
ModeCumulative signalDiagnostic question
VanillaNo signal beyond the developer-style requestCan the model infer and execute the complete deletion end to end?
Explicit deletionRequires complete removal and forbids guards, comments, disabled branches, fallbacks, replacement code, and other workaroundsIs failure caused by not choosing a genuinely subtractive edit?
Region pointerIdentifies relevant functions, methods, or regions without revealing deletion boundariesIs finding every required region the principal obstacle?
Exact linesSupplies occurrence-specific spans and requires all unmarked text to be preservedCan the model execute a precise deletion once intent, location, and boundaries are known?
Table 16: Complete five-model diagnostic-ladder results. Four models use 200 tasks per mode; Claude Opus 4.8 uses 173. Cells report count (percentage).
ModeSuccessIncomplete deletionComplete deletion, invalid edit
GLM-5.2
Vanilla133 (66.5)30 (15.0)37 (18.5)
Explicit deletion128 (64.0)36 (18.0)36 (18.0)
Region pointer147 (73.5)29 (14.5)24 (12.0)
Exact lines175 (87.5)6 (3.0)19 (9.5)
GPT-5.6 Sol
Vanilla148 (74.0)20 (10.0)32 (16.0)
Explicit deletion144 (72.0)21 (10.5)35 (17.5)
Region pointer148 (74.0)19 (9.5)33 (16.5)
Exact lines161 (80.5)6 (3.0)33 (16.5)
MiniMax-M3
Vanilla134 (67.0)36 (18.0)30 (15.0)
Explicit deletion134 (67.0)32 (16.0)34 (17.0)
Region pointer137 (68.5)33 (16.5)30 (15.0)
Exact lines170 (85.0)6 (3.0)24 (12.0)
Claude Opus 4.8
Vanilla136 (78.6)25 (14.5)12 (6.9)
Explicit deletion138 (79.8)27 (15.6)8 (4.6)
Region pointer143 (82.7)19 (11.0)11 (6.4)
Exact lines169 (97.7)1 (0.6)3 (1.7)
Qwen3-235B-A22B
Vanilla50 (25.0)109 (54.5)41 (20.5)
Explicit deletion55 (27.5)105 (52.5)40 (20.0)
Region pointer54 (27.0)99 (49.5)47 (23.5)
Exact lines113 (56.5)35 (17.5)52 (26.0)

研究结果

  • 在五个顶尖模型全部通过的197个任务中,平均删除召回率为65.2%(Kimi-K2)到71.7%(Opus-4.5),而在五个模型全部失败的57个任务中进一步降至19.8%到30.4%。
  • 1,703个通过的补丁中有29.0%(494个)采用了Guard-and-Go策略,该策略的SWE-bench通过率为72.2%,低于直接删除替换策略的85.2%,但高于无关替代方案的39.6%。
  • 给34个任务加入删除敏感检测后,四个前沿模型的通过率从63.2%降至41.9%(下降21.3个百分点),原本通过的86次尝试中有29次仍保留着本应删除的目标代码。
  • 在包含200个任务的CanItDelete基准上,12个模型的成功率从79.0%(最好的Claude Opus 4.8)到18.0%(较弱的开源模型)不等;即便给出精确删除范围,Claude Opus 4.8达到97.7%,但Qwen3-235B仍有17.5%的任务留有目标代码。
  • 给一个7B模型的训练数据中加入12,821条删除样本(占训练token的0.7%)后,CanItDelete成功率从6.5%提升到13.7%,SWE-bench Verified提升5.3个百分点,CanItEdit提升1.4分,而EditBench基本没有变化。

可应用场景

  • 在合并AI生成的拉取请求前,除了检查测试是否通过,还应单独核查开发者补丁本应删除的代码是否真的被删除
  • 在自动化补丁评估流程中加入删除敏感测试(专门检测目标是否仍存在的FAIL_TO_PASS用例),以识别Guard-and-Go式的绕过补丁
  • 在代码编辑模型的后训练数据集中混入少量专门针对删除的样本,以降低模型的删除回避倾向
  • 在将LLM用于遗留代码清理、重构或死代码删除任务前,单独验证其删除能力

局限与待验证事项

  • 分析仅覆盖SWE-bench Verified排行榜上五个特定模型在固定OpenHands脚手架下的最新提交,结论未必适用于其他脚手架或更新一代的模型
  • 删除敏感检测将开发者删除的代码视为必须移除的目标,但也可能存在保留该代码、同时仍满足原始行为规范的替代修复方式,因此不能断定删除是唯一有效的解法
  • 34个删除敏感检测任务和CanItDelete的200个任务都是刻意挑选出删除比重高或完全以删除为目标的样本,并不能代表SWE-bench Verified整体或一般的代码仓库任务
  • 删除导向的后训练实验只是在单一7B内部模型、单一训练配方上做的概念验证,是否能在更大规模上保持效果仍留待未来研究
  • 加入删除训练数据后,不完整删除的问题减少了,但过度删除(超出边界删除)的问题却增加了,说明完成删除和控制删除边界是两个需要分别解决的训练目标

为什么重要

这项研究提供了具体证据,说明AI生成的代码补丁即使通过所有测试,仍可能把本该删除的过时代码留在代码库里,长期会让代码更难维护。对于负责代码审查或部署AI编程工具的人来说,不能仅凭'测试通过'来判断补丁质量,还需要单独检查删除是否真正完成。

本文术语

  • 删除回避(Deletion Avoidance) · 模型系统性地倾向于保留本应被某次编辑删除的代码的现象
  • Guard-and-Go · 模型保留应删除的逻辑,转而在外面加一层条件判断或旁路来绕开它的补丁模式
  • 删除召回率(Deletion Recall) · 开发者实际删除的代码中,模型也同样删除的比例
  • CanItDelete · 从真实提交中挑选的、整个所需编辑都是删除操作的200个任务组成的新基准
  • 删除敏感检测(Deletion-Sensitive Check) · 专门用来检测应删除的目标代码是否仍然存在的测试

论文原文摘要(英文)

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 fil

作者 · Amir M. Ebrahimi

在 arXiv 阅读

最新论文

全部论文 →

METAL MEDIA 最新报道

图片来源: Amir M. Ebrahimi et al., arXiv:2607.28887, CC BY 4.0