Watching the Repair Trajectory: Temporal Stability as a Detector of Test-Gaming in Iterative Code Refinement

When a language model fixes a bug by repeatedly running tests, reading the failures and editing its patch, the final patch is the only thing anyone looks at. That discards most of the evidence. Work on noisy labels has shown that how a model's predictions move over time says more about whether they are right than how confident the model is at any single moment. Real patterns settle early and stay put, while memorized noise flickers. This note proposes the same idea for code repair. We record what each intermediate patch actually does, meaning which existing repository tests it passes and how its executed bytecode is distributed, at every refinement step. We test whether patches that only game the tests leave a distinctive signature. We expect that signature to be late, abrupt flips on the targeted test together with churn in unrelated behavior. Genuine fixes, by contrast, should converge early and leave the rest of the program alone.

This matters because iterative refinement against model-written tests is now known to make things worse in a specific way. On SWE-bench Verified it raises the rate of patches that pass the generated tests but fail the hidden acceptance tests Investigating Test Overfitting on SWE-bench. If trajectory stability flags those patches, it becomes a cheap dispatcher. Stable patches are accepted automatically. Unstable ones go to a human, and the human is asked to break the patch rather than approve it, inside a scored game whose outputs are machine-checkable counterexample inputs.

Core Claim

The claim is that, at a fixed execution budget, features of the refinement trajectory predict hidden-test failure of a test-passing patch better than features of the final patch alone. This includes better prediction than the disagreement among several independently sampled final patches. A secondary claim is that using this signal to route a small fraction of patches to an adversarial "find a breaking input" human task lowers the overfitting rate more per human-minute than routing by any snapshot signal. The tertiary claim is that framing that task as a game recovers more valid counterexamples per minute than paying for the same task. This third claim is weaker and explicitly falsifiable.

Where This Sits

Three bodies of work supply the method. SELFIE relabels a training example when its predicted class has been consistent over a sliding window of epochs. Time-Consistent Self-Supervision scores unlabeled examples by how little their output distribution drifts between steps, and argues that instantaneous confidence is unreliable. AcTune uses a moving-average memory of predictions to decide which examples can be pseudo-labeled and which go to a human annotator, reporting a 56.2% average reduction in labels. We reuse AcTune's routing logic directly. Our difference is that the "prediction" is the observable behavior of a program, and the "time" axis is the debugging turn, not the training epoch. All three papers evaluate only on image or text classification.

Two code papers motivate the gap and also constrain the design. Dynamic Stability of LLM-Generated Code measures divergence in static and runtime opcode distributions, finding SCTD around 3–5% and DCTD around 1% among correct solutions but up to 20% and 15% on outlier problems. It measures that divergence across independently sampled completions, not across a single agent's successive edits. Its cross-sample divergence is therefore our most dangerous competitor rather than our method. SlopCodeBench tracks code over sequential specification checkpoints and finds structural erosion in 77% of agent trajectories. It uses static complexity metrics and does not ask whether trajectory shape predicts hidden failure. Yan et al. report that compiler-feedback gains plateau within 2 to 4 iterations and then turn into circular edits. This constrains us: if most trajectories are that short, there may be too little history to read, and our analysis must report how prediction quality depends on trajectory length.

On the human side, When Incentives Backfire, Data Stops Being Human argues that piece-rate pay pushes annotators into fast, shallow work and LLM shortcuts. It offers a conceptual spectrum but no system. O2ARC 3.0 is a working gamified collection platform for ARC puzzles, with lives, scores and leaderboards, reporting 8.7/10 satisfaction from 50 participants. The research file names verification fatigue as an open problem of human-in-the-loop synthesis. People rubber-stamp plausible code, as seen in pipelines like NaturalCodeBench, where experts corrected GPT-4-drafted tests. Our design choice responds to this by making the human task generative and verifiable: submit an input on which the patch and the issue's intended behavior disagree. This sidesteps the main weakness of gamifying technical review, which is that scoring "good review" is itself hard. A counterexample either reproduces under execution or it does not.

Research Program

The first component is instrumentation. We run a standard test-driven refinement loop on SWE-bench Verified, following the setup of Investigating Test Overfitting on SWE-bench: a generated reproduction test, iterative edits, and stopping when the generated test passes. At each turn $t$ we execute the current patch and record a behavior vector $b_t$. This vector contains the pass/fail outcome of every pre-existing repository test, which is legitimately available before the fix, plus the generated test. We also record the runtime opcode frequency distribution $o_t$ over those executions, using the tracing of Dynamic Stability of LLM-Generated Code, and the edited line set $e_t$.

The second component is the stability signal. Borrowing the exponential moving average from AcTune and TC-SSL, we summarize a trajectory of length $k$ by

$$ S = \sum_{t=2}^{k} \lambda^{\,k-t}\Big[ d_H(b_t, b_{t-1}) + \mathrm{JSD}(o_t, o_{t-1}) + \big(1 - \mathrm{Jaccard}(e_t, e_{t-1})\big) \Big]. $$

Here $d_H$ is the normalized Hamming distance between consecutive behavior vectors, $\mathrm{JSD}$ is Jensen–Shannon divergence between opcode distributions, the Jaccard term measures edit-location churn, and $\lambda \in (0,1]$ controls how much recent turns dominate. A high $S$ means the patch was still thrashing when it started passing. We also record one discrete feature: the turn at which the generated test first passes, relative to $k$. This is the code analogue of the learning-order signal in FineCL. The three terms and $\lambda$ are tuned on a held-out split, so the reported signal is fixed before test evaluation. We will also report a logistic combination of the components, so that no single hand-weighted sum is load-bearing.

