HAFixAgent:历史感知的自动化程序修复智能体
HAFixAgent: History-Aware Automated Program Repair Agent
November 2, 2025
作者: Yu Shi, Hao Li, Bram Adams, Ahmed E. Hassan
cs.AI
摘要
近年来,自动化程序修复(APR)研究已转向大语言模型和基于智能体的系统,但现有系统大多依赖本地快照上下文,忽略了代码库历史。已有研究表明,代码库历史有助于单行错误的修复,因为最后修改错误代码行的提交往往就是引入该错误的提交。本文系统性地探究代码库历史能否在大规模场景下提升智能体式APR系统的性能,特别是针对复杂的多区块错误。我们提出HAFixAgent——一种历史感知的错误修复智能体,它将基于代码追溯的仓库启发式信息注入修复循环。通过对Defects4J中全部854个真实错误的初步研究,我们发现与错误相关的历史信息不仅广泛存在且高度集中,这为系统设计提供了依据。HAFixAgent与两种前沿基准方法的实证对比表明:(1)有效性:相较基于智能体的基准方法提升212.3%,较针对多区块错误的基准方法提升29.9%;(2)效率:历史信息未显著增加智能体步骤,令牌成本保持相当水平,且在复杂多文件-多区块错误场景下中位数成本显著降低;(3)实用性:组合不同历史启发式策略可修复更多错误,形成清晰的成本效益权衡。HAFixAgent为历史感知的智能体式APR提供了实用方案:将智能体锚定于版本控制历史,优先采用基于差异的历史上下文,并在需要时整合互补性启发式策略。
English
Automated program repair (APR) has recently shifted toward large language
models and agent-based systems, yet most systems rely on local snapshot
context, overlooking repository history. Prior work shows that repository
history helps repair single-line bugs, since the last commit touching the buggy
line is often the bug-introducing one. In this paper, we investigate whether
repository history can also improve agentic APR systems at scale, especially
for complex multi-hunk bugs. We present HAFixAgent, a History-Aware Bug-Fixing
Agent that injects blame-derived repository heuristics into its repair loop. A
preliminary study of all 854 real-world bugs from Defects4J motivates our
design, showing that bug-relevant history is both widely available and highly
concentrated. Empirical comparison of HAFixAgent with two state-of-the-art
baselines shows: (1) Effectiveness: HAFixAgent significantly improves over the
agent-based baseline (by 212.3%) and the multi-hunk baseline (by 29.9%). (2)
Efficiency: history does not significantly increase agent steps and keeps token
costs comparable, with notably lower median costs for complex
multi-file-multi-hunk bugs. (3) Practicality: combining different historical
heuristics repairs more bugs, offering a clear cost-benefit trade-off.
HAFixAgent offers a practical recipe for history-aware agentic APR: ground the
agent in version control history, prioritize diff-based historical context, and
integrate complementary heuristics when needed.