Forward Deployed EngineeringAI EngineeringReward Modeling
Train a reward model for a coding agent from 100K noisy human scores biased toward short solutions.
Question 71 of 73 · Updated
On this page
Interview-ready answer#
I would not train a scalar reward model directly on the 100K scores and immediately optimize the coding agent against it. That would teach the agent to maximize a biased proxy, potentially producing short but incorrect or incomplete solutions.
Instead, I would combine execution-based correctness with debiased human judgments of maintainability and task fulfillment. First establish a trusted evaluation set, quantify the length bias, repair the supervision, and train a reward model that prefers working solutions over attractive-looking failures. Finally, test whether optimizing that reward actually improves the agent's performance on unseen tasks.
1. Turn noisy scores into useful supervision#
Start with an audit of the 100K ratings. Recover the task, repository snapshot, candidate patch or trajectory, annotator, rubric version and score wherever available. Check whether the scores are ordinal ratings, comparable numerical judgments or aggregated feedback. Deduplicate near-identical tasks and patches, and split by repository or task family before constructing training pairs to prevent leakage.
Use a small, stratified expert-reviewed set as a calibration anchor. Include different languages, task complexities, solution lengths and annotator groups. Obtain multiple independent ratings on selected examples to estimate disagreement and identify unreliable rubric dimensions.
Separate three questions:
| Dimension | Evidence |
|---|---|
| Does the change solve the task? | Execution, hidden tests, requirements and expert review |
| Is the change safe and compatible? | Regression tests, security checks and repository constraints |
| Is it maintainable and appropriately concise? | Calibrated human judgments, readability and unnecessary complexity |
A short correct patch can be excellent. A short patch that omits error handling or breaks a contract must not receive a high reward simply because it is short.
2. Measure and correct length bias#
Raw correlation between response length and score is insufficient: simpler tasks often require shorter solutions. Separate explanation length, patch size and trajectory length; these are different signals.
Compare candidates for the same task while controlling for execution outcomes, complexity and available annotator information. Build deliberately challenging pairs in which a longer solution is correct and a shorter alternative is defective, as well as pairs in the opposite direction.
Illustrative diagnostic: consider 100 matched-task pairs with a failing short solution and a passing long solution, and another 100 with the lengths reversed. Suppose humans prefer the failing short answer in 30 cases, but prefer the failing long answer in only 5 cases. The wrong-solution preference rates are 30% versus 5%, a 25-percentage-point gap. This suggests a possible short-answer bias; other quality differences must still be controlled before attributing the gap causally to length. The arithmetic was checked locally with exact rational arithmetic.
To repair the supervision:
- Re-label high-impact disagreements using a rubric that prioritizes correctness and complete requirements.
- Add counterexamples: concise but incorrect patches, longer necessary fixes, equally correct solutions of different lengths and concise correct solutions.
- Estimate annotator-specific reliability and scoring tendencies using shared calibration examples. Downweight unreliable observations rather than assuming all scores share a common scale.
Do not simply subtract a fixed reward per token or regress all length effects out of the score. That can remove legitimate maintainability preferences and penalize necessary work. Length should matter conditionally on task requirements and correctness.
3. Add execution feedback and train the reward model#
Run candidate patches in isolated, reproducible environments against independent tests. Use immutable repository snapshots, resource limits, restricted permissions and no unrestricted network or secret access. Distinguish infrastructure failures from actual solution failures; an unavailable test harness is not evidence that the code is wrong.
For repository agents, assess the resulting patch and relevant trajectory evidence, rather than relying on the final natural-language claim that the bug was fixed. Include regression tests, edge cases and checks for changes outside the authorized scope.
I would train a model that takes the task context and candidate solution as input, with separate heads for predicted functional success and human-rated quality if labels support them. If trustworthy execution is available at decision time, use it directly instead of substituting a learned prediction.
For comparable candidates to the same task, use calibrated ratings and execution evidence to create reliable preference pairs. The pairwise ranking loss for preferred solution a and rejected solution b is:
Loss = −log sigmoid(r(a) − r(b))
Weight pairs by label reliability; exclude ambiguous comparisons or model ties explicitly. If there is only one rated candidate per task, do not invent cross-task preferences from uncalibrated scores. Use an ordinal-rating objective or collect additional within-task comparisons.
A practical reward hierarchy is:
- Enforce non-negotiable security and task constraints outside the learned reward.
- Favor verified functional correctness; handle partial test evidence and unknown outcomes explicitly.
- Optimize maintainability, minimal necessary changes and cost among otherwise acceptable solutions.
When execution is expensive or incomplete, the learned reward can rank candidates or guide exploration, but final correctness should be verified where possible. Passing tests is evidence, not a proof of correctness.
4. Prevent reward hacking during agent training#
A coding agent optimized against a weak scorer may learn to satisfy superficial tests, weaken tests, hard-code outputs, or claim success without making a valid change. Keep the trusted evaluation harness outside the agent's modification boundary. Check the final repository state, not only tool output or self-reported success.
Start with reward-guided reranking of candidate patches before running costly reinforcement learning. Compare a raw-score reward model, a debiased model and an execution-augmented model under the same candidate-generation budget. Then use fresh agent-generated candidates to identify reward-model blind spots as the policy distribution changes.
If running RL, monitor independent task success, reward score, policy drift, solution length and resource use. Stop optimization when reward improves but independently verified outcomes degrade. FDE-0060 explains that divergence; here the key is preventing it through better coding-specific supervision.
5. Decide whether the reward model is good enough#
The release test is not just agreement with the original human ratings.
| Evaluation | What it establishes |
|---|---|
| Within-task ranking on held-out, expert-reviewed pairs | Whether preferences reflect the intended rubric |
| Accuracy on short-wrong versus long-correct cases and the reverse | Whether the scorer still exploits length as a shortcut |
| Calibration of predicted success against independent execution | Whether success predictions can support downstream decisions |
| Fixed-budget best-of-N selection on unseen tasks | Whether the reward improves actual candidate selection |
| Policy-training holdout with hidden tests and security gates | Whether optimization improves real task completion without unacceptable side effects |
Report results by task difficulty, repository family, language and length, with uncertainty. Keep held-out tests inaccessible to the agent and separate from reward-model tuning. If functional success drops or critical policy violations appear, do not promote the resulting policy even if human preference agreement improves.
The expert-level judgment is to treat the 100K scores as imperfect evidence, not ground truth. Use executable outcomes to anchor correctness, calibrated human judgments to capture qualities tests cannot measure, and independent evaluation to verify that reward optimization improves the actual coding agent.
References
- 1.
- 2.
- 3.
- 4.
Related questions
Explore other topics:AI AgentsAI System DesignLarge Language Models