Editor’s introduction
The study evaluates HAFixAgent, an agent-based program repair system that integrates blame-derived repository history into its repair process. Across 854 Java and 501 Python bugs from Defects4J and BugsInPy, researchers found that bug-relevant history is widely available, with 71.1% and 87.4% of Java and Python bugs respectively having blameable commits. The best history heuristic improved repair success by up to 64.3% on weaker models, outperforming baseline agents like RepairAgent and BIRCH-feedback. The three history heuristics are complementary, each repairing a distinct subset of bugs, and their hybrid approach significantly increases overall repair coverage, with statistical significance under realistic fault localization. This advantage persists even when localization is imperfect, though individual heuristics lose effectiveness on weaker models due to misleading history injection from faulty fault localization. The hybrid approach maintains performance across models, demonstrating robustness in real-world conditions where fault localization is not perfect.
Introduction
Since manually identifying and fixing software bugs consumes significant developer time and resources, automated program repair (APR) has been an active and promising research direction for over a decade, aiming to mitigate this burden by automatically generating patches for detected bugs. APR has evolved from heuristic-based, constraint-based, and template-based techniques to learning-based methods and, most recently, large language model-based approaches and agent-based approaches. However, despite substantial progress, reliably repairing complex bugs remains challenging.
We hypothesize that adapting history-based context from the single-line setting to multi-line and multi-file bugs, and giving it to an agent that acts on it over multiple turns, can improve their repair as well. History provides information on relevant past changes, developer rationale, and co-evolution patterns, while an agent can exploit this rich history across multiple repair turns. Yet it is unclear whether this benefit materializes at scale, whether it survives realistic fault localization, and whether the three history heuristics are redundant or genuinely complementary.
RQ0. To what extent is historical information available in real-world bugs? Before integrating repository history, we first establish whether relevant historical information is broadly available for use in APR, since it is not always present: some bugs are fixed only by inserting missing or new code, which git blame cannot annotate, leaving them blameless. We analyze both Defects4J and BugsInPy to measure the availability and concentration of historical information. Our findings confirm that 71.1% (Defects4J) and 87.4% (BugsInPy) of bugs have available historical information. In Defects4J, 99.5% of blameable bugs map to a single blame commit, while BugsInPy shows more scattered blame (58.4% single-commit).
LLM and Agent-based APR
Large language models have significantly advanced APR, outperforming prior learning-based approaches. Conversation-driven repair simulates debugging by interleaving generation with test feedback. Self-directed repair uses chain-of-thought to gather knowledge before fixing. Hybrid and template-guided methods constrain the patch space with analysis or repair templates.
Agent-based APR represents a further step, shifting from single-shot generation to autonomous, tool-using workflows. An LLM-based agent couples reasoning with memory and tools within an iterative execution loop, often conceptualized as a Reason-Act (ReAct) cycle. This approach is central to Agentic Software Engineering. SWE-agent introduced an Agent-Computer Interface with developer-centric tools for resolving GitHub issues. OpenHands builds generalist agents, and RepairAgent provided dedicated toolsets for code reading, patch generation, and test feedback. AutoCodeRover enhanced agents with program analysis context, while multi-agent collaboration and empirical studies are mapping this design space. A recent trend incorporates memory and experience from prior repair trajectories. Prometheus further introduces a memory-centric framework with a unified knowledge graph for long-horizon codebase navigation. Agentless questions whether full autonomy is necessary, showing that a simple localize-repair-validate pipeline can rival agent-based systems. However, these systems generally rely on local code and runtime outputs, with limited study of commit history as a first-class context inside the loop, which is the focus of this work.
Context and History for APR
A core question for LLM-based APR is which context to provide. Prior work shows that adding bug-related facts such as error messages, stack traces, and failing tests improves repair, and that models are sensitive to how much code surrounds the edit region. Other work leverages natural language bug reports or repository-level evaluations.
Beyond local signals, decades of Mining Software Repositories (MSR) research have established that historical data is a powerful asset for understanding and fixing bugs. pioneered history-driven repair by mining bug-fix patterns that recur across many projects and prioritizing patch candidates that match them. This differs from our history: we retrieve the specific commit that last modified the buggy lines, not fixes to similar bugs elsewhere. More recently, git blame, which annotates each line with the commit that last modified it, provides a direct heuristic for identifying the bug-introducing commit, aligning with the SZZ algorithm’s core assumption. The last commit to touch a line is, however, a heuristic proxy for, not a guarantee of, the true bug-inducing commit (BIC). A separate line of work identifies BICs more precisely: FONTE ranks commits by fault-localization-weighted suspiciousness from a failure, SemBIC statically tracks semantic changes along the failing execution path across history, and LLM4SZZ augments SZZ with LLM-based assessment.
HAFixAgent adopts the lightweight blame proxy and measures its aggregate effect, and integrating principled BIC identification is a complementary direction. HAFix demonstrated that injecting this blame-derived context significantly improves repair for single-line bugs. Layered knowledge injection systematically adds project and repository knowledge to prompts. HAFixAgent advances this direction by bringing blame-driven history into the agentic workflow and quantifying its effect on both single-hunk and multi-hunk bugs across two benchmarks.
Motivation
Providing LLM agents with informative context is essential for effective repair. While most context engineering approaches for automated program repair (APR) focus on knowledge obtained from a given snapshot of a code base, only recently APR techniques were proposed that leverage code history. Inspired by the domain of mining software repositories, prior work on single-line APR uses context related to the last commit that touched the bug location, as the latter commit commonly is assumed to be the bug-introducing commit and hence has valuable knowledge about the introduced bug. Finding this commit for single-line bugs is straightforward (as obtained using the git blame command), as they only comprise one buggy line.
Unfortunately, more complex bugs touching one hunk, multiple hunks in one file or multiple hunks across files potentially would require combining blame commit information of many different lines, potentially drowning the latter information within an LLM’s token window, and hence reducing the performance of historical context for APR. In such a case, an APR technique would need to aggregate and rank multiple blame history sources, increasing prompt size, latency, and the risk of distraction.
Furthermore, for a given buggy snapshot of the code base, blame commits do not exist for all buggy lines. For instance, when the fault location is actually an insertion point (where code currently is missing) rather than an existing line that needs to be modified, git blame cannot be applied, as it can only annotate existing code. Hence, the more likely bug fixes insert lines instead of modifying them, the less applicable a blame-based historical APR technique would become, unless a workaround can be found.
Dataset
To study the availability and distribution of historical information in real-world bugs across languages, we choose two established benchmarks. Defects4J (v3.0.1) is a standard and widely-used benchmark for evaluating recent APR techniques. It contains 854 Java bugs alongside test cases for each bug collected from 17 different open-source projects, spanning various domains such as data visualization (Chart), compiler construction (Closure), and date/time utilities (Time). BugsInPy is a benchmark of 501 Python bugs collected from 17 popular open-source projects, including data processing (pandas), web frameworks (fastapi, tornado), and utility libraries (tqdm, thefuck). BugsInPy complements Defects4J by covering a dynamically typed language with different development practices and commit patterns.
In this preliminary RQ, we use the oracle bug fix provided by each benchmark in a post-hoc manner to identify the buggy lines (i.e., the lines in the buggy snapshot that were modified or deleted in the fix), then run git blame on exactly these lines to obtain the most recent commits that previously modified them. We then de-duplicate the commit hashes for each bug, count each bug’s unique blame commits, and compute the distribution by bug category.
Bug Category Terminology
To categorize bugs based on the structure of their bug fix commits, we first define a hunk as a single, contiguous block of edits (i.e., additions, deletions, or modifications) applied to a specific region in the source code, similar to earlier work. A patch file can contain one or more such hunks, and a bug fix can change more than one such file. Furthermore, following prior work on bug categorization, we classify bugs in both datasets into four mutually exclusive categories based on the number and location of these hunks: (1) Single-Line (SL): The fix edits exactly one line in one file. (2) Single-Hunk (SH): The fix edits one contiguous hunk of multiple lines in one file. (3) Single-File-Multi-Hunk (SFMH): The fix contains two or more distinct hunks confined to a single file. (4) Multi-File-Multi-Hunk (MFMH): The fix contains hunks that span two or more different files. Unlike prior work that either nests SL within SH or collapses SFMH and MFMH into one multi-hunk class, we keep all four categories separate for finer granularity.
We also categorize bugs by blame availability, i.e., whether the buggy version contains an existing faulty line that fault localization could point to and git blame can annotate. (1) Blameable: the bug fix modifies or deletes at least one existing line in the buggy snapshot, so such a faulty line exists for fault localization to identify and git blame to annotate. The fix is therefore not purely new code. (2) Blameless: the bug fix only inserts new lines or files, with no deletions or modifications, so no existing faulty line exists, and fault localization can at most indicate where new code is needed.
Results
Historical blame commit information is broadly available, even for complex bugs, with 71.1% of Defects4J and 87.4% of BugsInPy bugs blameable. In Defects4J, complex multi-hunk bugs (SFMH and MFMH), which account for 64.8% of the dataset, maintain high history availability: 69.2% of SFMH and 80.5% of MFMH bugs are blameable. SH has the lowest rate at 52.2%, as single-hunk bugs are more frequently pure insertions. In BugsInPy, blame availability is even higher across all categories, with SL at 92.7%, SFMH at 91.6%, and MFMH at 92.3%, while SH remains the lowest at 73.8%, consistent with the Defects4J pattern. These results indicate that historical blame data is commonly available across bug categories and both datasets, supporting history-aware APR techniques. For bugs with no blame commit (28.9% in Defects4J, 12.6% in BugsInPy), a workaround would be required.
Agent Execution Loop
HAFixAgent’s execution loop follows an observe-act-feedback paradigm, inspired by frameworks like ReAct and those used in recent software engineering agents. The loop proceeds with the following steps. 5 The LLM receives the current state (including the full conversation history of prior actions and observations). 6 The agent parses the model output to extract a tool invocation (i.e., a bash command, which the system prompt constrains the model always to provide) as the next action. 7 The command runs in a containerized tool sandbox that exposes repair utilities and dataset tools (e.g., search, edit and compile). 8 Stdout and stderr are collected from the output of command execution as feedback. 9 Compilation and test outcomes are captured and parsed. 10 The loop terminates on success or when a termination guard (e.g., step limit, cost limit, or timeout) is reached. 11 Otherwise, the observation is appended to the conversation history and fed back to the LLM for the next reasoning step.
Tools
The agent invokes standard bash tools (grep, sed, find, and head/tail for file operations, compile and test for project validation, and echo for completion signaling), with optional chaining via && or ||. These actions are executed between steps 7 and 8 in the loop, and the full toolset is embedded in the system prompt (available in the replication package).
HAFixAgent intentionally exposes a simple but powerful set of bash tools together with project commands like compile and test. A key design choice is that the historical context is not an interactive tool, but is instead modularized and prepared by the History Extractor and injected directly into the agent’s context before the execution loop begins. This decouples history retrieval from agent actions, which allows the agent’s toolset to remain simple, modular, scalable and focused on repair-related operations (e.g., read, edit and test).
In practice, the loop alternates between reading around fault locations, applying edits, compiling, and testing until all tests pass. Termination occurs when the agent emits a completion signal after passing tests, or when a guard (step, cost, or timeout) is reached.
Motivation
All experiments so far assume perfect fault localization, which is unrealistic in practice: real FL tools produce imprecise locations. Hence, when blame is computed on incorrect lines, irrelevant commits may be retrieved by our approach, potentially negating the history benefit. While perfect FL remains the right setting for isolating history’s effect in RQ1, because it removes localization as a confound, this RQ complements that controlled result with a realism check: it re-runs all configurations under spectrum-based fault localization (SBFL), an automated technique that ranks suspicious code from test coverage, to test whether the history benefit observed under perfect localization survives the imperfect locations a practitioner would actually obtain. Prior history-aware APR assumes perfect FL, while the closest agentic system, RepairAgent, reports realistic FL only for a 100-bug Defects4J subset and only for overall repair. Our empirical evaluation pairs perfect and realistic FL on the same bugs, all 827 Defects4J and 361 BugsInPy bugs for which SBFL produces a ranking, across two languages and three base models.
Threats to Validity
Internal Validity. DeepSeek-V3.2-Exp is available as open weights, but the pretraining corpus is not disclosed to our knowledge. As a result, we cannot verify if the specific projects or bugs in Defects4J are included in the pretraining data. However, our evaluation focuses on the relative effectiveness improvement of different historical heuristics, rather than their absolute performance. For instance, if HAFixAgent-fl_diff fixes a bug that HAFixAgent-non-history does not fix, this improvement is attributed to the benefit of historical context, regardless of whether the LLM has seen the bug before.
Our RQ1 evaluation assumes perfect fault localization, a common setup in LLM-based APR studies. To mitigate this threat, RQ2 evaluates HAFixAgent under realistic SBFL with GZoltar and FauxPy. Under realistic localization the complementarity remains significant (the hybrid approach still beats non-history on both benchmarks), and the best history configuration remains numerically ahead, so the perfect-FL results are not merely an artifact of idealized localization.
External Validity. Our study evaluates on Defects4J (854 Java bugs) and BugsInPy (501 Python bugs). While this covers two languages and 34 projects, results may not transfer to other ecosystems where project size, test adequacy, and repository practices differ. The history profiles already differ between our two benchmarks (e.g., 99.5% single-commit in Defects4J versus 58.4% in BugsInPy), suggesting that history-aware techniques may need adaptation per ecosystem. We expose a dataset-agnostic interface behind the history extractor and release all code and scripts for replication. Evaluating on repository-level benchmarks such as SWE-bench is future work.
Conclusion and Future Work
This paper presented HAFixAgent, a history-aware agentic approach that injects blame-derived repository context into an observe-act-verify loop to repair single- and multi-hunk bugs. A preliminary study on 854 Defects4J (Java) and 501 BugsInPy (Python) bugs shows that blame commit history is widely available (71.1% and 87.4% blameable, respectively), with Defects4J blame highly concentrated in a single commit (99.5%) while BugsInPy shows more scattered blame (58.4% single-commit).
Using the same LLM for all experiments including replicated baselines, we find that under perfect fault localization the net benefit of history is modest (+4.4% on Defects4J, +1.1% on BugsInPy), but the three history heuristics are complementary: each repairs a different subset of bugs, so combining them into a hybrid approach repairs significantly more bugs than non-history. The gain from history generalizes across all three base models and is larger on the two weaker ones, and the complementarity remains significant under realistic SBFL. History does not inflate agent cost on either benchmark. On the same LLM, HAFixAgent outperforms the RepairAgent (+56.6%) and BIRCH-feedback (+47.1%) baselines, showing it is a strong repair agent independent of history.
Three promising directions for future work emerge from our findings. First, the complementarity of the three heuristics shows that repository history is rich: each heuristic repairs bugs the others miss, so no individual heuristic uses all of it. Future work should design more diverse heuristics over richer historical context, such as commit messages as a standalone heuristic, issue and pull-request discussions, and co-change relations, and design approaches to combine them per bug. Such an approach could also adapt the history during repair, for example by filtering it for relevance or by dropping it when the first repair steps show no progress, and reach the bugs repaired by the hybrid approach in a single run. Second, HAFixAgent currently uses an LLM judge to select a single blame commit. For BugsInPy bugs where 41.6% have multiple blame commits, combining context from several blame commits could further improve repair effectiveness. Third, evolving HAFixAgent into a multi-agent architecture with specialized History, Fixer, and Reviewer agents could improve repair of complex MFMH bugs where a single agent’s context window is easily overwhelmed.


