Manuscript Offprint

arXiv:2610.13020

Trajectory-Aware Policy Optimization: Closing the State Distribution Gap in Long-Horizon LLM RL

Zhicheng Cai, Weinan Dai, Yuyan Zhou, Wei-Ying Ma, Ya-Qin Zhang, Hao Zhou

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

ABSTRACT

Reinforcement learning (RL) has become a dominant paradigm for enhancing LLMs' reasoning capabilities. Yet long-horizon autoregressive rollouts introduce a fundamental limitation: local policy mismatch can compound into severe state distribution shift over trajectories. Existing LLM RL methods, such as GRPO and GSPO, control policy mismatch at the token or sequence level, but overlook this trajectory-induced shift, causing training instability and eventual collapse as the horizon grows. To close the state distribution gap, we propose Trajectory-Aware Policy Optimization (TAPO), a principled framework that theoretically derives the state-distribution correction from the off-policy policy gradient and incorporates it into the RL objective. TAPO further employs a geometric-mean estimator for variance reduction, together with a length-aware dynamic clipping that prevents overly deviated updates across the trajectory. Extensive experiments demonstrate that TAPO significantly surpasses existing LLM RL algorithms across eight competition-level benchmarks, achieving up to 48% and 12% improvement over GRPO on mathematical reasoning and algorithmic coding, with substantially enhanced training stability.

1 INTRODUCTION

Reinforcement Learning (RL) has emerged as a critical paradigm for eliciting complex reasoning capabilities in Large Language Models (LLMs) (Guo et al., 2025; Comanici et al., 2025; OpenAI, 2024), yielding major breakthroughs across long-horizon reasoning frontiers including mathematical problem-solving (Shao et al., 2024; Wang et al., 2024; Luo et al., 2025), algorithmic coding (Dou et al., 2024; Anthropic, 2024), and deep search (OpenAI, 2025; Jin et al., 2025).

However, long-horizon autoregressive rollouts expose RL to a fundamental vulnerability: local policy mismatch can compound into severe state distribution shift over the trajectory. At each step, the target policy acts on a state induced by all previously sampled tokens, making its state distribution dependent on the entire history of policy deviations. Thus, even modest deviations at individual positions can propagate through the trajectory, progressively driving the target policy toward states increasingly distant from the behavior policy's state distribution. As empirically demonstrated in Fig. 1, while the local token-level ratio remains relatively controllable across positions, the state-level ratio progressively drifts away from unity over long horizons.

Importance sampling provides a principled mechanism for correcting off-policy sampling mismatch, yet existing LLM RL methods primarily perform this correction at the action level. Two representative approaches, GRPO (Shao et al., 2024) and GSPO (Zheng et al., 2025), operate at different granularities: GRPO applies token-level importance ratios, while GSPO regards the full sequence as an action and aggregates token-level ratios into a sequence-level correction. However, neither explicitly corrects for the state distribution shift induced by the preceding trajectory. Consequently, as response lengths grow during training, the accumulated state shift manifests as an increasing KL divergence between the behavior and target policies, eventually driving training into collapse, as

*Corresponding author: zhouhao@air.tsinghua.edu.cn

Figure

Figure 1: Policy shifts along long-horizon token positions, measured by token- and state-level policy ratios and KL divergences. The dots are randomly sampled through the training process of GRPO. While the token-level ratio remains relatively stable across positions, the state-level ratio progressively deviates from unity toward later positions, revealing the accumulation of policy shift over long-horizon trajectories.

RL Objective

GRPO: token-level ratio

J(π)=Ex∼D,o∼μ(⋅∣x)[1∣o∣∑t=1∣o∣R~t⋅A^t]\mathcal{J}(\pi)=\mathbb{E}_{x\sim\mathcal{D},o\sim\mu(\cdot|x)}\left[\frac{1}{|o|}\sum_{t=1}^{|o|}\tilde{R}_{t}\cdot\hat{A}_{t}\right]

GSPO: sequence-level ratio

R~tGRPO=π(ot∣x,o<t)μ(ot∣x,o<t)\tilde{R}_{t}^{GRPO}=\frac{\pi(o_{t}|x,o_{<t})}{\mu(o_{t}|x,o_{<t})}

TAPO: trajectory-aware ratio

R~tGSPO=(∏i=1∣o∣π(oi∣x,o<i)μ(oi∣x,o<i))1∣o∣\tilde{R}_{t}^{GSPO}=\left(\prod_{i=1}^{|o|}\frac{\pi(o_{i}|x,o_{<i})}{\mu(o_{i}|x,o_{<i})}\right)^{\frac{1}{|o|}} R~tTAPO=(∏i=1tπ(oi∣x,o<i)μ(oi∣x,o<i))1t\tilde{R}_{t}^{TAPO}=\left(\prod_{i=1}^{t}\frac{\pi(o_{i}|x,o_{<i})}{\mu(o_{i}|x,o_{<i})}\right)^{\frac{1}{t}}

Training Score

Mean Response Length

KL between Policies

Policy Entropy

Figure

Figure 2: Formulations (upper) and training dynamics (bottom) of GRPO, GSPO, and TAPO. GRPO and GSPO apply policy-ratio correction at the token and sequence levels, respectively, whereas TAPO explicitly incorporates the state-distribution correction induced by the preceding trajectory. As response lengths increase, GRPO and GSPO exhibit growing KL divergence and eventual training collapse, while TAPO maintains controlled KL divergence and stable improvement.

shown in Fig. 2. This exposes a fundamental gap in existing policy optimization: controlling action-level mismatch at the token or sequence level does not guarantee control of the state distribution shift induced over long-horizon trajectories.

To close this gap, we propose Trajectory-Aware Policy Optimization (TAPO), a theoretically grounded RL algorithm that fundamentally corrects the state distribution shift over the trajectory. We first derive the off-policy policy gradient to reveal the state-distribution correction required for long-horizon autoregressive trajectories, and incorporate this correction into the RL objective. To control the variance of the state-level correction, we use a geometric-mean estimator over the preceding trajectory, yielding a stable and length-robust trajectory-aware policy ratio (Fig 2). Building on this formulation, we further introduce a dynamic clipping mechanism that adapts the clipping boundary to the length of preceding trajectory, preventing overly aggressive updates as the horizon grows while preserving sufficient flexibility at early explorations.

We conduct extensive experiments across various LLMs and competition-level benchmarks for mathematical reasoning and algorithmic coding. TAPO consistently outperforms existing RL algorithms, achieving up to 48% and 12% average improvements over GRPO on math and code, respectively, demonstrating substantial gains in long-horizon reasoning performance. Moreover, as Fig. 2 shows, while GRPO and GSPO eventually suffer from training collapse as the policy shift grows, TAPO maintains a steadily increasing training score with controlled KL divergence. These results demonstrate that explicitly correcting the trajectory-induced state distribution shift not only improves reasoning performance but also substantially enhances training stability.

In summary, our contributions are threefold:

• We identify and formalize the accumulation of state distribution shift as a fundamental issue in long-horizon LLM RL, and derive its corresponding correction from the off-policy policy gradient.

• We propose TAPO, a theoretically grounded RL algorithm, employing geometric-mean trajectory-aware ratio together with length-aware dynamic clipping for stable long-horizon optimization.

• Extensive experiments across mathematical reasoning and algorithmic coding demonstrate that TAPO consistently improves reasoning performance with enhanced training stability.

References (33)