Auditing the Filter: Stopping Self-Training Loops from Amplifying Their Own Test Bias

Code models are increasingly improved by training on their own work. The model writes candidate solutions and refines them against tests. The solutions that pass are kept and added to the next round of fine-tuning, and the cycle repeats. When the tests are written by a model rather than a human, this loop is a self-consuming system, meaning one that trains on outputs it has itself selected. The literature on such systems predicts that it will amplify whatever the filter gets wrong. Every flaw in the synthetic tests acts as a selection pressure, and every problem type the tests handle badly is pushed out of the training set a little more each round. This note proposes to measure that amplification in code, predict its rate from a simple selection identity, and remove it with a small, targeted fix.

The fix borrows an idea from fair online learning under partial feedback, the setting where a system only ever sees outcomes for the options it chose to accept. A self-training code loop never finds out whether the solutions its tests rejected were actually correct, so the tests' blind spots are never corrected. The proposal therefore spends a small budget each generation running an expensive, independent oracle (full hidden tests) on a random sample of both accepted and rejected candidates. That sample is used to estimate where the synthetic tests lie, and the next training set is reweighted to match. Stated in two sentences: self-training on test-filtered code is a curation loop that provably shifts the data toward whatever the filter rewards, including its errors and its preferred languages. Randomly auditing a few percent of the filter's decisions, rejections included, should be enough to keep the loop pointed at real correctness.

Core Claim

Treat each training generation $t$ as a distribution $p_t$ over candidate programs. Let $s \in \{0,1\}$ be acceptance by model-written tests and $g \in \{0,1\}$ be correctness on the hidden oracle tests. If the next generation reproduces the accepted set faithfully, then $p_{t+1} \propto p_t \cdot s$. Two exact consequences follow:

$$ \Delta \mathbb{E}[g] = \frac{\mathrm{Cov}_t(g, s)}{\mathbb{E}_t[s]}, \qquad \frac{p_{t+1}(L)}{p_t(L)} = \frac{\mathbb{E}_t[s \mid L]}{\mathbb{E}_t[s]}, $$

Here $L$ denotes a stratum such as programming language, difficulty tier, or solution complexity. The first identity says true correctness improves only as long as the synthetic tests stay positively correlated with the oracle under the current model's own outputs. Once the model learns to produce programs the tests accept but the oracle rejects, that covariance shrinks or turns negative, and the loop starts selecting for test-gaming. The second identity says any stratum with below-average acceptance shrinks geometrically. That is the code analogue of the collapse to a single class proven for curated image generation.

These identities come from reading Self-Consuming Generative Models with Curated Data Provably Optimize Human Preferences in code terms. That paper shows that retraining on curated self-outputs acts like reward optimization, driving variance to zero and collapsing CIFAR-10 to 100% airplanes within 10 iterations. It studies continuous image models with a fixed scorer. We apply the same logic to discrete programs whose scorer (the synthetic tests) is itself imperfect and model-generated.

The new part is twofold. First, we test these predictions quantitatively across multiple self-training generations in code, which no paper in our file does. Second, we propose audited curation: an unbiased, random-sample estimate of the synthetic tests' false-accept and false-reject rates, stratified by language and complexity, used to reweight each generation toward $p_t \cdot \hat{g}$ rather than $p_t \cdot s$.

Where This Sits

Three papers motivate the proposal by showing the effect within a single step or a single episode. Investigating Test Overfitting on SWE-bench runs an agent that refines patches against its own generated tests. It finds that refinement raises the rate of patches that pass surrogate tests but fail the real ones, from 21.8% to 25.5% for Claude-3.7 Sonnet and from 33.0% to 35.9% for GPT-4o, and that models almost always trust the surrogate test over the code. It stops at one episode and explicitly does not examine models trained on their own overfitted patches, which is exactly the loop we study. Verification Limits Code LLM Training shows that filtering synthetic training data with a strict 100% pass rate on synthetic tests throws away complex solutions, and that relaxing to about 70% helps. That is a one-shot filtering result, and our second identity predicts it compounds over generations. The Matthew Effect of AI Programming Assistants reports large gaps between mainstream and niche languages, for example DeepSeek-V3 pass@1 of 79.81% in Python against 24.31% in Erlang and 20.82% in Racket. It also finds that iterative prompting widens rather than closes the gap. It frames this as an ecosystem-level feedback loop, but it does not study the model-training loop that would turn lower acceptance rates into lower representation.

