Full text not available for this paper
Counterfactual Rollout Replay: Forkable Environments as Free Process Rewards for Software Engineering Agents
Summary (Overview)
- Novel credit assignment method: The paper introduces Counterfactual Rollout Replay (CRR), a training-time procedure that uses forkable executable environments to obtain step-level return contrasts for software engineering (SWE) agents, without requiring human process labels or learned process reward models.
- Key mechanism: CRR selects a small set of decision points from an on-policy trajectory, restores each state via snapshot/restore, samples an alternative action, and rolls the branch forward to compute the advantage as the difference between the realised and counterfactual terminal returns.
- Empirical gains: With a 14B policy (Qwen3-14B), CRR improves pass@1 on SWE-bench Verified (41.7%), SWE-bench Live (35.9%), and SWE-rebench (32.6%), outperforming vanilla GRPO by 5.3, 4.8, and 4.7 percentage points respectively.
- Equal-wall-clock advantage: On the same hardware, CRR achieves 41.7% versus 36.7% for extended outcome-only GRPO on SWE-bench Verified—a 5.0-point gain with fork overhead fully charged.
- Composability: CRR combines effectively with process-reward models (PRM) and trajectory-search methods (TSR), reaching 45.6% on Verified with the full stack.
Introduction and Theoretical Foundation
Background and Motivation
Software engineering agents solve repository-level issues through sequences of file inspection, code edits, shell commands, and tests. While PPO- and GRPO-style updates can improve task success, a trajectory-level advantage does not distinguish a useful localisation decision from a later edit that breaks the patch. This creates a credit-assignment bottleneck: the reward signal is sparse and terminal-only.
Key Insight
The paper exploits forkability—a property shared with games and simulators—which in the SWE setting provides access to a restorable repository and executable environment with auditable provenance. This allows alternative actions to be followed through the real task environment and evaluated by its verifier, without learning a transition model.
Theoretical Foundation
The research is grounded in the policy gradient framework. For expected return with an action-independent baseline , the policy-gradient identity is:
For GRPO, the centred outcome advantage is , where is the mean return of sibling trajectories from the same initial state.
Formal Problem Setup
The task is modelled as a finite-horizon Markov decision process . A sandbox is forkable at horizon if it supports a snapshot and restore such that executing any fixed sequence of actions from has the same trajectory distribution as executing it from .
Methodology
The CRR Advantage Estimator
Given an on-policy trajectory , a selector chooses decision indices . For each , CRR restores state , samples an alternative action , and completes an independently sampled on-policy continuation. The selected-step advantage is:
The hybrid advantage combines CRR at selected steps with outcome-only advantages elsewhere:
This is inserted into the clipped surrogate objective:
where .
Theoretical Properties
Proposition 1 (Fixed-index action-conditional contrast): For a fixed index and action-augmented history :
Proposition 2 (Variance decomposition): With , , and :
CRR has lower conditional variance than the outcome baseline in buckets satisfying:
Decision-Point Selector
The selector scores each step using entropy-weighted tool-type preference:
where approximates mean grammar-masked next-token entropy, and tool-type scores are: 0 for passive read/search, 0.25 for focused tests, 0.75 for shell commands, and 1.0 for file edits. The top- scores (default ) among steps with are selected.
Counterfactual Proposal
The proposal distribution excludes the realised action with temperature scaling:
with default .
Implementation Details
- Model: Qwen3-14B with rank-128 LoRA adapters
- Infrastructure: SkyRL-Agent for asynchronous dispatch, SWE-MiniSandbox for execution
- Hardware: One node with eight H100 80GB GPUs
- Training: 24,000 on-policy trajectories, 4,000 optimizer updates, learning rate
- Data: 3,638 deterministic instances (2,438 SWE-Gym + 1,200 SWE-rebench)
Empirical Validation / Results
Main Results (Table 2)
| Method | SWE-bench Verified | SWE-bench Live | SWE-rebench | Δ vs. GRPO |
|---|---|---|---|---|
| SWE-Agent (zero-shot) | 22.6 ± 1.4 | 18.9 ± 1.5 | 16.4 ± 1.6 | −13.8 |
| OpenHands (zero-shot) | 23.4 ± 1.4 | 19.7 ± 1.5 | 17.0 ± 1.6 | −13.0 |
| SWE-Gym SFT | 28.1 ± 1.2 | 24.0 ± 1.3 | 21.5 ± 1.4 | −8.3 |
| SWE-Fixer | 30.7 ± 1.1 | 25.8 ± 1.3 | 22.8 ± 1.4 | −5.7 |
| RLEF (outcome-only PPO) | 33.5 ± 1.0 | 28.6 ± 1.2 | 25.4 ± 1.3 | −2.9 |
| Murphy | 35.2 ± 0.9 | 30.0 ± 1.1 | 26.7 ± 1.2 | −1.2 |
| SkyRL-Agent (vanilla GRPO) | 36.4 ± 0.8 | 31.1 ± 1.1 | 27.9 ± 1.2 | 0.0 |
| SWE-Trace (rubric PRM) | 39.1 ± 0.7 | 33.7 ± 1.0 | 30.2 ± 1.1 | +2.7 |
| TSR + GRPO | 38.0 ± 0.8 | 32.5 ± 1.0 | 29.1 ± 1.1 | +1.6 |
| CRR (ours) | 41.7 ± 0.6 | 35.9 ± 0.9 | 32.6 ± 1.0 | +5.3 |
| CRR + TSR | 43.6 ± 0.5 | 37.6 ± 0.8 | 34.1 ± 0.9 | +7.2 |
| CRR + SWE-Trace | 44.9 ± 0.4 | 38.8 ± 0.8 | 35.4 ± 0.9 | +8.5 |
Resource Accounting (Table 1)
| Metric | GRPO | SWE-Trace | CRR |
|---|---|---|---|
| Device-time (H100-hours) | 188 | 233 | 321 |
| Node wall-clock (hours) | 23.5 | 29.1 | 40.1 |
| Verified pass@1 (%) | 36.4 ± 0.8 | 39.1 ± 0.7 | 41.7 ± 0.6 |
Equal-Wall-Clock Comparison
At 40.125 hours on identical hardware, CRR reaches 41.7% versus extended GRPO's 36.7%—a 5.0-point advantage. GRPO has then completed 37,824 trajectories and 6,304 updates, compared with CRR's 24,000 and 4,000.
Credit Assignment vs. Search-Select (Table 3)
| Method | Fork use | Pass@1 (%) |
|---|---|---|
| Vanilla GRPO | None | 33.3 ± 0.7 |
| Search-Select-GRPO | Sequence selection | 34.4 ± 0.8 |
| CRR | Credit assignment | 36.2 ± 0.6 |
Composition Results (Table 4)
| Configuration | none | TSR | PRM | TSR+PRM |
|---|---|---|---|---|
| Base GRPO | 36.4 | 38.0 | 39.1 | 40.0 |
| Base GRPO + CRR | 41.7 | 43.6 | 44.9 | 45.6 |
Sampling Evaluation (Table 5)
| Method | Greedy pass@1 | Sampled pass@1 | pass@8 | all-8 |
|---|---|---|---|---|
| Vanilla GRPO | 36.4 | 35.9 | 53.8 | 18.7 |
| SWE-Trace | 39.1 | 38.6 | 55.6 | 21.2 |
| CRR | 41.7 | 41.2 | 57.7 | 23.9 |
Key Ablation Findings
- Increasing from 0 to 1 gains 2.2 points; recovers 5.3 of the 5.6-point gain at
- The entropy-plus-tool-type selector outperforms either component alone
- Performance is stable for and degrades at higher temperatures
- The advantage disappears between replay-cost multipliers and
Theoretical and Practical Implications
Theoretical Contributions
- Executable contrast estimation: CRR provides an environment-grounded selected-step signal integrated into PPO/GRPO updates while retaining the realised trajectory, offering a principled alternative to learned process reward models.
- Scoped theoretical analysis: The estimator is unbiased for a proposal-dependent, action-conditional contrast at a fixed index; the variance decomposition provides a diagnostic condition rather than a universal guarantee, honestly characterising the method's scope.
- Mechanism distinction: The Search-Select control demonstrates that CRR's gains come from credit assignment (how actions are scored) rather than branch selection (which trajectories are trained on).
Practical Implications
- No additional supervision costs: CRR needs no human process labels, learned process reward model, or oracle hindsight annotation—the "free" in the title refers to supervision costs, not replay compute.
- Sample efficiency: CRR matches or exceeds full-budget GRPO pass-rate within 6,000 on-policy trajectories (vs. 24,000 for GRPO), a conservative fourfold reduction in counted trajectories.
- Composability with existing methods: CRR combines effectively with PRM and TSR, suggesting orthogonal mechanisms for improving SWE agent training.
Conclusion
Main Takeaways
CRR uses executable counterfactual continuations to score selected actions while retaining the realised training trajectory. It requires neither process labels nor a learned reward model but charges the additional replay compute. The experiments demonstrate improved pass@1 across three SWE benchmarks and an equal-wall-clock gain over vanilla GRPO on Verified.
Limitations
- Requires affordable, reliable forks and a trustworthy terminal verifier
- Expensive restoration can erase resource-efficiency advantages
- Deterministic transitions leave future policy-sampling variance intact
- The unbiasedness result concerns a fixed-index contrast; the implemented selector induces a weighted training objective without an established convergence guarantee
- Severe trajectory-length heterogeneity remains unresolved
- Averaging multiple counterfactuals does not generally remove systematic replay bias
Future Directions
Understanding replay noise, selector weighting, and heterogeneous trajectory costs remains an important direction. The practical value of CRR depends on affordable, reliable forkability in SWE environments.
Related papers
- SWE-at-Scale: Scalable Issue Synthesis from Historical Bug Fixes
SWE-at-Scale reverses real-world bug fixes to train bug-inducing models, generating SWE tasks that are more realistic, diverse, and challenging than existing synthetic baselines.
- AutoCompact: Learning When to Compact Context in Long-Horizon Coding Agents
AutoCompact trains coding agents to decide when and how to compact context, improving SWE-bench Verified pass rates by 9.2% over the base model.
- DuoDiscover: Scaling Autonomous Discovery Beyond the Evaluation Bottleneck
DuoDiscover co-discovers optimization targets and cheap proxy evaluators with fidelity testing, achieving up to 15x speedups and beating human experts across software and chip design.