Scaling Trajectories for Complex Tasks through Recursive Self-Rewrite

Zongxia Li, Yucheng Shi, Zhongzhi Li, Junyao Yang, Ruhan Wang, Chengsong Huang, Fuxiao Liu, Haitao Mi, Jordan Boyd-Graber, LeoweiLiangarXiv 2026

TL;DR

Recursive Self-Rewrite (RSR) is a framework that enables LLM agents to self-improve by discovering solutions to complex tasks using specialized "harnesses" and then rewriting those successes into clean, general-purpose training data. By distilling assisted successes into structured "runbooks" and re-executing them, the authors expanded a small set of 2,001 successes into over 11,000 high-quality trajectories, significantly boosting performance across multiple terminal-based benchmarks.

What Problem Does This Paper Address?

LLM agents often rely on a "harness"—the external code that manages their environment, provides tools, and handles errors. While specialized harnesses (like those that force a model to reflect on errors or manage explicit states) can help a model solve much harder tasks, they introduce a "distribution mismatch."

If you train a model directly on trajectories produced by a specialized harness, the model learns to rely on external interventions and workflow conventions that won't be there during standard deployment. The challenge is: How can we take the "assisted" successes of a model and turn them into "reusable" capabilities that the model can perform alone under a simple, general harness?

Methods

The RSR framework operates in three main stages:

  1. Multi-Harness Discovery: The researchers used a single base model (Qwen-3.8-27B) under three different harnesses—Terminus 2 (general interaction), StateM (state-guided execution), and RSRT (outcome-guided reflection)—to solve a diverse set of terminal tasks.
  2. Recursive Self-Rewrite: This is the core innovation. For every successful solution found, the model plays three roles to "clean" the experience:
  3. Planner: Extracts the core logic into a Runbook—a structured plan containing milestones, checks, and recovery strategies.
  4. Critic: Audits the runbook to ensure it doesn't "leak" the final answer or verifier internals, providing feedback for recursive revisions.
  5. Executor: Follows the finalized runbook to solve the task again in a fresh sandbox using only the general-purpose harness.
  6. Verification and Training: Only trajectories that pass the final task verifier and a "leak audit" are kept. These clean trajectories are then used for Supervised Fine-Tuning (SFT).
The RSR pipeline: Discovering successes, rewriting them via a Planner-Critic loop, and re-learning them in a fresh sandbox.

Datasets

The authors curated a pool of approximately 3,000 difficult terminal tasks spanning 50+ domains (e.g., biology, chemistry, software engineering, security).

  • SWR (Software Terminal-Bench): 2,500 new tasks.
  • RST: 420 tasks adapted from previous work for increased difficulty.
  • Evaluation Benchmarks: The model was tested on Terminal-Bench (v2, v3, v4), Terminal-Bench Hard (TBH), and a Long-Horizon Terminal-Bench (LHTB).

Key Insights and Ideas

  • Harness Complementarity: No single harness is a silver bullet. As shown in Figure 4, RSRT excels at scripting and automation, while StateM is superior for software development. Using a union of harnesses solved 34.3% more tasks than the strongest individual one.
  • Runbooks as Knowledge Distillation: The runbook acts as a bridge. It strips away the "noise" of the specialized harness (like specific prompts or controller messages) and preserves the "signal" (the underlying problem-solving strategy).
  • Data Augmentation through Re-execution: By sampling multiple runbooks and multiple executions per runbook, a single discovery can be scaled into many high-quality training examples.
  • Fresh Sandboxes Prevent Overfitting: Re-executing the plan in a fresh environment ensures the model isn't just "replaying" a sequence of commands but is actually learning to react to the environment's state.
Comparison of how different harnesses solve different subsets of tasks, highlighting the value of the union.

Key Results

The RSR-trained Qwen-3.8-27B model showed dramatic improvements over both the base model and "Direct SFT" (training on raw, un-rewritten trajectories):

  • Terminal-Bench 2: Pass@3 jumped from 57.0% to 74.2%.
  • Terminal-Bench Hard: Pass@3 increased from 39.0% to 63.0%.
  • Terminal-Bench 4: A notoriously difficult benchmark saw an increase from 1.5% to 9.1%.
  • Long-Horizon Tasks: On LHTB, the process reward (a measure of partial progress) rose from 0.21 to 0.29.

Crucially, Direct SFT actually hurt performance on some benchmarks (like TB2) because the model learned "dead-end" behaviors—looping through the same actions without progress—which the RSR process successfully filtered out.

Limitations and Future Work

  • Long-Horizon Completion: While partial progress improved on the Long-Horizon Terminal-Bench, the model still failed to fully complete any of the 46 tasks, suggesting that extremely long-range reasoning remains a major hurdle.
  • Model Scale: The study focused on a 27B parameter model. Exploring how this recursive rewriting scales to smaller "edge" models or larger frontier models is an open question.
  • Sandbox Complexity: The authors noted that more complex harnesses (like StateM) occasionally suffered from sandbox errors, which limited the number of successful rollouts available for rewriting. Improving the robustness of these discovery environments is a clear path forward.

Summary updated

BibTeX
@misc{li2026scaling,
  author = {Zongxia Li and Yucheng Shi and Zhongzhi Li and Junyao Yang and Ruhan Wang and Chengsong Huang and Fuxiao Liu and Haitao Mi and Jordan Boyd-Graber and LeoweiLiang},
  title = {{Scaling Trajectories for Complex Tasks through Recursive Self-Rewrite}},
  year = {2026},
  eprint = {2610.02826},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2610.02826},
}
Figure