Two papers constrain the design. VeriScale shows that sparse tests let models game specifications: GPT-5.5's success on Lean 4 specification generation drops from 68.78% to 44.44% once the tests are expanded 83×. This argues that stricter tests alone are the obvious fix. Read together with Verification Limits, however, stricter tests also discard valid hard solutions. Our design sidesteps this tension because it does not change how strict the filter is. It measures the filter's errors instead. The partial-feedback result of Equal Opportunity in Online Classification with Partial Feedback, which proves an unavoidable regret cost for exploring while enforcing fairness when only accepted items reveal outcomes, supplies the method. The underlying lesson is that rejected items must sometimes be observed or the bias cannot be learned. Our audit of rejected candidates is the direct translation of that lesson into a program-synthesis setting. We do not claim their regret bounds carry over, because their setting assumes a stationary environment and ours has a policy that changes each generation.

Finally, SlopCodeBench shows that code quality erodes within multi-turn agent trajectories: structural erosion rises in 77% of trajectories and verbosity in 75.5%. It also shows that quality-focused prompting does not stop the decay. We use its erosion and verbosity metrics as an extra diversity and quality readout. Its mitigation result also tells us not to expect prompting to fix a problem driven by selection.

Research Program

The main testbed is a function-level self-training loop, where many generations are affordable and an oracle exists. We start from an open code model of roughly 7B parameters, the scale of the Command 7B setting in Verification Limits. We use a training pool drawn from the LeetCode multi-language benchmark described in the Matthew Effect paper, which has 3,011 problems in 9 languages across three difficulty tiers, split by problem into training and held-out sets. Each generation proceeds in four steps. The model writes its own tests for each training problem. It then generates and refines candidate solutions against those tests for up to four rounds, since Yan et al. report that gains plateau after two to four. Accepted solutions are then collected under the chosen curation rule. Finally, the model is fine-tuned on that set to produce generation $t+1$. We run six generations per condition.

The benchmark's own evaluation tests serve as the oracle $g$. They are hidden from the loop and queried only through the audit budget, which is fixed at 5% of candidates per generation and sampled uniformly from both accepted and rejected sets.

Audited curation uses the audit sample to fit a small calibration model. It predicts $g$ from the synthetic-test outcome pattern (which tests passed), the language, the difficulty tier, and a program-complexity feature. Each candidate in the full pool then receives an estimated correctness weight $\hat{g}$. Rejected-but-likely-correct programs re-enter training with that weight, and accepted-but-likely-gaming programs are down-weighted. Because audit samples are drawn at random, the calibration is unbiased within each stratum. This is the property that selection-based filtering lacks.

We also log $\mathrm{Cov}_t(g,s)$ and the per-language acceptance ratio every generation, so the identities above can be checked against the observed drift. The identities hold exactly only if fine-tuning reproduces the accepted set faithfully, so we report how closely real training follows them.

A secondary testbed checks transfer to repository-level repair. On SWE-bench Verified, using an Agentless-plus-generated-tests loop in the style of the test-overfitting paper, we run three generations of fine-tuning on accepted patches from SWE-bench-train tasks. We track the overfitting rate across generations, with gold tests as the audit oracle. This is costly and is framed as a check on direction rather than a full replication.

Baselines

The naive reference point is generation 0, the base model with no self-training, together with the naive loop that fine-tunes each generation on everything passing 100% of its own tests. The naive loop is the condition the identities predict will drift. It must show a widening gap between surrogate and oracle correctness for the premise to hold.

The strongest existing filtering method is the relaxed threshold from Verification Limits Code LLM Training: accept at roughly 70% synthetic pass rate, combined with its "structured" test suites. Its reported numbers are a +3 pass@1 gain from structured over minimal suites and a 3-point gain of verified over unverified data on HumanEval, BigCodeBench and LBPP-v2.1. No absolute pass@1 figure for the 70% condition was found on Lacuna. The number we must beat is therefore our own reproduction of that condition at generation 6. It is the strongest competitor because it already targets the complexity-filtering bias. We run it with the same model, problems, refinement rounds and fine-tuning budget, tuning the threshold over a small grid on a validation split, with the same grid size used for the audit's calibration model.

