LEGO-RL: Harness-Native Reinforcement Learning for Coding Agents
Organizations: Huawei Technologies Co., Ltd · The Chinese University of Hong Kong
Abstract
Reinforcement learning for coding agents increasingly relies on long-running agent harnesses to manage tool integration, repository contexts, and execution feedback. However, the native execution environments of these harnesses are inherently misaligned with policy-gradient training: environmental crashes and reward hacking corrupt outcome signals, while train-inference discrepancies decouple rollout behavior from policy updates. To address this, we present LEGO-RL, a framework that bridges native coding-agent harnesses with scalable policy-gradient optimization without modifying their internal control flow. LEGO-RL is built upon three pillars: (1) faithful optimization via in-process LLM proxying that captures raw generation streams for token-level alignment and robust trainer-side log-probability recomputation, even under harness-side compaction or re-serialization; (2) reliable execution via scalable sandbox orchestration featuring image caching and stage-wise defenses to mitigate reward hacking; and (3) observable training through an integrated plugin that automates validation and monitoring, paired with a Live UI for granular trajectory diagnostics. We evaluate LEGO-RL by training the sparse MoE model Qwen3.5-35B-A3B with GSPO across three native coding-agent harnesses. LEGO-RL improves Qwen3.5-35B-A3B across OpenHands SDK (64.0% to 70.4%), Claude Code (62.4% to 68.2%), and OpenCode (57.2% to 66.6%) on SWE-bench Verified, while maintaining a rollout-training probability correlation above 0.99.
Figures & tables
| Harness-native fidelity | Execution & reward | Observability | ||||||
| Framework | Black-box harness | Token-in/ Token-out | History alignment | R3 | Fully async | Sandbox execution | Reward-hack defense | Training observability |
| verl ( 2025 ) | – | – | – | |||||
| slime ( 2025 ) | – | |||||||
| MOLT ( 2026 ) | – | – | – | – | ||||
| SkyRL-Agent ( 2025 ) | – | – | ||||||
| AReaL ( 2025 ) | – | – | – | – | – | |||
| Coding agent | Model | SWE-bench Verified (%) |
|---|---|---|
| OpenHands SDK | Qwen3.5-35B-A3B ( Qwen Team, 2026a ) | |
| Qwen3.6-35B-A3B ( Qwen Team, 2026b ) | ||
| KAT-Coder-V2.5-Dev ( KwaiKAT Team, 2026 ) | ||
| Lego-RL -Qwen3.5-35B-A3B | ||
| Claude Code | Qwen3.5-35B-A3B ( Qwen Team, 2026a ) | |
| Qwen3.6-35B-A3B ( Qwen Team, 2026b ) |
| per trajectory ( ) | |||||
|---|---|---|---|---|---|
| Coding agent | Pearson | KL ( ) | p50 | p90 | p99 |
| OpenHands SDK | |||||
| Claude Code | |||||
| OpenCode | |||||
| Stage | Mean (s) | p50 | p90 | p99 | Mean-time fraction |
|---|---|---|---|---|---|
| Sandbox setup | |||||
| Agent setup | |||||
| Agent execution | |||||
| Verification | |||||
| Other | |||||
| Trial total |
| Median latency | Paired ratio | |||||
|---|---|---|---|---|---|---|
| Optimization | Stage | With | Without | Median | p10–p90 | |
| Lazy image pull | sandbox setup | s | s | — | ||
| Prebuilt task image | sandbox setup | s | s | – | ||
| Mounted agent runtime | agent setup | s | s | – | ||
| Packaged grading toolchain | verification | s | s | – | ||
Appendix figures & tables9 assets
Supplementary material from the paper’s appendix.
Appendix
| Failure Mode | Incidence | Defense |
|---|---|---|
| Agent-side: shortcut exploitation | ||
| Reads git history | – | Rebase history to a single commit during agent phase; restore before grading |
| Downloads reference fix | Per-phase egress firewall in privilege-separated sidecar | |
| Edits test files | – | Withhold tests until grading; revert test-path edits |
| Environment-side: reward detached from agent | ||
| Grader applies reference patch | Audit affected instances out of pool; flag live if degenerate reward propagates | |
| Routing replay configuration | Pearson | Mean | Expert overlap | Top-1 agreement |
|---|---|---|---|---|
| Disabled | — | — | ||
| Enabled, misaligned | ||||
| Enabled, aligned |
| Series | First five steps | Last five steps | |
|---|---|---|---|
| training reward | |||
| turns per trajectory | |||
| response length (tokens) | |||
| tokens per turn | — | ||
| policy entropy | |||
| KL term of the loss |
| Behavior | First | Last | |
| Reads back a file it edited | |||
| Runs the test suite | |||
| Files explored before 1st edit | |||
| Ends with an explicit finish | |||
| Reproduces failure before editing | |||
| Solves despite a failed command |
| Policy loss | GSPO |
|---|---|
| Clip range (sequence-level) | |
| Advantage estimator | GRPO |
| Loss aggregation | seq-mean-token-mean |
| KL reward penalty | none |
| KL loss coefficient | |
| Learning rate |
LLM Agent Training
Large language model agent training teaches models to plan, use tools, and learn from multi-step interaction with environments.
See all 586 papers