Abstract
This paper introduces INTERVENOR (INTERactiVE chaiN Of Repair), a system designed to emulate the interactive code repair processes observed in humans, encompassing both code diagnosis and code repair. INTERVENOR prompts Large Language Models (LLMs) to play distinct roles during the code repair process, functioning as both a Code Learner and a Code Teacher. Specifically, the Code Learner is tasked with adhering to instructions to generate or repair code, while the Code Teacher is responsible for crafting a Chain-of-Repair (CoR) to serve as guidance for the Code Learner. During generating the CoR, the Code Teacher needs to check the generated codes from Code Learner and reassess how to address code bugs based on error feedback received from compilers. Experimental results demonstrate that INTERVENOR surpasses baseline models, exhibiting improvements of approximately 18% and 4.3% over GPT-3.5 in code generation and code translation tasks, respectively. Our further analyses show that CoR is effective to illuminate the reasons behind bugs and outline solution plans in natural language. With the feedback of code compilers, INTERVENOR can accurately identify syntax errors and assertion errors and provide precise instructions to repair codes.
Introduction: Overcoming Cognitive Inertia in Coding
Even advanced Large Language Models (LLMs) struggle to generate bug-free code on the first attempt. While "Self-Repair" techniques—where a model attempts to fix its own mistakes—have shown promise, they often fall victim to Degeneration-of-Thought (DoT). DoT is a form of cognitive inertia: if a model wrote the buggy code, it is statistically likely to overlook that same bug during review because the error aligns with its internal pre-existing thinking. To fix complex bugs, models require external grounding from a compiler and a structured way to rethink the problem.
The INTERVENOR Framework
INTERVENOR facilitates an interactive dialogue between two specialized agents to break the cycle of buggy code generation. The system mimics human-like interactive debugging by splitting the LLM into distinct roles:
- The Code Learner (Student): Responsible for generating the initial code and subsequently repairing it based on specific instructions.
- The Code Teacher: Acts as an experienced instructor. It examines the buggy code and the compiler's error message to craft a Chain-of-Repair (CoR).
The Workflow
- Generation: The Student generates code for a specific task.
- Check: The code is processed by a compiler. If it fails, the compiler provides a specific error message (e.g.,
AssertionErrororTypeError). - Instruction: The Teacher analyzes the bug and the error message to generate the CoR—a natural language explanation of why the code failed and a plan to fix it.
- Repair: The Student uses the CoR to rewrite the code. This loop continues until the code passes or a turn limit is reached.
The Chain-of-Repair (CoR)
The core innovation of this framework is the CoR, which acts as a bridge between cryptic compiler errors and the final code fix. By forcing the model to "think" in natural language before jumping back into syntax, INTERVENOR provides the necessary grounding to resolve complex logic errors.
Experimental Evaluation
The researchers evaluated INTERVENOR on several standard benchmarks, including HumanEval, MBPP, HumanEval-X (multi-lingual), and DS-1000 (data science). Additionally, the authors introduced CodeError, a new benchmark containing 4,463 examples of buggy code snippets across six error types (Assertion, Name, Type, Index, Value, and Syntax errors) to specifically test repair proficiency.
Key Results
- Performance Gains: INTERVENOR achieved an 18% improvement over GPT-3.5 on standard code generation benchmarks and a 4.3% improvement in code translation.
- Repair Proficiency: On the CodeError benchmark, INTERVENOR doubled the number of successfully repaired codes compared to standard prompting methods.
- Iterative Efficiency: Performance generally peaks around three turns of repair, suggesting that a few rounds of structured feedback are sufficient for most common bugs.
- Cross-Model Synergy: A stronger model (like GPT-4) acting as a Teacher can significantly improve the performance of a smaller Student model.
Conclusion and Future Work
INTERVENOR demonstrates that role-playing and natural language reasoning can effectively mitigate Degeneration-of-Thought in LLMs. However, the system's success remains tethered to the underlying LLM's reasoning capabilities and the robustness of the test suite. Future work may involve agents that generate their own unit tests to identify logical errors that do not trigger standard compiler failures.
Summary updated