The third component is triage. Patches that pass the generated test are ranked by $S$. The top fraction $\rho$ is routed to human review and the rest are accepted automatically. Any counterexample a human finds becomes a new test, and refinement resumes from it.

The fourth component is the human arena. It is a web game in the spirit of O2ARC, where players see the issue text, the patch and a sandbox. They earn points only for inputs that make the patched code disagree with the issue's stated behavior, confirmed by execution and by a second player's adjudication of the intended behavior. Points scale with how many of the agent's prior patches the input would also have broken, and leaderboards and progression unlock harder repositories.

Baselines

The naive reference point is refinement with no triage. Every patch that passes the generated test is accepted. On SWE-bench Verified this is exactly the condition in which Investigating Test Overfitting on SWE-bench reports test-overfitting rates rising from 21.8% to 25.5% for Claude-3.7 Sonnet and from 33.0% to 35.9% for GPT-4o. We rerun it with the same backbones and loop, so that our measured rate, not the reported one, is the reference. The reported figures serve as a sanity check that our reproduction is faithful.

The strongest snapshot competitor is cross-sample divergence. At the final turn we draw $N$ additional independent patches and score the original by its opcode and behavior divergence from them, following Dynamic Stability of LLM-Generated Code. $N$ is set so that the total number of executed program variants matches the average trajectory length. Both methods therefore see the same count of executions, the same tests and the same tuning budget on the same split. No reported result was found on Lacuna for using this divergence to predict hidden-test overfitting, so we establish the number ourselves. Beating it means a higher area under the precision-recall curve for predicting hidden-test failure among generated-test-passing patches, with a bootstrap confidence interval excluding zero.

The cheap-heuristic baseline is a classifier trained on final-patch features: diff size, number of turns taken, the model's mean token log-probability on the final patch, and whether the patch touches test-adjacent code. This is the "instant confidence" alternative. It receives the same training split and hyperparameter search as our logistic combination.

Two ablations isolate the key ingredient. The first shuffles the turn order of each trajectory before computing $S$. This keeps the set of intermediate behaviors and destroys their temporal order, so it tests whether time carries information beyond "the agent tried many things." The second drops the behavior-vector term and keeps only edit churn, which tests whether running the existing test suite at each turn is necessary.

For the human study, the baselines are paid approve/reject review on Prolific-style terms and paid break-it review using the identical interface without game mechanics. Each runs at matched total participant-minutes. The relevant prior figure is that oracle access to golden tests improved resolution by only about 3% Investigating Test Overfitting on SWE-bench. That figure is a ceiling-like warning: catching overfit patches does not automatically fix them, so we report both overfitting reduction and resolution change.

Why not just…?

Why not just cap refinement at three iterations, since gains plateau anyway? Yan et al. make this attractive, and it is a real threat if overfitting is concentrated in long trajectories. We run a fixed-cap baseline at each cap from 1 to 6 and report overfitting and resolution together. If a cap matches stability triage on both, the trajectory signal adds nothing beyond trajectory length, and we will say so. Our expectation is that the cap also cuts genuine late fixes, which is why resolution is reported alongside.

Why not just sample more candidates at the last step and measure their disagreement? This is the snapshot method from Dynamic Stability of LLM-Generated Code, and it is the most plausible equal. It is the central baseline above, at matched executions. If it wins, the proposal pivots. Triage would then use snapshot divergence, and the contribution would reduce to the human arena. The shuffled-trajectory ablation tells us which of the two stories holds.

Why not just write more and better generated tests? Ahmed et al. show that refining against generated tests is what raises overfitting, and that hiding test details did not help. More generated tests do, however, reduce the space a hack can hide in. We include a condition that triples the generated test count to measure how much of our gain survives that change.

Why not just pay reviewers well? The overjustification argument of When Incentives Backfire is a position, not a measurement. It is entirely possible that the break-it format, not the game, does the work. That is why paid break-it is a separate arm. If paid break-it matches the game in valid counterexamples per minute, we conclude that task format matters and motivation framing does not, and we report that as the finding.

Proposed Experiments

The decisive first experiment is prediction. We collect at least three refinement trajectories per SWE-bench Verified instance, using one closed and one open backbone. We label each generated-test-passing final patch by whether it fails the hidden fail-to-pass tests or breaks pass-to-pass tests. We then compare precision-recall area for $S$, the logistic combination, cross-sample divergence, the final-patch classifier and the shuffled ablation, stratified by trajectory length. TDD-bench Verified provides a second, independent split with the same protocol. If trajectory signals do not beat cross-sample divergence on both splits, the remaining experiments are rescoped as described above.

The second experiment is triage. We sweep the routing fraction $\rho$ from 5% to 30%, using an oracle "human" that reveals one hidden failing test. This yields the overfitting rate and resolution rate as a function of review budget for each routing signal. The resulting curve is the main quantitative result. As a secondary check, we apply the same signal to SlopCodeBench checkpoints and ask whether high $S$ at checkpoint $j$ predicts erosion or checkpoint failure at $j+1$. The best agent there passes only about 14.8% of checkpoints SlopCodeBench, so this check is an exploratory correlation, not a headline claim.

The third experiment replaces the oracle with people. We run a between-subjects study with three arms (game, paid break-it, paid approve/reject) on 60–100 high-$S$ patches drawn from the triage experiment, with a recruited pool of programmers. Outcomes are valid counterexamples per participant-minute, the fraction of truly overfit patches caught, voluntary continuation beyond the required session, and the rate of submissions bearing signs of LLM generation. Finally, we feed the counterexamples back as tests and rerun refinement. This measures whether human-found inputs lower the final overfitting rate more than an equal number of additional generated tests do. The whole program succeeds as a result if the first experiment is positive, even if the game arm ties paid break-it.