TL;DR
While Large Language Models (LLMs) are excellent at fixing buggy code, they suffer from "over-editing"—unnecessarily rewriting large portions of perfectly fine code. This paper introduces PRepair, a framework that uses an edit-aware reinforcement learning objective to train LLMs to make minimal, precise fixes. PRepair improves repair precision by up to 31.4% and accelerates inference speed by up to 15% when paired with speculative decoding.
What Problem Does This Paper Address?
When you ask a standard LLM to fix a bug, it often regenerates the entire function or rewrites large blocks of correct logic just to change a single operator. This phenomenon is known as over-editing.
Over-editing introduces two major issues in real-world software engineering:
- High Review Burden: Developers inspecting code changes via tools like
git diffhave to wade through dozens of lines of redundant changes to verify a simple fix. - Poor Bug Localization: The model fails to understand where the bug actually is, relying instead on brute-force rewriting to "hit" a correct solution.
Traditional reinforcement learning (RL) approaches for code repair exacerbate this because they use binary rewards based solely on functional correctness (i.e., whether the code passes unit tests). As a model trains on correctness alone, its tendency to over-edit actually increases over time.
Methods
To achieve precise code repair, the authors propose PRepair, which consists of two main stages:
- Self-Breaking (Data Generation): Realistic datasets containing both substantial correct logic and localized bugs are scarce. PRepair solves this by prompting an LLM to inject subtle logical bugs into correct "golden" programs. To ensure a high-quality training set, they use a min-max sampling strategy that selects buggy variants with the highest diversity in terms of edit distance, preventing the model from over-concentrating on repetitive bug patterns.
- Self-Repairing via EA-GRPO: The core innovation is Edit-Aware Group Relative Policy Optimization (EA-GRPO). Building on the value-model-free GRPO framework, EA-GRPO introduces a dynamic edit penalty. Crucially, this penalty is only activated when the model's rollout group achieves a minimum accuracy threshold ($\alpha$). This prevents the model from sacrificing correctness for the sake of brevity. When activated, it penalizes solutions with high edit costs relative to the group mean.
The authors also introduce a new evaluation metric, $\text{fix}_p@k$, which jointly evaluates whether a repaired program passes all unit tests and whether its edit cost falls within an acceptable tolerance ratio ($p$) of the theoretical minimum edit distance.
Datasets
The framework was evaluated across two distinct programming languages:
- Python: Evaluated on HumanEval-Fix (164 tasks with human-injected bugs). The training set was generated from the LeetCodeDataset, yielding 10,242 pairs after self-breaking and filtering.
- Verilog: Evaluated on a newly constructed benchmark of 352 samples based on QiMeng-CodeV-R1, targeting hardware-specific logical errors (e.g., bitwidth mismatches, arithmetic errors). The training set consisted of 11,200 self-broken Verilog samples.
Key Insights and Ideas
- The Correctness-Edit Tradeoff Myth: Standard RL training curves show that as a model gets better at passing tests, its edit cost balloons. However, explicitly penalizing edits does not harm correctness. Instead, it forces the model to implicitly develop error-localization capabilities, leading to cleaner and more robust generalization.
- Synergy with Speculative Decoding: Because PRepair minimizes changes, the original buggy code can serve as a high-fidelity "draft" for speculative decoding (specifically Prompt Lookup Decoding). Since most lines remain unchanged, the draft token acceptance rate skyrockets, translating directly into faster inference.
Key Results
- Superior Precision: Under the strict $\text{fix}_1@1$ metric (requiring minimal edits), PRepair outperformed vanilla GRPO by 20.95% on Python and 31.41% on Verilog using Qwen2.5-Coder-7B.
- Better Cross-Domain Generalization: When a model trained on Python data was evaluated on Verilog code repair, EA-GRPO maintained stable correctness and high precision, whereas vanilla GRPO's performance collapsed due to extreme over-editing in unfamiliar domains.
- Inference Speedups: When combined with speculative editing, PRepair achieved up to a 15% increase in decoding throughput. In contrast, vanilla GRPO caused a 35% throughput degradation because its over-edited outputs constantly broke speculative draft continuity.
Limitations and Future Work
- Manual Hyperparameter Tuning: The optimal settings for the group accuracy threshold ($\alpha$) and the penalty coefficient ($\beta$) vary across datasets and currently require manual calibration. The authors plan to explore automatic tuning methods.
- Function-Level Scope: PRepair is currently restricted to function-level code repair. Real-world software bugs often span multiple files or require project-level context, which remains an open challenge for precise repair frameworks.
Summary updated