Manuscript Offprint

arXiv:2610.05831

Selecting Long-Horizon Trajectories for Reliable and Efficient Terminal-Agent Training

Cuong Dang, Hoang Anh Just, Ruoxi Jia

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

ABSTRACT

Terminal agents are commonly trained by imitating long teacher trajectories, yet how much of each trajectory to supervise remains unexplored. We study the supervision horizon, the number of trajectory tokens retained for training, and show that it is a key design axis for reliability and cost. Reliability improves with longer horizons but saturates: on Terminal-Bench, a 12K-token horizon solves more tasks than 16K (29 ± 0.7 vs. 26 ± 0.8) while requiring 30% less training time. The horizon also shapes agent behavior: short horizons cause premature termination, intermediate horizons yield productive error recovery, and long horizons induce over-persistence. We analyze this saturation through a bias–complexity bound, in which longer supervision reduces temporal supervision bias but increases finite-sample estimation error from more heterogeneous late-stage histories. Guided by this analysis, we propose selective long-horizon refinement, which first trains on short prefixes and then refines only on continuations that are most likely under the warm-start model. It consistently outperforms full long-horizon training. At 16K, it raises successful attempts from 110 ± 2.7 to 126 ± 2.1 and tasks solved in at least six of eight attempts from 9 ± 0.7 to 14 ± 0.6; with half of the long-horizon data, it still reaches 122 ± 2.4 while cutting training time by 23%. The gains transfer across benchmarks, from 64 ± 2.6 to 73 ± 2.1 on Terminal-Bench v2.0 and from 137 ± 2.7 to 155 ± 2.2 on OpenThoughts-TBLite. For long-horizon supervision, selecting the right trajectories matters more than training on all of them.

1 INTRODUCTION

Terminal-based coding agents such as OpenAI Codex (OpenAI, 2025) and Anthropic Claude Code (Anthropic, 2026) are becoming a common interface for software development, operating directly over terminals and repositories to execute commands, modify code, and iteratively solve tasks. Recent works have therefore begun to study how to train smaller, capable terminal agents efficiently (Pi et al., 2026; Cheng et al., 2026; Gandhi et al., 2026; Wu et al., 2026).

A common way to train terminal agents is imitation learning from teacher-generated trajectories, where the student is supervised to reproduce the teacher's actions conditioned on the preceding interaction history. These long-horizon terminal trajectories involve extended sequences of interdependent decisions in which later actions depend on earlier observations, modifications, errors, and intermediate outcomes. As trajectories unfold, the agent may need to recover from failed commands, revise hypotheses, verify in-

Table 1: Training time and accuracy across supervision horizons.

Cutoff4K8K12K16K
Time (h) ↓10.1721.6535.4450.81
Accuracy (%) ↑24252926

intermediate results, or switch strategies based on accumulated interaction history. Training with a short horizon can therefore omit these later-stage behaviors and provide insufficient supervision for recovery, correction, verification, and strategy switching. In contrast, longer horizons expose the student to richer temporal dependencies and may improve persistence and long-range reasoning, but they also incur substantially higher training cost and introduce increasingly heterogeneous histories

Figure

B. Horizon controls Behaviors

12K (Balanced)

4K (Under-persistent)

Figure

16K (Over-persistent)

Too little

(premature termination)

Productive persistence

Excessive

(post-solution overreach)

Persistence

Figure

Supervision Horizon

Figure 1: Overview of our three main findings on effective training horizons for terminal agents. (A) Reliability Improves with Diminishing Returns: increasing the training horizon substantially improves reliability, but the marginal gains diminish beyond an intermediate sweet spot, where 12K provides a favorable balance between successful attempts, training compute, and inference length. (B) Horizon Controls Behaviors: increasing the training horizon shifts agents from under-persistence at 4K, to productive persistence at 12K, and over-persistence at 16K; theoretically, this reflects a trade-off between decreasing temporal supervision bias and increasing estimation difficulty. (C) Less is More: Quality over Quantity in Long-Horizon Training: simply training on more long-horizon trajectories is not necessarily beneficial; training on a smaller set of appropriately selected long-horizon trajectories can achieve higher reliability than using the full long-horizon data, showing that data quality matters more than data quantity for exploiting long-horizon supervision.

and more complex decision situations. As shown in Table 1, increasing the cutoff from 8K to 16K more than doubles training time, from 21.65 to 50.81 hours, while Terminal-Bench accuracy improves only marginally from 25 to 26. Moreover, the 12K model achieves the highest accuracy of 29 with 35.44 hours of training, suggesting that simply extending the supervision horizon does not yield proportional performance gains and may even exhibit diminishing returns. This motivates two important design questions that remains largely unresolved:

Q1: Is supervising the longer teacher trajectory always better?

Q2: Can selectively chosen long-horizon trajectories provide better and more efficient supervision than using all long-horizon data?

To answer these questions, we study the effective training horizon for terminal agents: a horizon that is sufficiently long to capture useful temporal dependencies, yet not so long that additional supervision becomes inefficient or counterproductive. As summarized in Figure 1, our study reveals three main findings. ① First, increasing the training horizon substantially improves reliability, but the gains diminish beyond an intermediate sweet spot, indicating that full-horizon supervision is not necessarily optimal. ② Second, the training horizon systematically shapes the agent's behavioral regime: short horizons induce under-persistence, intermediate horizons encourage productive persistence, while excessively long horizons lead to over-persistence, causing agents to continue acting unnecessarily and resulting in longer test-time inference trajectories. We further explain this intermediate optimum theoretically by decomposing the total error into two competing quantities: temporal supervision bias, which decreases as longer horizons expose the model to richer later-stage behaviors, and finite-sample estimation error, which increases as the learner must model a more complex set of long-horizon histories. The effective training horizon therefore emerges at an intermediate point that balances the decreasing temporal supervision bias against the increasing estimation error. These findings lead to a declarative answer to Q1: No, supervising a longer teacher trajectory is not always better; the effective training horizon lies in the middle. ③ Third, we show that more long-horizon data is not always better. A two-stage strategy that first trains on the full short-horizon data and then refines the model using only half of the long-horizon trajectories achieves higher reliability than full long-horizon training while reducing both training and inference costs. This leads to a declarative answer to Q2: Yes, selectively chosen long-horizon trajectories can provide more effective and efficient supervision than using the full long-horizon dataset.

Our contributions are fourfold and organized as follows. ① First, we characterize the relationship between training horizon and agent reliability, showing that reliability improves with longer supervision but exhibits diminishing returns (Section 4). ② Second, we explain this scaling behavior empirically through the notion of persistence, revealing a transition from under-persistence to productive persistence and eventually over-persistence (Section 5.1). ③ Third, we theoretically explain why longer supervision eventually exhibits diminishing returns, characterizing the effective training horizon through a trade-off between temporal supervision bias and finite-sample estimation error (Section 5.2). ④ Fourth, we propose a simple, efficient two-stage training strategy that combines full short-horizon training with selective long-horizon refinement to further improve reliability (Section 6).