Source-linked AI summary
Neural Program Repair with Execution-based Backpropagation
He Ye, Matias Martinez, Martin Monperrus
TL;DR
Existing NMT-based program repair optimizes token similarity, which can produce non-compilable patches and penalize semantically equivalent alternatives. RewardRepair adds compilation and test-execution rewards to neural training, and it repairs 207 bugs across four benchmarks while improving compilable-patch rates over the state of the art.
Problem
NMT-based repair uses purely syntactic token-level loss, which does not reward compilability or semantically equivalent patches.
Method
RewardRepair uses discriminators based on compilation and test execution to convert patch quality into rewards that modulate cross-entropy during backpropagation.
Results
RewardRepair correctly repairs 207 bugs across four benchmarks and produces 45.3% compilable top-30 patches versus 39% for the state of the art.
Takeaways & Limitations
The results show that execution information can be embedded in backpropagation to improve neural program repair.
Takeaways & Limitations
The evaluation tests RewardRepair in Java, so generalization to arbitrary programming languages remains a threat to external validity.
Abstract
from arXiv · showhide
Neural machine translation (NMT) architectures have achieved promising results for automatic program repair. Yet, they have the limitation of generating low-quality patches (e.g., not compilable patches). This is because the existing works only optimize a purely syntactic loss function based on characters and tokens without incorporating program-specific information during neural network weight optimization. In this paper, we propose a novel program repair model called RewardRepair. The core novelty of RewardRepair is to improve NMT-based program repair with a loss function based on program compilation and test execution information, rewarding the network to produce patches that compile and that do not overfit. We conduct several experiments to evaluate RewardRepair showing that it is feasible and effective to use compilation and test execution results to optimize the underlying neural repair model. RewardRepair correctly repairs 207 bugs over four benchmarks. we report on repair success for 121 bugs that are fixed for the first time in the literature. Also, RewardRepair produces up to 45.3% of compilable patches, an improvement over the 39% by the state-of-the-art.
1 INTRODUCTION
RewardRepair addresses a mismatch in neural program repair: token-level cross-entropy does not directly reward compilable, correct, or semantically equivalent patches. It combines syntactic and execution-based learning and evaluates the approach across four benchmarks.
- NMT-based repair treats bug fixing as translating buggy token sequences into correct token sequences.
- Cross-entropy can favor non-compilable patches and penalize syntactically different but semantically equivalent patches.The loss requires strict matching between generated and human-written patches rather than rewarding compilation or semantic equivalence.
- RewardRepair combines token-level syntactic training with execution-based semantic training through a discriminator-derived reward signal.Compilation and test execution feedback modulates cross-entropy before neural-network weight updates.
- 207 bugs were repaired across Defects4J versions 1.2 and 2.0, Bugs.jar, and QuixBugs.The approach improved performance on Defects4J(v2.0) and Bugs.jar and achieved top-2 performance on Defects4J(v1.2) and QuixBugs.
- 45.3% of top-30 candidate patches were compilable, compared with 39% for the state-of-the-art.
2 BACKGROUND
Neural repair commonly uses NMT with token-based cross-entropy, but this objective can prefer textual similarity over compilation and semantic validity. A motivating example shows how a non-compilable patch receives a lower loss than a semantically equivalent patch.
- 2.1 Neural Program Repair: Neural program repair applies NMT encoder-decoder-attention models with cross-entropy loss to update network weights.The loss compares generated tokens with human-written patch tokens through strict pairwise matching.
- 2.2 Limitations of Current Neural Repair: Cross-entropy does not favor compiling patches over non-compilable patches and discourages exploration of equivalent solutions.The paper describes this tendency toward strictly identical translations as overcorrection.
- 2.3 Motivating Example: In the motivating example, the non-compilable patch has loss 0.1157, while the semantically equivalent patch has loss 0.4224.The non-compilable patch contains an undefined variable, whereas the alternative is semantically equivalent to the human-written patch.
- 2.3 Motivating Example: The example demonstrates that token-based cross-entropy can favor a non-compilable patch over a valid semantic alternative.
3 REWARDREPAIR
RewardRepair uses staged training to combine a supervised patch generator with execution-informed semantic optimization. It represents buggy and context code as token sequences and generates candidate patches for inference.
- 3. REWARDREPAIR: RewardRepair has three stages: syntactic training, semantic training, and inference.
- 3. REWARDREPAIR: Syntactic training initializes the model with cross-entropy, while semantic training uses four discriminators to modulate that loss.The discriminators assess patch differences, compilability, plausibility, and regression behavior.
- 3. REWARDREPAIR: After training, RewardRepair generates patches for new and unseen bugs using the trained patch generator.
- 3. REWARDREPAIR: The model represents buggy code and context code as separate token sequences, with context comprising surrounding lines and a buggy-class summary.
- 3. REWARDREPAIR: The encoder-decoder transforms buggy-code tokens B and context tokens C into a predicted patch F′ during both training phases.The lengths of buggy, context, ground-truth, and predicted sequences may differ.
3.4 Syntactic Training of RewardRepair
RewardRepair begins with supervised syntactic training that optimizes token-level cross-entropy on buggy-code and fixed-code pairs. Repeated training epochs optimize the patch generator’s network weights before semantic training.
- Syntactic training minimizes cross-entropy between the ground-truth fix patch F and predicted patch F′.
- The training corpus contains paired buggy code and fixed code used to train the syntactic objective.
- Multiple syntactic-training epochs can reach convergence and produce the best combination of network weights.At the end of this phase, the patch generator’s connection weights are optimized.
3.5 Semantic Training of RewardRepair
RewardRepair combines token-level cross-entropy with execution-based semantic training. Serial discriminators assess patch quality and use rewards to reweight the loss during backpropagation.
- Semantic training: RewardRepair combines cross-entropy with compilation and execution information through a mixed learning objective.The semantic objective adds program-specific knowledge beyond token-level syntactic loss.
- Discriminators: Four serial discriminators assess whether patches differ from the buggy code, compile, pass human-written tests, and avoid regressions.Each discriminator performs binary classification, passing affirmative patches to the next criterion.
- Discriminators: The difference discriminator penalizes no-change patches that are identical to the buggy input.It compares buggy and generated code as token sequences and assigns a negative reward when they match.
- Discriminators: The regression discriminator uses automatically generated tests to encourage patches whose behavior matches the ground-truth program beyond existing tests.This is intended to reduce patch overfitting and regressions.
- Rewarded loss: Reward values are ordered from no-change and non-compilable patches to compilable, plausible, and likely-correct patches.The scaling parameters satisfy R_no-change < R_non-compilable < R_compilable < R_plausible < R_l-correct.
- Rewarded loss: RewardRepair dynamically scales cross-entropy by (1 − R), with higher rewards producing smaller losses.Negative rewards increase the original loss for low-quality patches, while positive rewards reduce it for compilable, plausible, or likely-correct patches.
3.6 Inference
During inference, RewardRepair encodes a suspicious statement and its context, then generates the n best candidate patches using beam search.
- Inference: RewardRepair encodes the suspicious statement and surrounding context as token sequences for patch generation.The suspicious statement is identified by fault localization tools such as Ochiai.
- Inference: The configured inference beam size n determines how many top patches RewardRepair outputs for a suspicious statement.The model returns the n best patches produced by the generator.
3.7 Implementation
RewardRepair uses a Hugging Face Transformer patch generator with separate syntactic and semantic training stages and bounded token lengths.
- Model and training: RewardRepair implements its patch generator with a state-of-the-art Transformer architecture from Hugging Face.The model is trained for 15 syntactic epochs and 4 semantic epochs.
- Configuration: The implementation uses a vocabulary of 32 128 tokens, accepts up to 512 input tokens, and generates patches of up to 100 tokens.The learning rate is 1e−4 for both syntactic and semantic training.
4 EXPERIMENTAL METHODOLOGY
The evaluation compares RewardRepair with existing repair systems, measures compilability, and isolates semantic training across multiple benchmark datasets under single-file, single-hunk criteria.
- Research questions: The methodology defines three research questions covering comparative repair effectiveness, compilable-patch rate, and semantic-training impact.RQ1 compares with state-of-the-art tools, RQ2 measures compilability, and RQ3 uses ablation.
- Dataset criteria: Training and testing data contain bug-fix patches restricted to single files and single contiguous hunks with behavioral changes.Comment-only or logging-only changes are discarded.
- Dataset criteria: Semantic training requires compilable patched programs, executable tests, and automatically generated tests, criteria met by 123 single-hunk Bears bugs.The criteria are explicitly described as very strong, and several other datasets do not meet them.
- Testing benchmarks: Testing uses Defects4J versions 1.2 and 2.0, Bugs.jar, and QuixBugs after filtering for single-hunk bugs.The filtered set includes 120 Defects4J(v1.2) bugs and 257 additional Defects4J(v2.0) bugs.
- Evaluation protocol: RQ1 compares RewardRepair with CURE, Recoder, CoCoNuT, and other approaches using spectrum-based and perfect fault localization.Results are compared using established literature values for related approaches.
- Evaluation metrics: The evaluation counts correctly repaired bugs and uniquely repaired bugs as its two traditional APR performance metrics.Correctness requires either an identical developer patch or agreement from at least two authors after manual analysis.
- Evaluation protocol: RQ2 compares compilable rates at beam sizes 30, 100, and 200 against reported results from SequenceR, CoCoNuT, and CURE.Larger beams are excluded because of available GPU limitations.
- Ablation study: RQ3 compares syntactic-only training with combined syntactic and semantic training, followed by manual analysis of uniquely repaired bugs.The ablation uses the same protocol as RQ1.
5 EXPERIMENTAL RESULTS
RewardRepair improves neural program repair by incorporating compilation and execution feedback into training, yielding more correct and compilable patches across four benchmarks. Its performance gains include 207 correct repairs, 121 unique repairs, and up to 45.3% compilable patches, while remaining sensitive to project and beam-size effects.
- RQ1: Comparative Study: RewardRepair outperforms all APR approaches on Defects4J(v2.0) and Bugs.jar, while achieving top-2 performance on Defects4J(v1.2) and QuixBugs.On Defects4J(v1.2), only Recoder performs better; on QuixBugs, CURE’s larger beam size may explain its advantage.
- RQ1: Comparative Study: 5, 34, 78 and 4 bugs are uniquely repaired on Defects4J(v1.2), Defects4J(v2.0), Bugs.jar and QuixBugs, respectively.The Defects4J(v1.2) unique repairs span Closure, Lang and Math, indicating that the result is not confined to one project domain.
- RQ1: Comparative Study: 45, 45, 97 and 20 bugs are correctly repaired on Defects4J(v1.2), Defects4J(v2.0), Bugs.jar and QuixBugs, respectively.These results total 207 correct repairs across the four benchmarks, including 121 bugs repaired for the first time in the APR literature.
- RQ2: Compilable Rate: 45.3% is RewardRepair’s highest compilable rate, exceeding CURE, CoCoNuT and SequenceR across all reported beam-size configurations.Compilable rates decrease as beam size increases, consistent with the ordering of candidates by decreasing probability.
- RQ2: Compilable Rate: Project-specific compilable rates vary substantially, reaching 0% in the worst case, and larger beam sizes reduce the rate across projects.Lang patches compile much more often than Time patches, making non-uniform compilability a limitation of neural program repair.
- RQ3: Semantic Training: Semantic training increases correct patches on every benchmark, including Defects4J(v1.2), where the count rises from 42 to 45.The improvement occurs despite semantic training using only 123 samples versus more than 3 million for syntactic training.
6 DISCUSSION
RewardRepair’s inference study finds larger beam sizes generate more correct patches, while its generalizability remains untested beyond Java.
- Larger beam sizes generate more correct patches, confirming an earlier study.The authors provide beam-size-500 results in an online appendix.
- RewardRepair’s performance has only been tested in Java on established benchmarks.The approach may apply to other languages and datasets, but that generalization remains a threat to external validity.
7 RELATED WORK
RewardRepair addresses the mismatch between token-level cross-entropy training and program-repair objectives by incorporating compilation and execution information during training. It differs from related approaches in both its training-time use of execution feedback and its emphasis on the training objective rather than code representation.
- RewardRepair targets the discrepancy between syntactic cross-entropy optimization and generating compilable, correct patches.Its key novelty is a discriminative model that captures compilation and execution knowledge during training.
- Unlike generate-and-validate and synthesis-based approaches, RewardRepair automatically incorporates execution information into neural repair training.Related synthesis methods commonly extract repair constraints through symbolic execution and human knowledge.
- RewardRepair addresses non-compilable patches during training, unlike a related inference-stage valid-identifier checker.The paper distinguishes its approach by operating at training time rather than filtering invalid tokens only during inference.
- Discriminator-based repair studies use discriminators for vulnerability repair or similarity to human-written patches.These works are related through discriminator use but pursue different repair objectives.
- Prior work improves cross-entropy with sentence-level translation evaluation to reduce overcorrection of synonymous words and phrases.This provides a precedent for combining token-level loss with higher-level evaluation.
- Other research uses execution semantics to guide synthesis, measure semantic redundancy, or enrich code representations.RewardRepair’s novelty lies in improving the training objective rather than the representation.
8 CONCLUSION
RewardRepair uses compilation and test execution outcomes to provide reward signals that modulate token-level cross-entropy during neural program-repair training. Experiments across established benchmarks show that execution information can be embedded in backpropagation to improve neural program repair.
- RewardRepair uses a discriminative model to convert generated-patch execution outcomes into reward signals.The reward modulates the purely syntactic cross-entropy loss during semantic training.
- Extensive evaluation on Defects4J, Bugs.jar, and QuixBugs shows execution information can improve neural program repair.The conclusion reports feasibility of embedding execution information in the backpropagation process.