Abstract
Automated Program Repair (APR) has recently transitioned from heuristic-based methods to Large Language Model (LLM) sampling. However, traditional "Generate and Validate" (G&V) approaches suffer from redundancy and a lack of execution context. This paper introduces Conversational APR, a paradigm that treats code repair as an iterative dialogue between the model and a validation suite. By incorporating execution feedback into subsequent prompts, LLMs can refine their logic and triangulate correct solutions. Experimental results on the QuixBugs benchmark demonstrate that this approach significantly improves repair success rates and efficiency, with ChatGPT fixing 28 out of 30 Python bugs within three turns.
Introduction
Automated Program Repair aims to reduce the manual effort of debugging by automatically generating patches. While the shift toward LLMs like Codex has improved performance, the standard "Generate and Validate" approach remains inefficient. In G&V, a model is prompted with a buggy snippet to generate numerous independent patches, which are then tested. This method is often redundant, lacks functional context, and provides no feedback loop when a patch fails. To address these limitations, we propose a conversational framework where the model learns from its mistakes through iterative feedback.
The Conversational APR Framework
Conversational APR transforms the repair process into a multi-turn dialogue. Each turn consists of three distinct steps: prompt construction, patch sampling, and validation. Unlike static sampling, the feedback loop ensures that if a patch fails, the specific error (e.g., an incorrect return value for a specific input) is appended to the conversation history.
This "contextual memory" allows the LLM to perform in-context learning, preventing it from repeating previous errors. The authors found that "functional prompts"—which provide concrete examples of failing test cases—are significantly more effective than abstract natural language descriptions of the bug.
Experimental Setup
The framework was evaluated using the QuixBugs benchmark, comprising 40 classic algorithmic bugs in Python and Java. The study tested 10 different LLMs, including various sizes of CodeGen, Codex, and ChatGPT. The primary metric was the number of bugs fixed within a limited number of conversational turns (chain length).
Results and Discussion
The conversational approach yielded marked improvements across all tested models. Larger models demonstrated a superior ability to handle long-term dependencies in the conversation, making them more resilient as the chain length increased.
Key Findings:
- Efficiency: Conversational APR reaches correct patches in fewer total samples than baseline G&V.
- The "Sweet Spot": For many models, a chain length of 3 to 4 turns is optimal. Beyond this, smaller models may become overwhelmed by the history of failed attempts, leading to a performance plateau or dip.
- ChatGPT Dominance: ChatGPT, optimized via Reinforcement Learning from Human Feedback (RLHF), proved exceptionally adept at "listening" to feedback, fixing 93% of the Python bugs in the benchmark within three turns.
Conclusion and Future Work
Conversational APR represents a significant step toward more intelligent, interactive debugging tools. While highly effective, the approach currently faces challenges in representing complex data structures (like large graphs) in text-based prompts and the increased token cost of longer conversation histories. Future research will explore more sophisticated feedback mechanisms, such as stack traces and human-in-the-loop integration, to further enhance the repair capabilities of LLMs.
Summary updated