TL;DR
This paper introduces "Anchored Self-Play" (ASP), a novel method to train AI models for code repair. ASP addresses the problem of AI-generated bugs becoming unrealistic by anchoring the training process to a small set of real-world bugs, leading to more robust and effective code repair across various bug sources.
What Problem Does This Paper Address?
Training AI models to fix buggy code (code repair) is crucial for improving software development workflows. However, creating large, high-quality datasets of real-world bugs is challenging. Researchers have explored using AI models themselves to generate bugs for training, creating an "automatic curriculum" where the AI learns to create increasingly difficult bugs as it improves at fixing them. This "generator-fixer self-play" relies on unit tests to verify correctness (i.e., the fix passes tests). The core problem is that unit tests only check if a program works, not if the bugs it generates are realistic or resemble those found in actual software. This can lead to AI models becoming overfit to synthetic bugs, performing poorly on real-world code. The paper aims to bridge this gap by evaluating and improving code repair performance across diverse bug sources, including human-written code, LM-generated code, and human edits of LM-generated code.
Methods
The paper proposes Anchored Self-Play (ASP), which builds upon generator-fixer self-play. In generator-fixer self-play, a single AI model acts as both a bug generator and a bug fixer, trained using reinforcement learning. The generator creates bugs, and the fixer attempts to repair them, with unit tests providing rewards.
ASP introduces two key anchoring mechanisms to combat "distribution drift" (where the generated bugs become unrealistic):
- Similarity-Guided Generator Shaping: A reward is added to the generator's objective that encourages it to produce bugs whose "edits" (differences from the correct code) are similar in embedding space to a small set of reference bugs. This nudges the generator towards more realistic bug patterns.
- Reference Mixing for Fixer Training: During training, a portion of the generated bugs presented to the fixer are replaced with bugs from the reference set. This ensures the fixer is consistently exposed to realistic bugs, even as the generator evolves.
The paper also introduces BugSourceBench, a new benchmark designed to isolate the effect of bug source on repair performance. It uses the same programming tasks and unit tests but varies the origin of the buggy code.
Datasets
- BigCodeBench: Used as the primary source for constructing programming tasks and reference solutions.
- BugSourceBench: A newly introduced benchmark for evaluating code repair generalization across different bug sources. It includes four variants:
- HUMAN: Bugs introduced by human annotators into human-written code.
- HUMAN-EDITED LM: Bugs from LM-generated code that have been subsequently edited by humans.
- LM ERRORS (Qwen-7B): Bugs generated by a weaker LM (Qwen2.5-Coder-7B-Instruct).
- LM ERRORS (GPT-OSS-20B): Bugs generated by a stronger LM (gpt-oss-20b).
Key Insights and Ideas
- Unit-test-only self-play leads to "distribution drift": AI models trained solely on unit-test feedback can generate bugs that are valid and difficult but not realistic, leading to degraded performance on real-world bugs.
- Realism matters for code repair generalization: Evaluating models only on synthetic bugs can be misleading. Performance gains on generated bugs do not necessarily translate to improvements on human-authored bugs.
- Anchoring self-play with reference bugs is effective: ASP's dual approach of guiding generation with similarity and exposing the fixer to real bugs stabilizes training and improves cross-source repair.
- Code repair is distinct from code generation: Models that excel at generating code from scratch may struggle with repairing existing buggy code, highlighting the need for specialized repair capabilities like fault localization.
Key Results
- ASP significantly outperforms standard self-play: ASP achieved an average fix rate improvement of +7.0 percentage points (absolute) / +24% (relative) over standard self-play on BugSourceBench.
- Gains across all bug sources: ASP showed improvements on both LM-generated bugs (e.g., +11 pp / +100% relative for Qwen-7B) and human-originated bugs (e.g., +3.4 pp / +7.1% relative for Human).
- Robustness to bug source: Standard self-play showed inconsistent gains, even degrading on human-authored bugs, while ASP maintained strong performance across all sources.
- Sample efficiency: ASP showed improvements even with small reference sets (as few as 50 bugs).
- Test-time fixer performance: ASP-trained fixers improved the performance of larger code-generation models when used as test-time fixers.
Limitations and Future Work
- Python function-level repair: The current work focuses on single Python functions. Future work could extend to multi-file repairs, dependency management, and build-system interactions.
- Frozen embedding model: The realism signal relies on a pre-trained, frozen code-embedding model. Future work could explore learned critics or human preference data for stronger realism signals.
- Limited realism signal: The current realism signal is based on code embeddings. More sophisticated approaches like learned bug-style critics or preference-based rewards could be explored.
- Future work directions: The authors suggest exploring stronger realism objectives, learned bug-style critics, preference-based rewards, or richer anchoring signals beyond code embeddings.
Summary updated