ChatPaper.aiChatPaper

「添加是機器所為,刪除是人類所為:衡量並緩解大型語言模型程式碼編輯中的刪除迴避」

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

摘要

大型語言模型日益頻繁地撰寫與修復生產環境程式碼,然而越來越多的證據顯示,它們通過測試的修補程式反而讓程式碼庫更難維護。我們找出一個具體成因:刪除迴避(deletion avoidance),亦即系統性地傾向保留預期編輯中應刪除的程式碼。在官方 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.