arXiv:2610.18484cs.AIOct 2026

Manuscript Offprint

arXiv:2610.18484

ReTerm: Recovery Training for Self-Improving Terminal Agents

Wei Xie, Kaituo Feng, Shiming Fu, Yong Liu, Xiangyu Yue, Shuangjia Zheng

ABSTRACT

Terminal agents have shown strong abilities in complex coding tasks. However, they often struggle to recover from errors during long-running execution (e.g., command errors, faulty implementations), eventually leading to task failures. To this end, we present ReTerm, a self-improving terminal agent trained by learning how to recover from its own failed terminal tasks. To support its training, we construct a customized data pipeline and produce ReTerm-10K, a high-quality dataset that provides effective recovery demonstrations for SFT cold start. Furthermore, we propose ReTerm-GRPO, an online RL algorithm that forks from the agent's own failure states to generate multiple independent self-recovery attempts. By learning from whether these attempts successfully complete the task, the agent self-improves through its own recovery experience. Built on Qwen3.5-9B, our ReTerm-9B achieves 34.8% Pass@1 on Terminal-Bench 2.0, improving over the base model by 14.6 points. Further analysis shows that our method achieves consistently higher recovery rates across diverse error categories compared with standard GRPO training. All code, data and model are released at https://github.com/twothsnd/ReTerm.

1 INTRODUCTION

The ability to interact with terminal environments has become increasingly important for agents to tackle complex coding tasks (OpenAI, 2025; Anthropic, 2025). It allows large language models (LLMs) to work within runtime environments and make progress on the tasks through long-horizon interactions. Recent works have constructed large collections of executable tasks to strengthen this capability. These tasks support supervised fine-tuning (SFT) on generated trajectories (Yang et al., 2026a; Jain et al., 2025; Li et al., 2026; Shi et al., 2026) and reinforcement learning (RL) with feedback from task verifiers (Cao et al., 2025; Gandhi et al., 2026; Ivison et al., 2026; Shen et al., 2026). Such efforts have achieved substantial performance gains on challenging benchmarks such as Terminal-Bench 2.0 (Merrill et al., 2026), highlighting the effectiveness of these training approaches.

Despite these advances, terminal agents still encounter errors frequently during extended execution and struggle to recover (Merrill et al., 2026; Feng et al., 2026b). For instance, an agent may meet a command error, misdiagnose its root cause, and continue acting in the wrong direction. To address this, a contemporary work, TermiGen (Zhu et al., 2026), actively injects hand-crafted errors into trajectories to generate recovery samples for training. However, these artificially constructed errors may exhibit a distributional mismatch with agents' own naturally generated errors. Moreover, it relies solely on SFT, leaving the potential of RL to further enhance terminal agents' recovery capability unexplored.

To this end, we introduce ReTerm, a self-improving terminal agent trained to recover from failures produced during its own execution. We first construct ReTerm-10K, a recovery trajectory dataset generated by our dedicated data pipeline. Specifically, we use the base model to execute terminal

∗^{*}Corresponding author.

Figure

Figure 1: An inference example revealing the difference in recovery behavior between models trained by GRPO and our proposed ReTerm-GRPO. With ReTerm-GRPO, the model formulates a stronger recovery strategy.

tasks and collect failed trajectories together with the environment states they leave behind. Starting from these failure states, a stronger model is asked to perform recovery based on the inherited execution history. We then apply a series of quality filters to remove unsuccessful, malformed, non-compliant, or inefficient recovery trajectories, retaining only high-quality samples for SFT cold start. Unlike conventional trajectory synthesis that teaches an agent to solve tasks from a clean environment, ReTerm-10K explicitly teaches how to continue from a faulty environment state, identify what went wrong, and repair the remaining problems.

Furthermore, we propose ReTerm-GRPO, an online reinforcement learning algorithm that explicitly learns self-recovery from errors produced by the evolving policy. For each sampled failed rollout, ReTerm-GRPO preserves the resulting execution state and branches into multiple independent self-recovery attempts from the same failure state. Then, their verifier outcomes provide group-relative learning signals for optimizing recovery behaviors, turning self-generated failures into opportunities for self-improvement. To support recovery training when a single training batch yields too few failed rollouts, we introduce a recovery task queue to store recovery tasks across training steps. Newly constructed tasks are inserted at the front and sampled first, while the oldest tasks are removed when the queue exceeds its capacity. This design reduces the need for additional rollouts while keeping recovery training focused on failures generated by recent policies.

We conduct comprehensive experiments to assess the effectiveness of ReTerm. Built on Qwen3.5-9B (Qwen Team, 2026), our ReTerm-9B achieves 34.8% Pass@1 on Terminal-Bench 2.0 and 58.4% Pass@1 on SWE-bench Verified (Chowdhury et al., 2024), establishing strong results on challenging terminal and coding tasks. Beyond these core evaluations, ReTerm also shows strong generalization across diverse out-of-domain benchmarks, improving over the base model by 20.0 points on AIME 2025 and 11.0 points on SpreadsheetBench Verified (Ma et al., 2024). Moreover, the same improvement trend persists under different agent harnesses, suggesting that our training induces transferable capabilities across interaction setups. To better understand where these gains come from, we identify five representative error categories in terminal interaction trajectories. Across all categories, ReTerm consistently exhibits higher recovery rates than the model trained by standard GRPO (Guo et al., 2025). Our main contributions are summarized as follows:

• We introduce ReTerm, a self-improving terminal agent developed through our recovery-oriented post-training framework. To support its training, we build a specialized data pipeline and construct ReTerm-10K, a high-quality dataset which offers effective recovery samples.

• To further improve recovery capability through online learning, we propose ReTerm-GRPO, which learns directly from failure states generated by the evolving policy and enables self-recovery capability to co-evolve with task-solving capability.

• Extensive experiments demonstrate that ReTerm achieves strong performance on multiple tough terminal and coding benchmarks and generalizes across various out-of-domain tasks and agent harnesses.

Figure

Figure 2: Overview of our data curation pipeline. Starting from an executable task, we collect various failed attempts induced by the base model. Then, a stronger model is asked to recover from the resulting failure state based on the limited information. For the generated recovery continuations, we finally apply four-step quality filtering and construct a high-quality dataset.