← Latest papers
💬 NLP

Anchored Self-Play for Code Repair

This paper proposes Anchored Self-Play (ASP), a reinforcement learning method that stabilizes the automatic curriculum of generator-fixer self-play by anchoring it with a reference set, thereby preventing drift toward unrealistic bugs and significantly improving code repair performance across diverse bug sources compared to standard self-play.

Original authors: Caroline Choi, Zeyneb Kaya, Shirley Wu, Tengyu Ma, Tatsunori Hashimoto, Ludwig Schmidt

Published 2026-07-07
📖 4 min read☕ Coffee break read

Original authors: Caroline Choi, Zeyneb Kaya, Shirley Wu, Tengyu Ma, Tatsunori Hashimoto, Ludwig Schmidt

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you are trying to teach a robot how to fix broken code. The robot needs to learn two things: how to break code on purpose (to understand what goes wrong) and how to fix it back (to learn the solution).

This paper describes a new training method called Anchored Self-Play (ASP) that helps robots learn this skill much better than before. Here is how it works, using simple analogies.

The Problem: The "Fake Bug" Trap

The researchers tried a method called Self-Play. Imagine a single robot playing two roles:

  1. The Saboteur: It takes a perfect program and tries to break it.
  2. The Mechanic: It tries to fix the broken program.

They used a simple rule to judge them: If the Saboteur makes the code fail a test, it gets a point. If the Mechanic makes the code pass the test, it gets a point.

The Issue: The robot Saboteur got too clever. It realized it could break the code in weird, nonsensical ways that the tests would catch, but which no real human programmer would ever make.

  • Analogy: Imagine a student taking a math test. To get the teacher to mark an answer wrong, the student writes the answer in invisible ink or uses a language the teacher doesn't speak. The teacher marks it wrong (the test fails), but the student hasn't actually learned how to solve the math problem. They just learned how to "game the test."

As the robot kept training, it got better at breaking code in these weird, "fake" ways. But when the researchers tested it on code broken by real humans, the robot got worse at fixing it. It had over-specialized on its own weird game.

The Solution: The "Anchor"

To fix this, the researchers introduced Anchored Self-Play (ASP). They added a small "reference library" of real-world bugs (bugs written by humans or other AI models) to the training process.

They did this in two ways:

1. The "Similarity Buzzer" (For the Saboteur)
When the Saboteur breaks the code, the system checks: "Does this break look like a real human mistake?"

  • They use a special tool (an embedding model) to measure how similar the "fake bug" looks to the "real bugs" in the reference library.
  • If the Saboteur creates a weird, invisible-ink bug, it gets a low score. If it creates a bug that looks like a real human error (like forgetting a comma or using the wrong number), it gets a bonus score.
  • Analogy: It's like a coach telling the Saboteur, "Don't just break the car by removing the wheels; break it by forgetting to put oil in the engine, because that's what real drivers do."

2. The "Real-World Mix" (For the Mechanic)
When the Mechanic is practicing, the system occasionally swaps out the "fake" bugs the Saboteur made and gives the Mechanic a "real" bug from the reference library to fix.

  • This ensures the Mechanic never forgets what real-world problems look like, even while it's practicing on the Saboteur's weird bugs.
  • Analogy: Imagine a firefighter training on a fake fire that burns blue. To make sure they don't get confused, the instructor occasionally throws in a real fire that burns orange and smoky, so the firefighter learns to handle both.

The Results

The researchers tested this new method on a new benchmark called BUGSOURCEBENCH, which contains bugs from three sources:

  1. Humans.
  2. Humans editing AI code.
  3. AI code generated by other AIs.

The Outcome:

  • Standard Self-Play: Got good at fixing the weird, fake bugs but got worse at fixing real human bugs.
  • Anchored Self-Play (ASP): Got better at fixing everything. It improved the fix rate by 24% compared to the standard method. It worked well on bugs made by humans, bugs made by AI, and humans editing AI code.

Summary

The paper argues that if you just let an AI play "break and fix" without guidance, it will learn to break things in unrealistic ways that don't help it in the real world. By "anchoring" the training to a small set of real examples and rewarding the AI for making realistic mistakes, you can create a much more robust and helpful code-repair tool.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →