Synthetic Data for Coding Agents: How Reversing Bug Fixes Breaks the Training Data Bottleneck
This article examines why data scarcity, rather than model capability, is the primary bottleneck for coding agents, and why prompt-driven synthetic bug generation suffers from mode collapse. It introduces a reverse pipeline that applies real-world repair patches backward to generate grounded defect tasks, then details the six-step workflow, explicit diversity controls, evaluation metrics, and common pitfalls such as answer leakage, fake defects, and environment drift.
1. The Overlooked Bottleneck: Not Model Intelligence, but Task Scarcity
When discussing the capability boundaries of coding agents (AI programs that can autonomously read repositories, locate issues, modify code, and run tests), the industry tends to focus on model size, context length, and reasoning strategies. Yet what truly blocks engineering deployment is often a more mundane link: there are too few tasks available for training and evaluation, and those that exist are noisy and expensive.
On the surface, open source communities produce a massive number of issues every day, so the raw material seems endless. The problem is that real defects accumulate naturally at the pace of human development and cannot be produced on demand. Moreover, an executable task is not a single line of description text; it consists of at least three components:
- A repository snapshot that can be built and run, with complete dependencies;
- A deliberately broken or naturally occurring defect;
- A set of tests and validation logic that can determine whether the issue is “fixed.”
The cost of constructing and validating these three components is extremely high, which means data scale and data quality constantly squeeze each other. As a result, the industry has turned to a synthetic approach: letting large models write their own problems and create their own defects. The success or failure of this route depends almost entirely on one metric: diversity.
2. Why “Letting the Model Write Problems” Narrows Over Time
Existing synthetic approaches fall into two broad categories. One has the model directly rewrite a piece of source code to artificially inject a defect. The other has the model first implement a new feature, then use a regression introduced by a flawed implementation as the defect. Both can quickly inflate the quantity, but they share the same structural weakness: the defects are entirely prompt-driven, and the model generates freely based on “common patterns from memory” in an unconstrained state.
This leads to a typical mode collapse: the first few samples show some novelty, but as the sampling volume grows, defect types rapidly converge to a few high-frequency routines. The result is a beautiful quantity curve paired with a flat diagnostic difficulty curve. The model learns only a handful of templates, not the myriad failure modes found in real engineering.
The source material offers a persuasive observation: on a general-purpose model without specialized training, repeatedly sampling the same source code 200 times yields only about 61.74% unique patches after normalized deduplication. In other words, nearly 40% of the “new samples” are just old samples in a new shell. Such redundant data not only wastes compute but also amplifies evaluation bias: scores rise on leaderboards, then things break in production.
3. The Core Idea: Reversing “Fixes” into a “Defect Generator”
The key insight is that fixing defects happens every day in the real world, and a repair patch is itself a high-quality “reverse instruction manual.” A patch records the shortest path from “broken” back to “working”; applying it in reverse yields a credible degradation process.
Formally, let the original repository state be $S{good}$ and the human repair patch be $p$, so the fixed state is $S{fixed}=p(S_{good})$. Traditional synthesis samples a generation distribution $q(z)$ to produce defects directly. The reverse approach first collects the real patch distribution, then takes its inverse:
Forward (real world): S_buggy --patch--> S_fixedReverse (data synthesis): S_fixed --reverse--> S_buggy'Task triple: (repo@S_fixed, issue description, validation cases)
This yields three benefits: the defect distribution naturally aligns with the real distribution; defects are strongly coupled with repository context instead of floating fragments; and because the starting point is a runnable repository that passes tests, the environment build success rate is significantly higher than generating from scratch.
4. From Patch to Task: An Executable Pipeline
- Candidate collection: Filter “fix-type” changes from the commit history of public repositories, excluding pure refactoring, formatting, dependency upgrades, and documentation changes.
- Reversibility check: Keep only patches that can be cleanly reverse-applied without conflicts; a high conflict rate indicates severe context drift.
- Semantic annotation: Have the model generate an issue description based on the diff and related discussion, requiring it to “describe only the symptom and expectation, without revealing the fix,” to avoid answer leakage.
- Environment freezing: Lock dependency versions and build scripts, produce a reproducible repository snapshot, and containerize it for batch scheduling.
- Bidirectional validation: Confirm in the forward direction that all tests pass after the fix; confirm in the reverse direction that at least two independent tests turn red in the defect state, preventing “fake defects.”
- Difficulty stratification: Label tasks by dimensions such as number of changed files, cross-module call chains, and whether concurrency and boundary conditions are involved, for use in curriculum learning.
A schematic validation skeleton:
def build_task(repo, patch, tests):fixed = apply(repo, patch)assert run(tests, fixed).all_passed, "Fixed state failed; discard"buggy = reverse_apply(fixed, patch)result = run(tests, buggy)assert result.failed_count >= 2, "Defect not observable; discard"return Task(snapshot=buggy, spec=describe(patch, leak=False),oracle=tests, difficulty=score(patch))
5. Diversity Cannot Rely on Prayer: It Needs Explicit Constraints
Reversing the process solves “is it real,” but does not automatically solve “is it repetitive.” Engineering practice suggests layering three controls:
- Cluster deduplication: Compute similarity after normalizing patches, sample with quotas per semantic cluster, and down-weight clusters that exceed their quota;
- Coverage-driven sampling: Maintain a defect type matrix (null values, boundaries, concurrency, types, resource leaks, permission checks, etc.) and prioritize filling low-frequency cells;
- Difficulty and length constraints: Limit the proportion of single-point changes to prevent tasks from degenerating into “change one constant.”
The evaluation side must change too. In addition to pass rate, report the effective sample rate after deduplication, defect type entropy, and cross-repository generalization gaps. Looking only at pass rate is like measuring height with a contaminated ruler.
6. Implementation Advice and Common Pitfalls
For teams that want to build their own data loop, the pragmatic path is: first run the full pipeline on a small set of high-quality real patches, then gradually scale up sampling; treat environment build success rate and validation pass rate as primary monitoring metrics; and run mixing-ratio experiments with synthetic and real data. Synthetic data is generally better suited to filling long-tail types, while real data is used to calibrate the distribution.
Watch out for three types of pitfalls: first, answer leakage, where the description includes function names or the fix approach, causing the model to learn to “guess intent” rather than “read code”; second, fake defects, where tests and implementation are both broken, making the task unsolvable; third, environment drift, where unlocked dependencies cause large-scale failures when batch tasks are scheduled.
Reversing the repair process is essentially converting the accumulated experience of human engineers into a scalable supervision signal. When both the authenticity and diversity of data are constrained by engineering, improving the capability of coding agents is no longer a matter of piling up volume and hoping for luck, but a measurable and reproducible path.
