研究LLM修复代码时定位上下文的作用,发现过多上下文未必更好。
On the Role of Fault Localization Context for LLM-Based Program Repair
- 测试61种上下文配置,比较文件、元素、行级信息对修复的影响。
- 文件级上下文提升15-17倍效果,6-10个相关文件最有效。
- 行级上下文常因噪声降低性能,语义检索比规则方法更优。
故障定位(FL)是基于大语言模型(LLM)的自动程序修复(APR)的关键环节,但其影响尚未充分探索。我们基于GPT-5-mini,在500个SWE-bench Verified实例上开展大规模实证研究,评估了61种不同层级(文件级、元素级、行级)上下文配置。结果表明:更多上下文并不总能提升修复性能。文件级定位是主导因素,相比无文件基准,修复成功率提升15-17倍。扩展文件上下文通常有益,成功修复多见于约6-10个相关文件的配置。元素级上下文增益依赖文件上下文质量,而行级上下文因噪声放大常导致性能下降。基于LLM的检索方法总体优于结构启发式,且使用更少文件和标记。最佳策略是结合高层语义理解与精确行级定位。研究挑战了‘增加上下文即提升修复’的假设,为设计高效LLM驱动的故障定位策略提供实践指导。
原文摘要 · Abstract (English)
Fault Localization (FL) is a key component of Large Language Model (LLM)-based Automated Program Repair (APR), yet its impact remains underexplored. In particular, it is unclear how much localization is needed, whether additional context beyond the predicted buggy location is beneficial, and how such context should be retrieved. We conduct a large-scale empirical study on 500 SWE-bench Verified instances using GPT-5-mini, evaluating 61 configurations that vary file-level, element-level, and line-level context. Our results show that more context does not consistently improve repair performance. File-level localization is the dominant factor, yielding a 15-17x improvement over a no-file baseline. Expanding file context is often associated with improved performance, with successful repairs most commonly observed in configurations with approximately 6-10 relevant files. Element-level context expansion provides conditional gains that depend strongly on the file context quality, while line-level context expansion frequently degrades performance due to noise amplification. LLM-based retrieval generally outperforms structural heuristics while using fewer files and tokens. Overall, the most effective FL context strategy typically combines a broad semantic understanding at higher abstraction levels with precise line-level localization. These findings challenge our assumption that increasing the localization context uniformly improves APR, and provide practical guidance for designing LLM-based FL strategies.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。