RePair: Automated Program Repair with Process-based Feedback

Yuze Zhao, Zhenya Huang, Yixiao Ma, Rui Li, Kai Zhang, Hao Jiang, Qi Liu, Linbo Zhu, Yu Su

Introduction: The Challenge of Automated Program Repair

Automated Program Repair (APR) aims to fix buggy code automatically, a task that remains notoriously difficult for artificial intelligence. While massive Large Language Models (LLMs) with over 100 billion parameters have shown promise, smaller models (under 20B) often struggle to fix complex bugs in a single generation step.

The fundamental issue identified by researchers is a mismatch between how models are trained and how humans actually work. Humans do not fix code in one go; we write a draft, check compiler errors, run test cases, and refine the code iteratively. Standard APR approaches treat repair as a "one-shot" generation task where the model must output a perfect solution immediately. This lack of process-based feedback prevents smaller models from learning the intermediate steps necessary to bridge the gap between a broken program and a working one.

The iterative nature of program repair, showing multiple submissions failing different constraints (Time Limit, Memory Limit) before reaching an accepted state.

Methods: The RePair Framework

To address this, the researchers introduced RePair, an actor-critic framework designed for iterative refinement. RePair transforms APR from a static generation task into a dynamic process guided by feedback.

The RePair framework architecture, featuring the CodeNet4Repair dataset, the learning process, and the process-based feedback loop with a virtual reward model.

The framework consists of three core components:

  1. The Repair Model (Actor): Based on the StarCoder (15.5B) architecture, this model is first fine-tuned on repair tasks (SFT) and then further optimized using Reinforcement Learning (PPO). Its role is to generate potential fixes for a given buggy program.
  2. The Reward Model (Critic): Interacting with real compilers and test environments is computationally expensive and slow during training. To solve this, the authors trained a "virtual tool" reward model. This model predicts program quality based on a predefined hierarchy of errors, allowing for high-throughput training.
  3. Process-based Feedback: During inference, the model generates a solution, the critic evaluates it, and if the "reward" improves, the model uses that new version as a starting point for the next step. This continues until the code is fixed or a step limit is reached.

Datasets: CodeNet4Repair

The authors developed a new benchmark called CodeNet4Repair, derived from the IBM CodeNet dataset. Unlike previous datasets that only show "before" and "after" snapshots, CodeNet4Repair captures the multi-step repair process—the actual sequence of attempts a human took to fix a problem. It includes problem descriptions, time/memory limits, and high-quality test cases for over 10,000 repair processes in Python.

Key Insights

  • Decomposing Complexity: The edit distance for a single-step fix is often too large for a small model to navigate successfully. By breaking repair into multiple steps, the model only needs to make small, manageable changes at each stage.
  • The Error Hierarchy: The researchers empirically defined a partial order for program states: AC (Accepted) > PE (Presentation Error) > WA (Wrong Answer) = TLE (Time Limit) = MLE (Memory Limit) > CE (Compile Error) > RE (Runtime Error). This provides a clear "direction" for the reinforcement learning agent to follow.
  • Virtual Tools for Training: Using a Reward Model to simulate compilers and test environments allows for much more efficient policy optimization compared to using external tools directly in the loop.

Key Results: Process Beats Scale

RePair demonstrates that a focus on iterative process can allow smaller models to rival much larger counterparts:

  • Performance: The 15B RePair model achieved a 44.34% pass@1 rate on CodeNet4Repair. This significantly outperformed much larger open-source models like LLaMA2-70B (7.59%) and nearly matched the performance of commercial giants like GPT-3.5 (46.39%) and Claude 2 (43.98%).
  • Ablation Studies: Removing iterative feedback caused performance to drop significantly, confirming that the model's success depends on its ability to see and react to its own progress.
  • Efficiency: Smaller models excel when trained via the implicit reward signals used in the RePair framework, even if they struggle to interpret raw, explicit text-based compiler error messages.

Limitations and Future Work

While RePair is highly effective, several areas for future growth remain:

  • Language and Domain Scope: The current evaluation is focused on Python within a competitive programming context. Future work is needed to see if these results generalize to other languages like C++ or Java and to complex real-world software engineering repositories.
  • Multi-turn Logic: While the model iterates, it does not yet have a long-term "memory" of all previous failed attempts in a single session. Incorporating such memory could help the model avoid repeating mistakes, mirroring human debugging behavior more closely.

Summary updated

BibTeX
@inproceedings{zhao2024repair,
  author = {Yuze Zhao and Zhenya Huang and Yixiao Ma and Rui Li and Kai Zhang and Hao Jiang and Qi Liu and Linbo Zhu and Yu Su},
  title = {{RePair: Automated Program Repair with Process-based Feedback}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.findings-acl.973},
}
Figure