The anchoring baseline mixes 50% human-written reference solutions into every generation. This is the fix that stabilized class proportions in Self-Consuming Generative Models with Curated Data Provably Optimize Human Preferences. It uses reference solutions from the same training problems, matched in count to the synthetic set.

The oracle-labels baseline trains directly on the 5% audited samples that pass the oracle, alone or added to the naive set. It spends exactly the same oracle budget as our method.

The fresh-adversarial-tests baseline regenerates tests each generation with mutation-based expansion in the spirit of VeriScale, with test-generation compute matched to the audit's oracle calls.

Two ablations isolate the key ingredient. The first audits only accepted candidates, which tests whether observing rejections is what matters. The second uses only stratum balancing, reweighting languages to equal share without any audit, which tests whether the gain is just rebalancing.

Beating these baselines means three things at generation 6. Held-out oracle pass@1 must be higher. The gap between surrogate and oracle pass rate must be no larger than at generation 0. Per-language share and pass@1 for Erlang and Racket must not decline. On these criteria, the audit must match or exceed anchoring and exceed the relaxed threshold and the oracle-labels baseline, with bootstrap confidence intervals over three seeds.

Why not just…?

Why not just relax the acceptance threshold to 70%? Verification Limits shows that relaxation helps in one filtering step, but it uses one global threshold, and the second identity says what drives extinction is the per-stratum acceptance ratio. A global threshold still accepts niche-language and hard-problem programs at a lower rate, so their share should still shrink, just more slowly. Relaxation also does nothing about false accepts from test gaming. The experiment settles this directly: if the relaxed threshold keeps Erlang and Racket shares flat across six generations, stratified auditing is unnecessary for the language-bias part of our claim.

Why not just anchor every generation with real human code? This is the most serious threat. It worked cleanly for CIFAR-10, and it may well stop the drift in our loop too. Our case against it rests on two points. It requires a supply of trusted human solutions in every stratum, and the Matthew Effect paper shows such data is scarcest precisely for niche languages. It also caps the benefit of self-training at the human data's own distribution. We will report anchoring honestly. If it matches the audit on all three criteria, the contribution narrows to cost: the audit needs oracle labels on 5% of candidates rather than human solutions for 50% of the training set. We would then emphasize the regime where human solutions are unavailable but tests can be run.

Why not just make the tests stronger, with more or adversarial tests? Verification Limits reports that going from two to four synthetic tests lowered average pass@1, because stricter filters discard hard, valid solutions. VeriScale shows the opposite danger with sparse tests. Stronger tests reduce false accepts at the price of more false rejects, and the naive loop never sees the false rejects. The fresh-adversarial-tests baseline measures which side of this trade dominates across generations.

Why not just spend the oracle budget on clean training labels? This is a fair question, since the audit uses the same oracle calls. The difference is volume: 5% of candidates is a small training set, while calibrated reweighting spreads the same information over the whole pool. The oracle-labels baseline tests this. If training on audited-correct samples alone does as well, the reweighting machinery is not earning its keep.

Why not just add a separate critic agent? In the SWE-bench overfitting study, an explicit critic that read logs and coverage still raised overfitting by 3.7 and 2.9 points. Perry et al. in Do Users Write More Insecure Code with AI Assistants? found that feeding model output back to the model amplified security errors. A model critic is another correlated filter, not an independent observation, so we do not include it as a main baseline.

Decisive Checks

The first check is whether the naive loop drifts at all. If, over six generations, the surrogate–oracle gap does not widen and niche-language share does not fall, the amplification premise fails for code. That would be a publishable negative result that bounds how far the image-domain theory carries over.

The second check is quantitative. The observed per-generation change in oracle pass rate should track $\mathrm{Cov}_t(g,s)/\mathbb{E}_t[s]$, and the observed change in language share should track the per-language acceptance ratio. We report the correlation and slope between predicted and observed values across generations and conditions.

The third check is the ablation contrast. Auditing accepted and rejected candidates should beat auditing accepted ones only, especially on hard problems and niche languages, where false rejects concentrate. If the two perform the same, the partial-feedback framing is wrong, and the gain comes only from catching gamed accepts.

The SWE-bench Verified transfer should show the overfitting rate rising across generations under the naive loop from the single-episode levels reported for Claude-3.7 and GPT-4o, and staying flat under auditing. SlopCodeBench erosion and verbosity metrics, computed on sampled programs from each generation, test whether diversity collapse also appears as the structural monoculture that paper describes.