Auditing Reward Labels to Improve Code Agent Training
Hidden tests often act as the reward labels that train code agents, so systematic false negatives and false positives can steer optimization in the wrong direction. This article explains why those tests function as rewards, how assertion-level audits and container reproduction expose bad labels, and what engineering practices make the remaining signal more trustworthy.
New code-agent capabilities are often discussed first in terms of model scale, iterative structural expansion, or inference-path design. From an engineering perspective, however, training quality depends on more than making a model larger or deeper. It also depends on whether the reward signal in the training loop is trustworthy. For a code agent, hidden tests are the reward labels: a patch that passes receives a reward, and a patch that fails receives zero. If those tests systematically misjudge results, the model keeps optimizing against the wrong signal, and gains from scaling can be offset by noise. This article starts from reward-label auditing and discusses the main risks, audit methods, and engineering path for training code agents.
1. Why hidden tests are reward labels
A common way to train a code agent is to package an issue, a repository snapshot, and the tests attached to a merge request into a task. The agent can see the problem description and code context, but not the tests used for scoring. After it generates a patch, the hidden tests determine the reward: a pass produces positive feedback, while a failure produces zero reward. The tests are therefore no longer only an evaluation tool; they become the reward labels for the training policy.
The problem is that checks performed when a task enters the training set are usually loose. If the reference fix passes and the original code fails, the task is treated as usable. That only proves that a reward is reachable. It does not prove that every correct fix receives a reward, or that only a correct fix can receive one. Tests with overly strict assertions, dependence on implementation details, or unstable environments can reject correct patches. Tests with insufficient coverage can also accept incorrect patches. Once training data is scaled up, these errors are amplified.
2. Two critical errors: false negatives and false positives
The first type is a false negative: a correct fix is rejected by the tests. A test may call a private method that the issue never mentions, or require an exact upstream prompt string to be reproduced. A correct fix can take an equivalent but different implementation path and still be marked wrong. A test may also depend on a particular execution order, timestamp, file permission, or network state that looks reasonable outside a container but cannot be reproduced reliably inside one. False negatives give the model a negative reward for being correct, reduce the use of valid positive examples, and especially waste difficult tasks that appear never to have been solved.
The second type is a false positive: an incorrect fix is accepted by the tests. A patch may handle only the single case described in the issue while breaking an adjacent path that has no test coverage. It may also pass by hard-coding behavior, bypassing validation, or changing state that the tests can observe. False positives reward reward hacking and teach the model fragile or incorrect repair patterns. More subtly, a false-positive task can look successful during training and still fail in real development.
Existing reinforcement-learning practice often stabilizes training by discarding tasks that were never solved or sample groups whose reward variance is zero. These methods avoid the tests themselves. They can reduce noisy samples, but they cannot tell whether a task is genuinely too hard or whether the tests judged it incorrectly. Label errors have already been recorded on evaluation benchmarks. Training data is larger and checked more coarsely, so its impact deserves systematic auditing.
3. Assertion-level auditing and container reproduction
An effective audit cannot stop at whether the reference patch passes. It needs to inspect the intent of each assertion. A practical workflow can parse test cases and assertions; identify assertions that depend on private implementation details, prompt text, fixed paths, or nondeterministic environments; reproduce suspected bad tasks in an isolated container; cross-check them with multiple equivalent correct patches and multiple incorrect patches; label each task as trusted, suspected false negative, suspected false positive, or environmentally unstable; and finally repair the tests or remove the task while retaining audit records and data versions.
The following is a neutral pseudocode sketch of the audit:
def audit_task(task, candidate_diffs, original_code, reference_fix):results = []for diff in candidate_diffs:run = run_in_isolated_container(code=task.repo_snapshot,diff=diff,tests=task.hidden_tests,timeout=task.timeout)results.append({"diff": diff,"passed": run.passed,"logs": run.logs,"flaky": run.non_deterministic})original_passed = run_tests_in_container(original_code, task.hidden_tests).passedreference_passed = run_tests_in_container(reference_fix, task.hidden_tests).passedif not reference_passed:return "invalid_reference"if original_passed:return "reward_too_easy"if any(r["flaky"] for r in results):return "environment_unstable"if all(not r["passed"] for r in candidate_diffs if r["is_correct"]):return "suspected_false_negative"if any(r["passed"] for r in candidate_diffs if not r["is_correct"]):return "suspected_false_positive"return "trusted"
The point of auditing is not to achieve full automation in one step. It is to build a pipeline of automatic classification, human review, and container reproduction. Automatic rules find high-risk assertions, container runs confirm whether behavior can be reproduced stably, and human review decides whether the test intent is reasonable. Audit results should be written back into the data version so that the training set, evaluation set, and later iterations remain traceable.
4. Training gains after auditing
An audit of more than 2,000 software-engineering tasks found that more than half carried a false-negative risk. Among tasks that a medium-scale model never solved, about three quarters were cases in which the tests rejected a correct fix. After assertion-by-assertion auditing, training on the remaining 1,000-plus trusted tasks improved results on a public software-engineering evaluation set by about 2 to 3 percentage points at the same scale and difficulty. This shows that a model’s failure to solve a task is not always evidence that the task is hard; the tests may have judged a correct fix to be wrong.
The gains come from three sources. First, fewer incorrect negative rewards mean the model is no longer penalized for equivalent implementations. Second, difficult tasks are used more effectively because “never solved” is separated into “genuinely hard” and “incorrectly judged,” rather than discarded wholesale. Third, reward variance is reduced, so the training signal is closer to real repair quality. Simply discarding zero-variance sample groups throws away valuable tasks whose tests are wrong. That wastes data and preserves bias.
5. Engineering checklist
First, treat tests as a contract rather than as implementation details. Assertions should focus on observable behavior, inputs and outputs, and error handling, not private methods, internal logs, or specific prompt text. Second, validate tests with multiple reference fixes and mutated patches. Several correct implementations should pass, while incorrect patches should fail consistently. Third, reproduce the environment in containers, pin dependencies, filesystem, network, and time conditions, and record unstable tests. Fourth, build an audit pipeline that automatically classifies suspicious tasks and sends them for human review, with audit records bound to data versions. Fifth, audit before training filters are applied; do not simply discard tasks that were never solved. First determine whether the issue is difficulty or labeling. Sixth, monitor false-negative and false-positive rates and include test quality among data-asset metrics. Seventh, prevent test leakage and tampering. Hidden tests should not be modified by patches, and training and evaluation data should be isolated. Eighth, in the engineering implementation, a general container platform can run reproduction tasks in batches, a logging service can retain audit evidence, and object storage can manage data versions and audit results.
6. Conclusion
The technical focus of code agents is shifting from simply increasing model scale to improving reward-signal quality. When hidden tests serve as reward labels, false negatives or false positives can send training in the wrong direction. Assertion-level auditing, container reproduction, cross-validation with multiple patches, and data versioning can upgrade “a reward is reachable” into “the reward is judged correctly.” For developers and organizations, a high-quality task set and trustworthy tests are not accessories. They are core infrastructure for improving code-agent capability. Only when the reward signal is trustworthy can scaling and structural innovation become stable engineering capability.
