Introduction
Self-repair—a process where a Large Language Model (LLM) attempts to debug and fix its own generated code—is frequently presented as a significant advancement in autonomous AI programming. The intuition is straightforward: if a program fails a unit test, the model should be able to interpret the error and iterate toward a solution, much like a human developer. However, this iterative process incurs a hidden cost: each repair attempt represents an additional model invocation. This research investigates whether self-repair is truly more compute-efficient than simply drawing more independent, identically distributed (i.i.d.) samples from the model.
Methodology: Formalizing the Repair Process
To evaluate self-repair rigorously, the researchers introduced Repair Trees. This framework starts with a problem specification and branches into several initial programs. Each failing program can then branch into multiple feedback strings, which in turn lead to multiple repaired versions.
A fair comparison requires evaluating models at an equivalent compute budget. The authors utilized a modified pass@k metric, where $k$ represents the total number of programs generated, whether they are initial samples or repair attempts. The study benchmarked three prominent models: Code Llama-13b-instruct, GPT-3.5-turbo, and GPT-4, using the HumanEval and APPS datasets.
The Feedback Bottleneck
The core challenge identified in the study is the "Feedback Bottleneck." For self-repair to be effective, the model must accurately diagnose its own errors. If the feedback is low-quality or misleading, the subsequent repair attempt is essentially a blind guess.
As illustrated in the example above, the model often struggles with subtle logic. In the "next Sunday" problem, the initial code failed for the input 'SUN' because of a modulo operation. While the feedback correctly identified the discrepancy, the model's ability to fix it depends entirely on the clarity of that internal or external critique. The study found that models often fail to provide the high-quality explanations necessary for successful debugging.
Key Results and Performance Analysis
The experimental results suggest that self-repair is not a "silver bullet." On the APPS dataset, GPT-4's self-repair performance only marginally outperformed the i.i.d. baseline—by approximately 5-8%—when controlled for compute budget. For weaker models like GPT-3.5 and Code Llama, self-repair frequently performed worse than simply generating more independent samples.
The data indicates that diversity often outweighs depth. For a fixed budget, generating a diverse set of initial programs is generally more effective than spending that budget on deep, multi-stage repairs of a single faulty program. However, self-repair showed more promise on high-difficulty "Competition" level tasks, where the probability of a random correct sample is extremely low.
The Human Gap and Feedback Boosting
To isolate the bottleneck, the researchers conducted "feedback boosting" experiments. When a stronger model (GPT-4) provided feedback for a weaker model (Code Llama), repair success rates surged. Furthermore, a human study revealed a significant performance gap: GPT-4 fixed 52.6% of programs when given human feedback, compared to only 33.3% with its own feedback. Humans tended to suggest high-level logical corrections, whereas LLMs often focused on minor, often incorrect, syntactic tweaks.
Conclusion
While self-repair mimics human workflows, its current implementation in LLMs is limited by the models' inability to accurately explain their own mistakes. For most tasks, the most compute-efficient strategy remains sampling a larger number of independent solutions. Future improvements in self-repair will likely depend on fine-tuning models specifically for code explanation and debugging logic, rather than just code generation. Until then, "regenerate" may be a more powerful tool than "repair."
Summary updated