Organizations: University of Chinese Academy of Sciences · Zhongguancun Academy, Beijing, China · Institute of Automation, Chinese Academy of Sciences · IIIS, Tsinghua University
Many real-world tasks require LLM agents to interact with their environments over long execution horizons. Errors that occur early in execution may propagate through both the agent context and environment state, and their effects may be difficult to reverse through subsequent actions. Existing methods mainly seek to reduce such errors through plan refinement and safety checks but provide little support after errors occur. To enable recovery during long-horizon execution, we present AgentRewind, a runtime recovery framework that records aligned checkpoints of the agent context and controlled environment, allowing agents to return to an earlier state and resume execution with information from previous attempts. We also construct MettleBench, a benchmark for evaluating task completion and partial progress on long-horizon engineering assignments containing a series of related requirements. Experiments across tasks, multiple models, execution strategies, and agent harnesses show that AgentRewind improves task success rate and average checklist progress over the compared baselines.
Figures & tables
Figure 1: Overview of AgentRewind. (a) AgentRewind operates as a runtime layer between the agent and the controlled external environment. The context recorder and environment-state recorder create aligned checkpoints dt=(ct,st) . During rewind, the agent selects a target checkpoint, after which the rewind executor restores the corresponding context and environment state and injects rewind memory. (b) An illustrative recoverable execution. When the agent determines that the current trajectory can no longer make progress, it invokes rewind. The trajectory returns to dk , retains the prefix through that checkpoint, and continues with a new suffix.
Figure 2: Distribution of the 82 MettleBench tasks across source benchmarks. Percentages are rounded to one decimal place.
Model
SR (%) ↑
Avg. Checklist progress (%) ↑
Avg. Trace Length
GPT-5.4
62.2
81.4
50.5
GPT-5.4 mini
33.7
64.6
72.4
Qwen3.7-Max
73.2
84.8
126.3
Qwen3.5-27B
56.1
79.1
211.6
Kimi K2.5
28.0
61.3
312.4
DeepSeek-V4-Flash
37.8
63.6
337.2
Table 1: Continue baselines across seven base models on MettleBench.
Figure 3: Task success (top) and checklist progress (bottom) over trace length for GPT-5.4 and GPT-5.4 mini. Curves show averages over three runs and are extended horizontally at their final observed values after termination.
Figure 4: Success by Continue trace-length tertiles. Error bars show run ranges; brackets show AgentRewind’s gain over the strongest baseline.
Strategy
Success Rate (%) ↑
Avg. Criteria Passed (%) ↑
Continue
78.7
88.7
Restart with Experiences
70.8
79.2
AgentRewind
83.1
90.2
Table 2: Results on Terminal-Bench 2.0 tasks.
Figure 5: Execution paths of Continue, Restart with Experiences, and AgentRewind in the Astropy FITS case. Scores denote checklist prefix progress.
Configuration
Success Rate (%) ↑
Avg. Checklist Progress (%) ↑
mini-SWE-agent
Continue
62.2
81.4
AgentRewind
87.8 (+25.6)
94.3 (+12.9)
FnCallAgent
Continue
58.5
77.9
AgentRewind
81.7 (+23.2)
91.4 (+13.5)
Table 3: Continue and AgentRewind across three agent harnesses using GPT-5.4; parentheses show absolute improvements.
Method
Recovery Rate (%) ↑
Checklist Progress Change (pp) ↑
Continue
8.0
5.1
AgentRewind
30.0
12.2
Table 4: Recovery from 50 paired failed Continue endpoints. Progress change is measured relative to each shared endpoint.
Variant
Success Rate (%) ↑
Avg. Checklist Progress (%) ↑
Full AgentRewind
87.8
94.3
w/o Env. Rewind
43.9
63.5
w/o Context Rewind
65.9
77.9
w/o Rewind Memory
51.2
69.4
Table 5: Component ablation of AgentRewind.
Appendix figures & tables10 assets
Supplementary material from the paper’s appendix.
Appendix
Source benchmark
Criteria
Share (%)
Per task
Terminal-Bench 2.0
208
32.5
7.43
ProgramBench
168
26.2
7.64
SWE-Bench
158
24.7
8.78
ProjectEval
56
8.8
8.00
GitTaskBench
50
7.8
7.14
Total
640
100.0
7.80
Appendix
Table 6: Distribution of the acceptance criteria of MettleBench across the source benchmarks, counting every criterion of a task towards that task’s source. The last column is the mean number of criteria per task for that source. No source contributes disproportionately many criteria: every share is within three points of the corresponding share of tasks in Figure 2 of the main paper. Percentages are rounded to one decimal place.
Statistic
Value
Tasks with machine-readable checklist
82 / 82
Total criteria
640
Criteria per task: mean (sd)
7.80 (1.63)
Criteria per task: median
7
Criteria per task: range
5 – 12
Criteria with failure feedback
640 / 640
Appendix
Table 7: Acceptance-criteria statistics over the 82 tasks.
#
Category
Criterion (intent)
P01
correctness
The leak scanner enumerates every object in a repository, reports correct match statistics for the healthy reference repository, and its unit tests pass.
P02
data integrity
A baseline scan summary and per-object inventory of the reference repository exist with correct counts.
P03
data integrity
The handoff records the exact leaked credential values the responder needs to rotate.
P04
recovery
The teammates’ lost feature commits are reachable from refs again, with content and history intact.
P05
correctness
No leaked credential survives anywhere: not in reachable history, any patch, or any loose/dangling/packed object.
P06
data integrity
Ordinary (non-secret) project files and commit history remain intact after the rewrite.
Appendix
Table 8: Hidden ordered checklist of the worked example. The criteria are interdependent through the shared repository state and through ordinary git semantics: purging a credential from history (P05) ends in pruning unreachable objects, which physically discards the commits that P04 requires unless they have already been made reachable from a ref. Later criteria can likewise invalidate earlier ones.
Parameter
Value
Execution strategy
Continue
Agent harness
mini-SWE-agent
Base models
7 (see Table 1 of the main paper)
Temperature
0.0
exception: Kimi K2.5
0.6 (no-thinking mode)
Step limit per run
none
Appendix
Table 9: Configuration of the base-model comparison under Continue (Table 1 of the main paper).
Parameter
Value
Shared by all strategies
Base models
GPT-5.4, GPT-5.4 mini
Independent runs
3
Temperature
0.0
Step limit per run
none
Wall-clock limit per episode
none
Appendix
Table 10: Configuration of the execution-strategy comparison. The strategies share every setting in the upper block and differ only in the parameters listed under their own headings.
Parameter
Value
Shared by both arms
Base model
GPT-5.4
Agent harness
mini-SWE-agent
Temperature
0.0
Paired trials
50
Starting state
failed Continue endpoint
Appendix
Table 11: Configuration of the paired recovery comparison. Both arms resume from the same failed Continue endpoint and share every setting in the upper block; only the availability of rewind differs.
Parameter
Value
Shared by all variants
Base model
GPT-5.4
Agent harness
mini-SWE-agent
Temperature
0.0
Tasks
82
Submission-failure mode
continue
Appendix
Table 12: Configuration of the component ablation. Each variant changes exactly one setting relative to full AgentRewind; all other parameters are those of the upper block.
Execution strategy
Task success rate (%) ↑
Avg. checklist progress (%) ↑
GPT-5.4
Continue
62.2 ± 2.1
81.4 ± 1.0
Restart with Experiences
78.0 ± 2.4
88.8 ± 1.2
Safety Review
34.1 ± 1.2
54.4 ± 2.1
AgentRewind
87.8 ± 1.2
94.3 ± 0.5
GPT-5.4 mini
Appendix
Table 13: Exact performance of the compared execution strategies, reported as mean ± standard deviation over independent runs ( n=3 ; sample standard deviation).
Path class
Snapshot
At restore
Examples
tracked
yes
reverted
task files
excluded
no
left as is
.git contents, .env , secrets
volatile
no
deleted
caches, build directories
Appendix
Table 14: How the three path classes are treated. Only tracked paths take part in a restore, which is what makes the recovery boundary of the main paper precise.
Baseline
n=
W
pHolm
r
Task success , GPT-5.4
Continue
35
35.5
< 0.0001
0.89
Restart with Experiences
23
59.0
0.031
0.57
Safety Review
54
0.0
< 0.0001
1.00
Task success , GPT-5.4 mini
Continue
39
115.5
0.0009
0.70
Appendix
Table 15: Two-sided Wilcoxon signed-rank tests of AgentRewind against each baseline. The pairing unit is the task ( n=82 ); the runs of each task are aggregated before pairing, over the same runs for both arms of a comparison. n= is the number of non-zero paired differences entering the test, pHolm is Holm-corrected across the twelve tests, and r is the matched-pairs rank-biserial correlation. All twelve comparisons favor AgentRewind.
Large language model (LLM) agents increasingly tackle long-horizon tasks through multi-step environment interaction, yet a single erroneous action can alter subsequent states and observations, causing errors to compound over time. Existing methods either correct the context without repairing altered environment states or restore earlier states while discarding useful experience, making it difficult to both eliminate failure conditions and avoid repeating past mistakes. We argue that reliable recovery should instead be treated as a rollback-boundary control problem that jointly determines when to intervene, where to resume, and what information should survive recovery. Based on this view, we propose Rollback-Induced Reflection (RIR), a unified recovery framework that restores execution to a selected prior state while carrying forward reusable knowledge distilled from the abandoned trajectory to guide subsequent decisions. We further characterize recovery through a unified operator over rollback depth and retained memory, providing a general view of state restoration and knowledge retention. Experiments on three long-horizon benchmarks show that RIR consistently improves average task performance across multiple LLM backbones, with structured reflection memory preserving useful experience and selective rollback enabling efficient recovery.
Large language model agents increasingly operate in long-horizon environments where early mistakes can trigger cascading failures and trap agents in dead-end trajectories. Agents must therefore be able to proactively recover from such states and turn their exploratory experience into guidance for subsequent decisions. We introduce ReTRAIL, a framework that enables agents to rewind the environment to earlier states while preserving valid progress and carrying forward knowledge learned from abandoned exploration. The environment state moves backward while the agent's knowledge continues to move forward. ReTRAIL trains a shared policy with two complementary signals: State-Anchored GRPO compares alternative continuations from revisited states to improve execution, while a branch-advancement reward guides reflection through the progress of subsequent exploration. Experiments across four interactive benchmark MineSweeper, Sokoban, ALFWorld and ScienceWorld show that simply adding a rewind primitive provides limited benefit and can even degrade performance. In contrast, ReTRAIL enables agents to rewind from unproductive states and use insights from abandoned branches to guide subsequent exploration. These results demonstrate the value of coupling environment rewinding with experience reuse within an ongoing task for long-horizon task solving. The code is available at https://github.com/whi497/ReTRAIL.
Ziang Ye, Wentao Shi, Lei Chen +7
University of Science and Technology of China · Shanghai Innovation Institute · Meituan +4
Large language model (LLM) agents increasingly undertake long-horizon tasks that require sustained reasoning, tool use, and revision across many interdependent steps. However, existing agent harnesses maintain task execution, task state, and completion assessment within a growing context, making the state difficult to track and allowing incorrect self-assessments to propagate into later decisions. We reformulate long-horizon execution as a task-state management problem and propose LongHorizon-Harness, which maintains the task state explicitly outside execution and updates it only with facts independently verified from the environment. Its Manage-Execute-Audit(MEA) loop uses a manager to maintain the task state and determine the next subtask, a fresh-context executor to perform it, and a read-only auditor to verify the resulting environment state before the next round. A lightweight AgentAdapter supports interchangeable model and harness backends without modifying their native agent loops. LongHorizon-Harness improves Qwen3.7-Plus from 51.8% to 80.7% on WeaveBench, from 69.7% to 77.2% on Terminal-Bench2.1, and from 2.8% to 8.3% on OSWorld2.0. It also raises Claude Opus4.7 from 20.0% to 34.3% on an OSWorld2.0 subset, demonstrating consistent gains across models, harnesses, and interaction domains.