TL;DR
This paper investigates whether automated program repair (APR) techniques can fix bugs in code generated by large language models (LLMs) like Codex. They found that LLM-generated code shares common bugs with human code, and while existing APR tools have limited success, Codex's own editing capabilities show promise, especially when guided by fault localization information.
What Problem Does This Paper Address?
Large Language Models (LLMs) like Codex have demonstrated impressive capabilities in generating code from natural language descriptions. However, their success rate, particularly for complex programming tasks, remains relatively low. A key reason is their lack of deep understanding of program semantics, leading to incorrect or even non-compiling code. This paper addresses the gap in understanding how to improve the reliability of LLM-generated code by exploring whether established Automated Program Repair (APR) techniques can fix these generated programs. They also investigate the potential of LLMs themselves, specifically Codex's edit mode, as a repair tool.
Methods
The authors systematically evaluate the effectiveness of existing APR tools and Codex's edit mode on code generated by Codex for LeetCode programming tasks. Their methodology involves:
- Code Generation: Using Codex to generate initial solutions for programming tasks.
- Bug Identification: Identifying incorrect solutions that fail public and private test cases.
- APR Tool Evaluation: Applying established Java APR tools (TBar and Recoder) to fix these buggy solutions.
- Codex Edit Mode Evaluation: Testing Codex's edit mode (Codex-e) with different prompting strategies (e.g., "Fix bug in the program," "Fix line N," or providing specific code snippets) to see if it can repair the generated code.
- Defect Analysis: Manually categorizing the types of bugs found in Codex-generated code to understand common error patterns.
- Combination Strategies: Exploring how combining the patch spaces of different tools (APR tools and Codex-e) can lead to more effective repairs.
Datasets
- LMDefects: A newly introduced dataset comprising 113 Java programming tasks from LeetCode contests released after June 2021. This dataset was curated to avoid overlap with Codex's training data and includes easy and medium-level problems. Existing datasets were avoided due to potential training data overlap or lack of public tests required for APR.
Key Insights and Ideas
- LLM Bugs Mirror Human Bugs: Surprisingly, the types of bugs found in LLM-generated code (e.g., algorithm-related, syntax errors) are similar to those found in human-written code, suggesting that existing APR techniques might be applicable.
- Codex-e as a Promising Repair Tool: Codex's edit mode, especially when provided with specific fault localization information (like "Fix line N" or code snippets), demonstrates effectiveness in fixing bugs, sometimes outperforming traditional APR tools.
- Fault Localization is Key: The effectiveness of Codex-e is significantly enhanced when guided by fault localization information, highlighting the importance of pinpointing bug locations for repair.
- Limitations of Traditional APR: Existing APR tools struggle with complex bugs, multi-line fixes, and lack awareness of program dependencies, which are common in LLM-generated code.
- Complementary Strengths: Combining the patch generation capabilities of traditional APR tools with the flexibility of LLMs like Codex-e can cover a wider range of bugs and produce more comprehensive fixes.
Key Results
- Bug Patterns: 57% of Codex bugs are algorithm-related, and 11% are syntax errors. Approximately 32% of bugs require larger patches (more than five lines).
- APR Tool Effectiveness: TBar and Recoder could fix only a small fraction of the buggy solutions. Recoder performed slightly better, fixing 8 tasks compared to TBar's 6.
- Codex-e Performance:
- Codex-ebug (general "Fix bug" instruction) fixed 15 solutions.
- Codex-eline (specific line instruction) fixed 11 solutions.
- Codex-estm (instruction with code snippet) fixed 16 solutions, showing the best performance among the Codex-e strategies.
- Flexible Repair: Codex-e demonstrated the ability to generate patches at flexible locations, even beyond the specified line, which is a significant advantage over traditional APR tools.
- Combined Approach: Combining TBar and Codex-e successfully generated required patch ingredients for 9 incorrect solutions, with 2 of these being unfixable by either tool alone.
Limitations and Future Work
- Dataset Bias: The study focused on Java and LeetCode tasks, and findings might not generalize to other languages or programming domains.
- Codex Black Box: Codex-e was treated as a black box, and its internal mechanisms for generating edits were not analyzed.
- APR Tool Limitations: Existing APR tools still struggle with multi-line fixes and understanding program dependencies.
- Future Directions:
- Developing community-driven datasets for LLM defects.
- Enhancing LLMs with software engineering artifacts like fault localization.
- Exploring more flexible fault localization strategies for APR.
- Investigating how to effectively combine LLMs and APR tools for patch ingredient generation.
- Developing better methods for guiding LLMs like Codex-e through carefully crafted instructions.
Summary updated