Abstract
Automated Program Repair (APR) has traditionally focused on fine-grained, line-level fixes, which rely heavily on expensive statement-level fault localization. This paper introduces SRepair, a dual-LLM framework designed for practical function-level repair. By leveraging a "Chain of Thought" approach to generate natural language repair suggestions before code generation, SRepair achieves a new state-of-the-art on the Defects4J benchmark, fixing 300 bugs—an 85% improvement over previous methods. Notably, SRepair also demonstrates the first successful automated repair of multi-function bugs.
Introduction: The Practicality of Function-Level Repair
Automated Program Repair (APR) aims to automatically fix software bugs, reducing the burden on developers. Historically, APR tools have operated at the single-line or hunk-level (small blocks of code). While these approaches are precise, they suffer from a significant "hidden cost": the requirement for statement-level fault localization. To fix a bug, these tools must first be told exactly which line is broken—a task that is often as challenging as the repair itself.
This research advocates for a shift toward function-level repair. Instead of pinpointing a specific line, the repair tool is provided with the entire buggy function. Identifying a buggy function is significantly easier and cheaper than identifying a buggy line, making this approach more practical for real-world software engineering. However, function-level repair presents a larger search space and more complex logic, posing a challenge for traditional AI models.
The SRepair Framework
To address the complexities of function-level repair, the authors developed SRepair, a dual-LLM framework that separates the logic of bug analysis from the syntax of code generation.
SRepair operates in two distinct stages:
- Repair Suggestion Model: Utilizing GPT-3.5-Turbo and a Chain of Thought (CoT) prompting strategy, this model analyzes the buggy code alongside "auxiliary information" such as triggering test cases, error messages, and comments. It identifies the root cause and provides a repair suggestion in plain English.
- Patch Generation Model: This stage uses Magicoder, an open-source model, to translate the natural language suggestions and the original buggy code into a final, patched function.
By decoupling "thinking" (logic) from "coding" (syntax), SRepair avoids the common pitfall where LLMs become distracted by complex code structures and lose track of the underlying bug logic.
Empirical Insights and LLM Behavior
Before finalizing SRepair, the authors conducted an extensive study on six LLMs (including GPT-3.5-Turbo, CodeLlama, and Magicoder) to understand their performance in function-level repair. Several key insights emerged:
- Zero-shot vs. Few-shot: Surprisingly, providing examples of fixes (few-shot learning) often degraded performance. LLMs tended to prioritize mimicking the style of the examples over solving the specific logic of the bug at hand, frequently leading to uncompilable code.
- The Distraction of Fault Localization: Explicitly labeling a buggy line can mislead an LLM. If a fix requires changes across multiple lines, the model may over-focus on the labeled line, failing to grasp the broader logic error.
- The Power of Auxiliary Information: Triggering tests and error messages are highly effective. Incorporating these into the prompt significantly improved repair performance, often compensating for the lack of fine-grained fault location data.
Evaluation and Results
The framework was evaluated on the Defects4J (v1.2 and v2.0) benchmark, the gold standard for Java APR, and QuixBugs, which tests cross-language generalizability in Python and Java.
SRepair established a new state-of-the-art by correctly fixing 300 single-function bugs in Defects4J. This represents an 85% improvement over the previous leading tool, ChatRepair (162 bugs), and is 1.59x more effective than Repilot. Furthermore, SRepair achieved a historic milestone by successfully fixing 32 multi-function bugs—bugs spanning different functions that must be corrected simultaneously—a feat previously unachieved in the field of APR.
In terms of efficiency, the tool is remarkably cost-effective. Repairing 300 bugs cost a total of $8.60 in API fees, averaging just $0.029 per correct fix. On the QuixBugs benchmark, SRepair achieved a 100% success rate for both Python and Java.
Conclusion
SRepair demonstrates that Large Language Models, when structured within a dual-model framework using Chain of Thought reasoning, can effectively bridge the gap between line-level and function-level program repair. By focusing on the function level, APR becomes a more practical tool for developers, reducing the reliance on expensive fault localization. Future work will explore integrating broader project context, such as class structures, to address even more complex system-wide bugs.
Summary updated