Is Self-Repair a Silver Bullet for Code Generation?

Theo X. Olausson, Jeevana Priya Inala, Chenglong Wang, Jianfeng Gao, Armando Solar-Lezama

TL;DR

Self-repair—where an LLM attempts to debug and fix its own code—is often less effective than simply drawing more random samples from the model when compute budgets are equal. The primary bottleneck is the "feedback" stage: models struggle to explain their own mistakes, and providing high-quality feedback (from humans or stronger models) is the only way to unlock significant performance gains.

What Problem Does This Paper Address?

Large Language Models (LLMs) like GPT-4 are impressive at coding, but they often stumble on complex logic. A popular strategy to fix this is self-repair: the model generates code, runs it against unit tests, looks at the error, explains the failure, and tries to fix it.

Self-repair pipeline example

While this sounds intuitive—it's how humans code, after all—it isn't "free." Every repair attempt is a model invocation that could have been used to just generate a fresh, independent code sample instead. The authors ask a critical question: Is self-repair actually a better use of your "compute budget" than just sampling more programs i.i.d. (independent and identically distributed)?

Methods

The researchers formalize the self-repair process into a Repair Tree consisting of four stages:

  1. Code Generation: Generating $n_p$ initial samples.
  2. Execution: Running samples against unit tests to find failures.
  3. Feedback Generation: Using a model to explain why a program failed based on the error message.
  4. Code Repair: Using that explanation to generate a fixed version.

To ensure a fair fight, they compare self-repair against a baseline of pass@k, where $k$ is the total number of programs generated (initial + repairs). If a repair tree generates 20 total programs, it is compared against a baseline of 20 independent samples.

They tested three models: Code Llama-13b-instruct, GPT-3.5, and GPT-4. Crucially, they also performed "feedback boosting" experiments, where a stronger model (like GPT-4) provided the explanation for a weaker model (like Code Llama) to use during the repair phase.

Datasets

The study utilized two primary benchmarks for Python programming:

  • HumanEval: A standard set of 164 hand-written introductory programming problems.
  • APPS: A much more challenging dataset of 5,000+ problems drawn from coding competitions, categorized into Introductory, Interview, and Competition levels. The authors used a representative subset of 300 tasks.

Key Insights and Ideas

  • The Feedback Bottleneck: The biggest hurdle isn't the model's ability to write code, but its ability to critique it. LLMs are surprisingly bad at identifying the root cause of their own bugs. When the authors replaced model-generated feedback with human-written feedback, repair success rates skyrocketed.
  • Diversity Over Depth: The results suggest that if you have a limited budget, you are almost always better off generating a diverse set of initial attempts rather than trying to perform deep, multi-step repairs on a single faulty attempt.
  • The "Power Struggle": There is a correlation between a model's ability to generate a correct solution and its ability to repair one. On easy problems, the model doesn't need repair (it gets it right the first time). On hard problems, the model's feedback is often too poor to guide a successful repair. This leaves a very narrow "Goldilocks zone" where self-repair is actually useful.
  • Stronger Models as Mentors: Using GPT-4 to provide feedback to Code Llama resulted in much higher gains than Code Llama trying to debug itself. This suggests a "teacher-student" architecture might be more viable than true "self"-repair.

Key Results

  • Modest Gains: On the difficult APPS dataset, GPT-4's self-repair only outperformed the i.i.d. baseline by about 8%.
  • Diminishing Returns: For GPT-3.5 and Code Llama, self-repair often performed worse than simple sampling at lower compute budgets.
Mean pass rate vs number of programs sampled
  • Human Feedback is King: In a small-scale study, replacing GPT-4's self-explanations with human feedback increased the repair success rate from 33.3% to 52.6% (a 1.58x improvement).
  • Inaccuracy: GPT-4’s feedback was found to be "obviously inaccurate" in 40% of cases (32/80), whereas human feedback was inaccurate only 8.7% of the time.

Limitations and Future Work

  • Scope of Tasks: The study focused on self-contained Python puzzles with clear unit tests. In real-world software engineering, specifications are often ambiguous, and unit tests may not exist or may be incomplete.
  • Human Cost: While the paper accounts for the computational cost of repair, it doesn't account for the human time cost in the human-in-the-loop experiments.
  • Prompting & Fine-tuning: The authors used one-shot prompting. It is possible that models specifically fine-tuned on "explanation" or "debugging" datasets might overcome the feedback bottleneck identified here.
  • Future Direction: The authors suggest exploring how self-repair might help resolve ambiguities in natural language specifications rather than just fixing logical bugs.

Summary updated

BibTeX
@inproceedings{olausson2024is,
  author = {Theo X. Olausson and Jeevana Priya Inala and Chenglong Wang and Jianfeng Gao and Armando Solar-Lezama},
  title = {{Is Self-Repair a Silver Bullet for Code Generation?}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=y0GJXRungR},
}
Figure