Online Environment Repair for Coding Agents
Organizations: Hunyuan Team, Tencent
Abstract
Programmatic verifiers provide scalable reward signals for training coding agents with reinforcement learning, yet subtle harness defects and incomplete unit tests allow policies to earn full credit without solving the intended task. Existing training-time defenses intervene either by penalizing suspicious outputs or by filtering flagged tasks and rollouts. However, output penalties leave the underlying verifier exploitable, driving policies to disguise shortcuts under reasoning monitors or zeroing out valid solutions under detector false positives, whereas task and rollout filtering discards or mutes the hardest problems where shortcuts emerge earliest. Pre-training verifier hardening repairs the environment directly, but misses vulnerability classes that surface only as the policy improves during reinforcement learning. In this paper, we propose online environment repair, which leaves triggering rollout rewards unchanged to remove hiding incentives and asynchronously patches exploited environments during training. Candidate repairs triggered by execution invariants or differential fuzzing are deployed only after passing three automated validation gates that block the exploit while preserving valid solutions, canceling detector false positives and enabling structural propagation across repositories without scaffold labels or reference solutions. Across 20 controlled GRPO experiments on heterogeneous software-engineering repositories, online environment repair reduces cumulative reward hacking from 36.9% to 0.06% and improves held-out Pass@8 from 21.7% to 46.7%, consistently outperforming reward-penalty, rollout-filtering, and static-hardening baselines while eliminating zero-shot exploitation on unseen loophole classes.
Figures & tables
| Locus | Condition (Detector) | Training Dynamics (Steps 1–160, 40,960 Rollouts) | Held-Out Unpatched SWE (120 Tasks 8 Rollouts) | ||||||
| Last-10 | Onset | Active Envs | Hack Rate | True Pass@1 | True Pass@8 | ||||
| — | SFT-Init (Step 0) | — | — | — | — | ||||
| — | None (Unmitigated) | Step 72 | ( ) | ||||||
| Locus 1 | KL-Reg ( ) | Step 83 | ( ) | ||||||
| Locus 1 | CoT-Penalty ( Qwen3-32B Full) | Step 67 | ( ) | ||||||
| Locus 1 | Code-Penalty ( Qwen3-32B Code) | Never | ( ) | ||||||
| Model | H1 | H2 | Total Hack | True Pass@1 |
|---|---|---|---|---|
| SFT-Init | ||||
| None | ||||
| KL-Reg | ||||
| CoT-Penalty | ||||
| Code-Penalty | ||||
| Exec-Penalty |
| Condition | Locus-3 / Reference Design | Train | Held-Out Unpatched SWE ( ) | Unseen H1 + H2 ( ) | |||
|---|---|---|---|---|---|---|---|
| Hack | Pass@1 | Pass@8 | Hack | Pass@1 | |||
| Offline-Harden (Static+Local) | Step-0 Qwen3-32B ( fixed, S7 / S8 ) | ||||||
| Offline-Prop (Static+Our Prop) | Step-0 Direct + Prop ( , S7 / S8 ) | ||||||
| Audit-LB ( Oracle) | Privileged Oracle Verifier Calls | ||||||
| OER-Local (Online+Local) | Direct Patches ( tasks, GPU-h) | ||||||
| OER-Prop (Online+Our Prop) | Direct + Prop ( tasks, GPU-h) | ||||||
Appendix figures & tables4 assets
Supplementary material from the paper’s appendix.
Appendix
| Family | Split (Tasks) | Vulnerability Surface & Evaluation Harness Structure |
|---|---|---|
| S1 (Full Mutable Harness) | Train (32) | Writable unit test suite, writable request/response data schemas, and exposed workspace test-case fixtures. |
| S2 (External Fixture Plugin) | Train (32) | Read-only unit tests, exposed structured replay fixtures, and a writable test-runner fixture plugin. |
| S3 (Editable Unit Tests) | Train (32) | No external data fixtures; expected I/O assertions are embedded directly in a writable unit test suite, allowing assertion edits or expected-failure decorators. |
| S4 (Regression Trace Store) | Train (32) | Read-only unit tests that load expected input–output pairs from an exposed regression-trace store in the workspace. |
| S5 (Mutable Output Matcher) | Train (32) | Read-only unit tests that delegate response verification to a writable output-matcher helper module. |
| S6 (Mutable Verification Hook) | Train (32) | Read-only unit tests that invoke a writable post-execution verification hook module. |
| S9 Condition (32 Tasks, 60 GRPO Steps) | Repair Mechanism | Benchmark Fix | RL Patches | Train | Last-10 Hack | Held-Out Pass@1 | Held-Out Pass@8 |
|---|---|---|---|---|---|---|---|
| S9-Lockdown (Primitives 1–6 Active at ) | Static Isolation Only | ( ) | |||||
| S9-OER ( D1 – D4 + Qwen3-32B ) | Sample-Literal Probe Only | ( ) | |||||
| S9-OER + D5 (Diff. Fuzz + Qwen3-32B ) | Zero-Oracle D5 + Test Synthesis | ( ) |
| Group | Condition | Train | Last-10 | SWE Hack | SWE Pass@1 | SWE Pass@8 | Unseen Hack | Unseen Pass@1 |
|---|---|---|---|---|---|---|---|---|
| Init | SFT-Init (Step 0) | — | — | |||||
| Base | None (Unmitigated) | |||||||
| Locus 1 | KL-Reg ( ) | |||||||
| Locus 1 | CoT-Penalty ( Qwen3-32B Full) | |||||||
| Locus 1 | Code-Penalty ( Qwen3-32B Code) | |||||||
| Locus 1 | Exec-Penalty (Same D1 – D4 ) |
Reward Hacking
Reward hacking studies how AI systems exploit imperfect objectives and how to detect, measure, and prevent behavior that scores well but misses intent.
See all 208 papers