Manuscript Offprint

arXiv:2610.07898

FC-SWE: Failure-Conditioned RL for Long-Horizon Software Engineering Agents

Jia Liufu, Bin Hu, Linglin Jing, Terry Kong, Yuki Huang, Ashwath Aithal, Wenming Yang, Jun Yang

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Jia Liufu 1,2^{1,2}, Bin Hu 1^{1}, Linglin Jing 1^{1}, Terry Kong 1^{1}, Yuki Huang 1^{1}, Ashwath Aithal 1^{1}, Wenming Yang 2^{2} and Jun Yang 1^{1}

1^{1}NVIDIA, 2^{2}Tsinghua University

Abstract: Repository-level software engineering (SWE) is a challenging long-horizon setting: agents must reason over extended interactions, use tools across multiple turns, and adapt to observations from stateful environments. Recent work trains SWE agents with reinforcement learning methods such as Group Relative Policy Optimization (GRPO), which independently sample multiple trajectories per issue, test the resulting patches, and compare terminal rewards within a fixed group. However, this training setup does not reuse verifier feedback from failed patches as context for subsequent attempts, even though this feedback contains valuable diagnostic information about what went wrong. Training on recovery trajectories is challenging because the preceding outcome determines whether the next trajectory is generated, while the failed execution determines its conditioning context. We introduce FC-SWE, a failure-conditioned RL framework that incorporates recovery attempts into policy training. After a patch fails verification, FC-SWE restores the repository to its original task state and uses the failed patch and verifier feedback as context for a recovery trajectory. FC-SWE adapts GRPO to these chains of complete, multi-turn tool-use trajectories through two mechanisms. Trajectory-local rewards preserve each attempt's verifier outcome, preventing recovery success from rewarding an earlier failed patch. Active-set advantage estimation forms a comparison group from all initial and recovery trajectories actually executed for the same issue, so failed attempts remain in the group while unexecuted attempts are excluded. On all 500 SWE-bench Verified tasks under a verifier-assisted protocol, FC-SWE with Qwen3.5-4B and SWE-agent achieves 41.7% Resolved@1 and 52.8% Resolved@2, compared with 38.9% and 48.5% for GRPO. Although trained with at most two attempts per chain, FC-SWE reaches 70.7% Resolved@11 under an eleven-attempt test-time budget.

1. Introduction

Large language models (LLMs) can generate code from natural-language instructions. Coding agents extend this capability by using tools to inspect files, edit code, and run tests, with execution feedback informing subsequent actions (Yang et al., 2024; Wang et al., 2024). These capabilities support repository-level software engineering (SWE), where agents must resolve issues in existing codebases rather than generate standalone programs (Jimenez et al., 2023). Each action can change the repository or reveal information needed for the next decision (Yao et al., 2023; Yang et al., 2024). Solving such tasks therefore requires cycles of inspection, editing, execution, and revision across repeated interactions with the environment.

To improve software reasoning and agent behavior over these extended interactions, recent work has applied reinforcement learning (RL) to repository-level SWE (Wei et al., 2025; Golubev et al., 2025; Luo et al., 2025a). In execution-based pipelines, the sequence of model outputs, tool calls, and environment observations forms a complete trajectory that culminates in a candidate code patch. A test-suite verifier evaluates the patch, and its outcome is used as a terminal reward for policy optimization (Golubev et al., 2025; Luo et al., 2025a). Although effective, training only on independent attempts does not explicitly teach the policy to use the diagnostic information from a failed verification in a subsequent recovery attempt.

A failed verification, however, provides more than a negative outcome: failing tests, error messages, and tracebacks can reveal why the patch was rejected and provide concrete guidance for

Figure

ata_t: agent action / tool call oto_t: environment observation rkr_k: verifier reward for the complete attempt kk

Figure 1 | Comparison of trajectory execution in GRPO and FC-SWE. During training, our GRPO baseline samples independent attempts, whereas FC-SWE launches a recovery trajectory after failure, conditioned on the failed patch and verifier output. Each executed trajectory retains its own verifier reward.

recovery (Gehring et al., 2024). This creates an opportunity to use not only the failed trajectory's terminal outcome, but also its diagnostic evidence to guide subsequent attempts (Shinn et al., 2023; Gehring et al., 2024). Incorporating this recovery process into reinforcement learning, however, is not straightforward. A recovery trajectory is generated only after a preceding trajectory fails, and its context is constructed from the failed patch and verifier feedback. Preceding executions therefore determine both which recovery trajectories enter training and the contexts under which they are generated, requiring explicit decisions about how verifier rewards are assigned and which trajectories form the comparison groups for advantage estimation.

To address these challenges, we introduce FC-SWE, a failure-conditioned reinforcement learning framework that incorporates post-failure recovery into policy optimization for long-horizon SWE agents. As illustrated in Figure 1, after a submitted patch fails verification, FC-SWE restores the repository to its original task state, provides the policy with the failed patch and verifier feedback alongside the original issue, and generates a recovery trajectory. This process forms an outcome-dependent recovery chain: the initial trajectory is always generated, whereas each recovery trajectory exists only if the preceding trajectory fails.

FC-SWE adapts Group Relative Policy Optimization (GRPO) (Shao et al., 2024) to these recovery chains through two mechanisms. Trajectory-local reward assignment gives each trajectory the verifier outcome of its own patch, so a chain that fails and then recovers retains the rewards

[0, 1]; the later success does not change the earlier failure's label. Active-set advantage estimation pools the initial and recovery trajectories actually executed for the same issue and uses the same leave-one-out reward baseline as our GRPO implementation (Ahmadian et al., 2024). This grouping allows comparisons across attempts while excluding unexecuted recovery slots from chains that have already succeeded.

We evaluate on all 500 SWE-bench Verified tasks using SWE-agent. We compare the initial Qwen3.5-4B policy (Base) with two policies separately trained from it using GRPO and FC-SWE; all three use the same feedback-enabled evaluation controller and attempt budgets. Averaged over three decoding seeds, FC-SWE achieves 41.7% Resolved@1 and 52.8% Resolved@2, compared with 27.9% and 36.3% for Base, and 38.9% and 48.5% for GRPO (Table 1). At a matched two-attempt budget, feedback-conditioned recovery performs worse than independent resampling for Base and GRPO but better for FC-SWE; context ablations further show that verifier evidence improves recovery beyond patch-only conditioning (Section 4.4). Although trained with at most two attempts per chain, the same FC-SWE policy reaches 70.7% cumulative resolution with up to eleven verifier-guided attempts at test time, compared with 67.3% for GRPO (Section 4.5).

Our main contributions are:

• We introduce FC-SWE, a failure-conditioned RL framework for long-horizon SWE agents that extends policy training beyond failed verification by restoring the repository to its original task state and generating recovery trajectories conditioned on failed patches and verifier feedback.

  • To optimize these outcome-dependent recovery chains, we introduce two complementary mechanisms. Trajectory-local reward assignment preserves each trajectory's own verifier outcome, preventing a later recovery success from changing the reward assigned to an earlier failure. Active-set advantage estimation compares the initial and recovery trajectories actually executed for each task while excluding unexecuted recovery slots from group statistics.

  • On all 500 SWE-bench Verified tasks, FC-SWE improves over the GRPO baseline trained without recovery trajectories by 2.9 and 4.3 percentage points on Resolved@1 and Resolved@2, respectively. Controlled evaluations further show that FC-SWE benefits from verifier evidence and outperforms independent resampling under the same two-attempt budget. Despite training with at most two attempts per chain, FC-SWE remains ahead of GRPO when evaluated at test time with up to eleven verifier-guided attempts.

References (47)