Manuscript Offprint
arXiv:2610.19376DeLoop: Repeated Actions as Self-Supervision for Long-Horizon Agents
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Tianle Chen, Pushkar Singh, Ketan Todi, Biswajit Paria, Qijia He, Wenqi Wang, Yuwen Tan, Jike Zhong, Sugato Basu, Deepti Ghadiyaram, Arjun Akula
Google, Boston University, University of Washington, University of Southern California, Google DeepMind, Project lead
Language-model agents that run long tasks often redo work they have already done: they re-issue a tool call they made earlier and get back exactly the same observation, a step that adds no new information. We identify this failure as a loop. Loops appear natively in Qwen, Llama, and Gemini agents and become far more common once the agent's history is compressed to fit its context window. To reduce these loops, we propose DeLoop, a self-supervised training method. DeLoop builds on a simple observation: the agent's own rollout can provide the supervision needed to learn from its loops. We use a looping action as a negative example and the first later non-looping action in the same rollout as a positive example. DeLoop learns from these pairs through direct preference optimization and does not require task rewards, gold answers, or LLM judges. On CodeGym under compression, DeLoop reduces the share of Qwen3-8B tasks containing loops from 57.3% to 6.1%. It also uses about one third as many steps per task, with similar task success. On Qwen3-32B, DeLoop reduces loops and steps while raising task success from 37.7% to 44.8%. Code and data will be publicly available.
Keywords: LLM agents, long-horizon agents, agent memory, context compression, agent loops, repeated actions, preference optimization
1. Introduction
Language-model agents increasingly solve tasks over long interaction horizons: they inspect repositories, execute commands, call tools, and act on environment feedback across many steps (Du et al., 2025; Jimenez et al., 2024; Yang et al., 2024a; Yao et al., 2023). Yet they often redo work they have already done. The agent calls the same tool with the same arguments, receives the same observation, and then issues the same call again (Figure 1). Each repeated call is a looping action: it gets back an observation the agent already has and adds no new information. We formulate this failure as a loop.
The failure is already present even when the full, uncompressed history is available, but compression makes it worse. On CodeGym (Du et al., 2025), the loop rate of Qwen3-8B (Yang et al., 2025), the share of tasks with at least one loop, rises from 29.0% with the full history (no summarization) to 57.3% under summarization, while looping actions per task increase more than More importantly, in addition to wasted tool calls, we empirically observed that trajectories that enter a loop fail in all six Qwen3 and Gemini models we evaluate: on average, 59.5% of looping runs fail, compared with 33.4% of loop-free runs (Figure 2). Thus, context compression makes looping more likely and increases the chances of task failure.
Recent work manages growing interaction histories through external memory (Fox et al., 2026; Packer et al., 2023), hierarchical or summarized working context (Hu et al., 2025; Sun et al., 2026; Wu et al., 2025), compact learned state (Zhou et al., 2025), and learned context compression or management (Kang et al., 2026; Liu et al., 2025; Lu et al., 2026). These works study what history should an agent retain to continue acting well under a bounded context window. In contrast, we study a complementary question about how the agent's policy uses its history after compression. That is, when the history records an action, does the agent use that record to avoid repeating it? We find that most agents do so only partly.
Another way to reduce looping is to improve the agent's policy. Some methods address agent failures at inference time through reflection (Shinn et al., 2023) or early stopping (Lu et al., 2025). Others train agents using demonstrations (Chen et al., 2023; Zeng et al., 2024), search-based training data (Yuan et al., 2025), or step-level supervision (Chen and Yuille, 2026; Tang, 2026; Xiong et al., 2024). We instead ask: can the failure itself provide a useful signal to improve agent's policy?
Based on these observations, we propose De-Loop, a self-supervised training method. Our key observation is that loops can provide their own training signal. We note that a loop is a simple trajectory-level event that can be identified directly from the action-observation trace, without requiring post-hoc failure attribution (Barke et al., 2026;
© 2026 Google. All rights reserved
Google Technical Report

Qwen3-8B on CodeGym

Figure 1: Training an agent on its own loops breaks the loop. (Left) A repeated search and the later action that marks the server as visited form a preference pair. DPO trains the agent to prefer the recovery. (Right) Qwen3-8B on CodeGym: DeLoop and the baseline summarize at 4,096 tokens; full history is the uncompressed reference.
Hou et al., 2026). Within a single rollout, we pair a looping action with the first later non-looping action that differs from it. The looping action provides a natural negative, while the later action provides a positive signal. Figure 1 illustrates this. These pairs are mined directly from the interaction, without gold answers, LLM judges, external rewards, or task-success labels. We train the policy on these pairs through direct preference optimization (DPO Rafailov et al., 2023).
On Qwen3-8B, DeLoop cuts the loop rate while lowering interaction cost, with similar task success. On Qwen3-32B, the self-mined pairs alone reduce loop rate from 38.5% to 12.9% and raise task success from 37.7% to 44.8%, while also lowering interaction cost. Adding cross-domain pairs (DeLoop-Mix) raises Qwen3-8B task success from 25.1% to 30.3%. Our contributions are:
-
Identifying loops in long-horizon agents: we identify and characterize loops, a simple failure in which an agent repeats an earlier action and receives the same observation. We show that loops occur even with the full history, grow sharply under compression, and are associated with task failure.
-
Mining loop actions as self-supervision: we introduce a simple mining method that turns discovered loops into preference pairs from the agent's own rollouts, with no external supervision.
-
Reducing loops in long-horizon agents: DeLoop reduces loops (57.3% to 6.1% on Qwen3-8B) while lowering interaction cost. The gains also extend to larger models, where there is pronounced improvement in task success (45.1% to 52.3% on Qwen3-14B and 37.7% to 44.8% on Qwen3-32B).
Context management. Long-horizon agents need to fit their history into a limited context. Common context management methods store the history in external memory or searchable logs (Fox et al., 2026; Packer et al., 2023; Wang et al., 2026b), summarize older interactions (Hu et al., 2025; Su et al., 2026; Sun et al., 2026; Wu et al., 2025), keep a compact learned state (Zhou et al., 2025), learn what to keep (Kang et al., 2026; Liu et al., 2025; Lu et al., 2026), or validate their summaries (Chen et al., 2026). However, removing plans from the context sharply hurts performance (Mehta and Datta, 2026). These methods decide what history to keep. We instead ask whether the agent uses the kept history to avoid repeating actions.
Learning from agent trajectories. Most methods that train agents on trajectories need an external signal to pick the better action. Agent tuning uses filtered or teacher-generated trajectories (Chen et al., 2023; Fu et al., 2025; Zeng et al., 2024), or successful attempts and outcome feedback (Guo et al., 2025; Jung et al., 2025; Le et al., 2026; Wang et al., 2024; Yang et al., 2024b; Zelikman et al., 2022). ETO and Agentic-DPO take the better action from experts (Chen and Yuille, 2026; Song et al., 2024). Step-DPO, IPR, and ToolGraph use step-level labels or rewards (Lai et al., 2024; Tang, 2026; Xiong et al., 2024). Agent-R and Agent Q use tree search guided by rewards or critiques (Putta et al., 2024; Yuan et al., 2025), and SCoRe trains self-correction with online RL (Kumar et al., 2025). DeLoop instead takes the better action from the agent's own later recovery in the same rollout and trains with DPO (Rafailov et al., 2023). Its only label is the exact-repeat rule of Section 3.1, so it needs no rewards, expert actions, or step labels. Like hindsight experience replay (Andrychowicz et al., 2017), it also learns from failed rollouts.
Penalizing repetition. Repetition can also be penalized directly. RLTR adds a penalty on redundant tool calls to its reward (Li et al., 2025). In text generation, penalized sampling (Keskar et al., 2019), unlikelihood training (Welleck et al., 2020), and DITTO (Xu et al., 2022) reduce repeated tokens and sentences. These penalties mark what to avoid; DeLoop also supplies the agent's own alternative action. Using our loop flag as a per-step penalty in online RL (GRPO) lowers the Qwen3-8B loop rate on CodeGym from 57.3% to 15.0%, against 6.1% for DeLoop (Section 5.3).
3. Loops in Long-Horizon Agents
3.1. Defining a Loop
A loop occurs when the agent repeats a previous tool call with identical arguments and receives the same observation. Thus, that step adds no new information.
For example, consider an agent counting clusters of online servers on a grid. The agent has tools to find unvisited servers and mark them as visited. In one rollout, it issues the same search three times without marking the returned server. Because that server remains unmarked, each call returns the same coordinates. The latter two calls therefore add no new information. This rollout comes from a Qwen3-8B agent on CodeGym (Du et al., 2025), where agents solve tasks through sequences of tool calls. Appendix B shows the rollout excerpt.
We detect such repetitions by comparing each tool call and its observation with earlier steps. Let denote the tool call at step , and its returned observation. We denote a trajectory of steps by . With canonicalizing each tool call so that formatting differences do not count, let denote the signature of step . Step is a repeat if its signature appeared earlier:
A trajectory loops if it contains at least one repeat:
A step with is a looping action. A repeated call with a new observation is not a looping action. We then label any run containing at least one looping action as a looping run. We report the percentage of looping runs as the loop rate.
3.2. Loops Are Costly
Each looping action consumes tokens and a tool execution without yielding a new observation. Under a fixed interaction budget, these repeated calls leave fewer opportunities to take actions that could advance the task. We compare looping and loop-free Qwen3-8B runs on CodeGym under summarization at 4,096 tokens. Both groups include successful and failed runs. Looping runs contain 6.5 looping actions on average. They execute 10.5 more actions per task on average than loop-free runs. Their interaction transcripts also contain 11k more tokens. The same pattern holds for all six models in the cost comparison (Appendix Figure 7).
Within each model’s compressed setting, looping runs are also more likely to fail than loop-free runs (Figure 2). The gap appears in all six Qwen3 and Gemini models: Qwen3-8B fails 85% of looping runs against 68% of loop-free runs. Gemini 3.1 Pro shows a wider gap: 48% against 12%. A loop thus marks a run that is more likely to fail and has a higher execution cost.
3.3. Compression Makes Loops More Common
An agent’s interaction history records what it has already done. To keep long rollouts within a context budget, the agent summarizes earlier interactions (Appendix D). We examine whether this compression makes the agent more likely to repeat completed actions. On CodeGym, Qwen3-8B loops in 29.0% of runs with the full history. Summarization at 4,096 tokens raises the loop rate to 57.3%. Lowering the threshold to 2,048 tokens raises it further to 64.7% (Figure 3a).
The same pattern appears in all three Gemini models that we run with and without compression (Figure 3b). We compare CodeGym runs with the full history against the subset of summarization runs in which compression fires. Gemini 3.1 Pro loops least with the full history yet shows the largest increase, .
To investigate this increase, we ask whether removing a completed action’s record makes the agent more likely to repeat it. We reconstruct 300 histories from 253 CodeGym tasks after compression. Each ends just before Qwen3-8B chooses its

Figure 2: Failure rates of looping and loop-free runs. Task-failure rate for runs with a loop (red) and without one (gray), for Qwen3-8B, Qwen3-14B, and four Gemini models in their compressed settings. Detector details: Appendix E.
next action. One version of each history keeps the most recent completed tool call and its observation. The other removes this record. We sample the next action eight times from each version. The agent repeats that call in 3.3% of samples with the record present and 48.8% with it removed (Appendix F).
The record therefore helps the agent avoid an immediate repeat. This explains why compression causes more loops. However, over a whole episode, keeping the record is not enough: Qwen3-8B still loops in 29.0% of runs with the full history. Under compression, a quarter of runs (25.2%) repeat a call that is still in the context word for word (Appendix J.1).
Better context management does not close this gap. Summaries that keep an explicit record of past actions, such as a trace of every executed call or a ledger of tried actions, still loop in 52.0% to 62.7% of runs, close to standard summarization at 57.3% (Appendix Table 4). The compressors ACON (Kang et al., 2026) and LLMLingua-2 (Pan et al., 2024) lower the loop rate to 46.3% and 46.7%, still well above the 29.0% with the full history. The agent often fails to use a record it has, so we train the policy itself (Section 4). This complements better compression: DeLoop-Mix lowers the loop rate under every memory policy we test (Section 6.1).
4. Repeated Actions as Self-Supervision
To reduce looping under compressed context, we propose DeLoop, preference optimization on self-mined loop pairs. A detected looping action serves as a negative example. If the same rollout later contains a different, non-looping action, the first such action serves as a positive example (Figure 4).
(a) Qwen3-8B on CodeGym

(b) Gemini models on CodeGym

Figure 3: Loop rates with and without compression. (a) Qwen3-8B on CodeGym across context settings. (b) Gemini full-history runs versus compression-triggered episodes of summarization runs.
4.1. Mining Preference Pairs from Loops
We run the compressed agent on training tasks and apply the structural detector of Section 3.1 to each rollout. For each detected looping action , we use that action as the rejected response . If the agent later recovers from the loop in the same rollout, we use the first action that breaks the loop as the chosen response .
For training, we pair both actions with the history that preceded the looping action:
If the agent does not recover from the loop before the rollout ends, we do not construct a training pair for that looping action. A single rollout can contribute multiple pairs.
For instance, the episode in Appendix B yields one of our self-mined pairs. The rejected action is the looping FindUnvisitedOnlineServer(start_row=3, start_col=0). The chosen action is the agent's own later MarkVisited(row=3, col=0), which breaks the loop.
Such a recovery provides a training pair even if the rollout ultimately fails the task. We identify the looping action and the subsequent recovery from the actions and observations alone. Pair construction therefore requires no task reward, gold label, or LLM judge.
Agent rollout (CodeGym)
Preference pair

no reward · no gold label · no LLM judge
Figure 4: A self-mined preference pair. Abridged Qwen3-8B CodeGym rollout (tool names shortened; Appendix B). x: history before the looping action; : looping action; : first later loop-breaking action.
4.2. Preference Training
We train the policy to prefer the chosen action over the looping action under the same context x. We use direct preference optimization (DPO; Rafailov et al., 2023), with the frozen base policy as the reference:
For Qwen3-8B, we train for one epoch with LoRA DPO ( ) on 8,000 self-mined CodeGym pairs. For Qwen3-14B and Qwen3-32B, we use the same mining rule and , with pairs mined from each model's own rollouts (Sections G.1 and G.17).
At inference time, we use the trained policy throughout the rollout to generate each next action. In our standard setting, the harness triggers compression when the estimated history exceeds 4,096 tokens. The same trained model summarizes older interactions under a separate prompt. It then continues acting from the updated context (Appendix D). DPO directly trains action preferences. Summary generation shares the updated weights but has no separate training objective.
5. Experiments
We first evaluate DeLoop on CodeGym and examine its training signal. We then vary the training data, context settings, and agent environments.
5.1. Experimental Setup
Benchmarks and models. CodeGym (Du et al., 2025) is our primary benchmark for both mining and evaluation: its tasks require many
| Method | Supervision (labels needed) | Loop (%) ↓ | Success (%) ↑ | Steps ↓ | Tokens/task (k) ↓ |
|---|---|---|---|---|---|
| Reference | |||||
| Full history | none | 29.0 | 31.7 | 12.23 | 24.3 |
| Training-free context methods | |||||
| Compressed baseline | none | 57.3 | 25.1 | 15.00 | 23.9 |
| Retrieval memory | none | 42.7 | 27.7 | 13.34 | 26.1 |
| ACON compressor | none | 46.3 | 29.3 | 14.84 | 20.5 |
| LLMLingua-2 compressor | none | 46.7 | 23.7 | 14.48 | 26.8 |
| History truncation | none | 65.3 | 18.0 | 16.05 | 34.8 |
| Training-free inference-time controls | |||||
| Exact duplicate blocker | none | 46.7 | 25.3 | 14.71 | 24.9 |
| Reflexion on stuck | none | 55.3 | 24.3 | 14.62 | 24.1 |
| Trained with labels | |||||
| Outcome DPO | outcome-ranked pairs (task success) | 34.7 | 25.7 | 10.99 | 15.9 |
| SFT on solved traces | solved trajectories (task success) | 42.7 | 21.3 | 10.61 | 25.2 |
| Gold-label DPO | looping pairs from outcomes (task success) | 22.3 | 25.7 | 8.10 | 11.3 |
| Gold-action GRPO | gold-action match reward (gold action) | 52.7 | 25.0 | 14.23 | 21.0 |
| Trained without labels | |||||
| Distillation SFT | full-history traces (none) | 43.7 | 26.3 | 11.52 | 26.6 |
| Ours | |||||
| DeLoop (ours) | self-mined pairs (none) | 6.1 (-51.2) | 25.9 (+0.8) | 4.67 (-10.33) | 12.7 (-11.2) |
| DeLoop-Mix (ours) | + cross-domain pairs (none) | 10.1 (-47.2) | 30.3 (+5.2) | 5.94 (-9.06) | 9.6 (-14.3) |
Table 1: Main comparison on CodeGym. Qwen3-8B under summarization at 4,096 tokens unless noted. Steps and estimated tokens are per-task averages. Shading: our methods; green: best compressed result; parentheses: change from the compressed baseline.
act–observe rounds, so the history grows until compression fires. We also evaluate on four further agent environments: ALFWorld (Shridhar et al., 2021), Open-AgentRL (Wang et al., 2026a), AppWorld (Trivedi et al., 2024), and ScienceWorld (Wang et al., 2022). Terminal-Bench (Merrill et al., 2026) and BrowseComplus (Chen et al., 2025) provide further evaluations in their native agent harnesses (Section 6.3). Our main agent is Qwen3-8B, and we repeat the CodeGym study with Qwen3-14B and Qwen3-32B (Yang et al., 2025).
Training variants. DeLoop trains on self-mined CodeGym pairs (Section 4.2). We also evaluate DeLoop-Mix, a variant trained with additional cross-domain pairs (Section 5.4). Its training data include pairs mined from Terminal-Bench rollouts.
Evaluation protocol and metrics. In our standard compressed setting, the agent summarizes its history whenever it exceeds 4,096 tokens; the same model writes the summary and continues from it. Unless noted otherwise, each policy in the main CodeGym comparison acts in this setting on 300 held-out tasks, and the full-history agent serves as the uncompressed reference. We report four metrics: the loop rate (Section 3), task success, steps per task, and estimated tokens per task (Appendix A).
Baselines. Training-free context methods change what the agent keeps from its history, including retrieval memory, ACON (Kang et al., 2026), and LLMLingua-2 (Pan et al., 2024). Training-free inference-time controls act during inference, including an exact duplicate blocker and Reflexion (Shinn et al., 2023). Trained baselines learn from task outcomes, solved trajectories, or gold actions, and distillation SFT on full-history traces is, like DeLoop, label-free. We do not run GRPO on task success: its reward arrives only once per episode, and even a per-step gold-action reward leaves only 2.7% of GRPO groups informative (Appendix G.10). The full battery is in Appendix Tables 4 and 18.
5.2. Main Results on CodeGym
We first test whether DeLoop reduces loops and interaction cost while maintaining task success on CodeGym (Table 1).
Qwen3-8B results. Self-mined pairs give the lowest loop rate of all methods. DeLoop cuts the loop rate 9.4×, from 57.3% to 6.1%. Training-free

Figure 5: Model scaling on CodeGym. Qwen3-8B, Qwen3-14B, and Qwen3-32B under summarization at 4,096 tokens. Task success versus loop rate, steps, and estimated tokens per task (left to right). Squares: compressed baseline; stars: DeLoop; colors: model size.
methods in Table 1 remain between 42.7% and 65.3%, and the strongest labeled baseline, gold-label DPO, reaches 22.3%. Breaking the loop also removes wasted interaction: steps per task fall from 15.00 to 4.67, fewer than any other method, and tokens per task fall by 47%, while task success holds.
Model scaling. We next test the same training signal at larger model sizes. We mine pairs from the compressed CodeGym rollouts of Qwen3-14B and Qwen3-32B with the same rule and train each model with DPO (Figure 5). Loops fall at every scale, on Qwen3-14B and on Qwen3-32B. Tokens per task fall by 35% and 29%, respectively. At these scales the repair also raises task success, by 7.2 points on Qwen3-14B and 7.1 points on Qwen3-32B.
General capability. We also check capabilities beyond agent rollouts. Performance is preserved on LiveCodeBench, MT-Bench, and IFEval (Appendix G.15).
5.3. Ablation Studies
We next examine the roles of the preference pair and the training objective (Table 2).
Contribution of each side of the pair. The looping action matters. Imitating only the loop-breaking action leaves a loop rate of 37.7%, while the contrast with the looping action brings it to 6.1%.
| Policy | Loop (%) ↓ | Success (%) ↑ |
|---|---|---|
| Compressed baseline | 57.3 | 25.1 |
| Objective (same loop signal) | ||
| DPO (DeLoop) | 6.1 (-51.2) | 25.9 (+0.8) |
| KTO | 12.6 | 23.8 |
| IPO | 11.7 | 24.0 |
| Looping-action penalty GRPO | 15.0 | 24.7 |
| SFT (chosen action only) | 37.7 | 21.3 |
Table 2: Training-objective ablations. Qwen3-8B on CodeGym under summarization at 4,096 tokens. DPO, KTO, IPO, and SFT use the same 8,000 self-mined pairs; SFT uses only chosen actions. GRPO penalizes looping actions in online rollouts. Parentheses: change from the compressed baseline.
Alternative training objectives. We then test the loop signal beyond DPO, using KTO (Ethayarajh et al., 2024), IPO (Azar et al., 2024), and online GRPO (Shao et al., 2024). Every objective cuts the loop rate to or below, and DPO (DeLoop) gives the lowest loop rate and the highest task success.
Remaining repeated actions. We also examine which repeated actions remain after training. The share of repeats that return new information rises from 29.9% to 69.8% (Appendix G.7).
5.4. Effect of Cross-Domain Training Data
Self-mined CodeGym pairs preserve task success at 8B. We next test whether adding experience from other agent tasks can improve it. We keep the 8,000 CodeGym pairs fixed, add 4,635 cross-domain pairs from ALFWorld, Open-AgentRL, and


Figure 6: Cross-domain data and context management. Qwen3-8B on CodeGym. (a) Task success with and without compression. (b) Loop rate across context settings. (c) Loop rate across memory policies. Base: untrained policy.
| Env. | Loop (%) ↓ | Success (%) ↑ | Tokens (k) ↓ | |||
|---|---|---|---|---|---|---|
| Base | Ours | Base | Ours | Base | Ours | |
| ALFWorld | 55.2 | 27.6 (-27.6) | 37.3 | 38.1 (+0.8) | 9.3 | 6.2 (-3.1) |
| Open-AgentRL | 79.0 | 73.5 (-5.5) | 43.9 | 45.5 (+1.6) | - | - |
| AppWorld | 73.7 | 40.9 (-32.8) | 7.0 | 5.8 (-1.2) | 17.9 | 14.1 (-3.8) |
| ScienceWorld | 96.5 | 83.5 (-13.0) | 3.5 | 1.5 (-2.0) | 6.5 | 6.0 (-0.5) |
Table 3: Evaluation in four additional agent environments. Base: untrained Qwen3-8B. Ours: DeLoop-Mix. Native metrics; green: improvement; parentheses: change from Base.
Terminal-Bench rollouts, mined with the same label-free rule, and train Qwen3-8B on all 12,635 pairs with the same DPO recipe to obtain DeLoop-Mix.
DeLoop-Mix raises success both with and without compression (Figure 6a). Under summarization at 4,096 tokens, the CodeGym success of Qwen3-8B rises from 25.1% to 30.3%, a gain of 5.2 points, compared with +0.8 points for DeLoop. With the full history, success rises from 31.7% to 36.2%, a gain of 4.5 points. The loop repair stays in place: the loop rate falls from 29.0% to 10.1% without compression and from 57.3% to 10.1% with it. Under summarization, DeLoop-Mix also uses the fewest tokens per task shown in Table 1.
6. Robustness and Generalization
The CodeGym results show that self-mined pairs reduce loops and interaction cost. We now test whether these gains extend to other context settings, memory policies, and agent environments.
6.1. Generalization Across Compression Settings and Memory Policies
We first evaluate our Qwen3-8B DeLoop policy on CodeGym under five context settings, from the full history to summarization at 2,048 tokens and truncation at 4,096 tokens. The loop rate falls in every setting, remaining between 4.7% and 12.8% while the untrained baseline reaches 65.3% (Figure 6b).
Beyond the amount of retained history, we vary how it is represented. We run DeLoop-Mix (Section 5.4) under seven alternative memory policies, from retrieval memory and Claude-style compaction to summaries augmented with an action ledger. The loop rate, steps per task, and tokens per task fall under all seven (Figure 6c); with the action ledger, the loop rate falls from 62.7% to 11.3% and task success rises by 5.7 points.
6.2. The Improvement Extends to Other Agent Environments
The context comparisons above all use CodeGym. We next run DeLoop-Mix in four further environments, ALFWorld, Open-AgentRL, AppWorld, and ScienceWorld, scored with each environment's native loop and success metrics (Table 3). ALFWorld and Open-AgentRL are evaluated on unseen games, disjoint from the training games behind their pairs (Appendix G.1). Loops fall in all four, by up to 32.8 points on AppWorld. Tokens per task fall wherever recorded, and task success on Open-AgentRL rises from 43.9% to 45.5%.
6.3. The Repair Transfers to New Benchmarks
Finally, we test DeLoop and DeLoop-Mix in native agent harnesses with different tools and interactions. Terminal-Bench tests terminal tasks, and BrowseComp-Plus tests web research. On Terminal-Bench, DeLoop cuts unproductive duplicate calls from 16.6 to 6.9 per task. On all 830 BrowseComp-Plus queries, DeLoop-Mix lowers the loop rate from 22.4% to 1.2% while matching the untrained model's accuracy; DeLoop, trained on CodeGym pairs alone, already lowers it to 6.4%. We also test zero-shot transfer from CodeGym to ALFWorld. DeLoop on Qwen3-32B, trained only on CodeGym pairs, lowers the ALFWorld loop rate from 64.9% to 54.5% and raises task success from 33.6% to 42.5%.
7. Conclusion
Long-horizon agents that compress their history fall into loops: they re-issue an action they already ran and receive the same result. On CodeGym, summarizing the history raises the loop rate of Qwen3-8B from 29.0% to 57.3%, and better context management alone does not remove it. Our key observation is that the loop labels itself: the looping action is the rejected action, and the agent's later loop-breaking action is the chosen one. Trained on these self-mined pairs, DeLoop cuts the loop rate , from 57.3% to 6.1%, at about one third of the steps per task while maintaining task success, and raises task success by 7.2 points at 14B and 7.1 points at 32B. An agent's own loops become its supervision: break the loop, keep the progress. We believe our work could help the community better understand and reduce loops in long-horizon agents.
References
M. Andrychowicz, F. Wolski, A. Ray, J. Schneider, R. Fong, P. Welinder, B. McGrew, J. Tobin, P. Abbeel, and W. Zaremba. Hindsight experience replay. In Advances in Neural Information Processing Systems, volume 30, 2017. URL https://proceedings.neurips.cc/paper/2017/hash/453fadbd8a1a3af50a9df4df899537b5-Abstract.html.
M. G. Azar, M. Rowland, B. Piot, D. Guo, D. Calandriello, M. Valko, and R. Munos. A general theoretical paradigm to understand learning from human preferences. arXiv preprint arXiv:2310.12036, 2024.
S. Barke, A. Goyal, A. Khare, A. Singh, S. Nath, and C. Bansal. AgentRx: Diagnosing AI agent failures from execution trajectories, 2026. URL https://arxiv.org/abs/2602.02475.
M. Cemri, M. Z. Pan, S. Yang, L. A. Agrawal, B. Chopra, R. Tiwari, K. Keutzer, A. Parameswaran, D. Klein, K. Ramchandran, M. Zaharia, J. E. Gonzalez, and I. Stoica. Why do multi-agent LLM systems fail? In Advances in Neural Information Processing Systems, Datasets and Benchmarks Track, 2025. URL https://proceedings.neurips.cc/paper_files/paper/2025/file/b1041e52d3be19f0a9bc491657488e4a-Paper-Datasets_and_Benchmarks_Track.pdf.
B. Chen, C. Shu, E. Shareghi, N. Collier, K. Narasimhan, and S. Yao. FireAct: Toward language agent fine-tuning. arXiv preprint arXiv:2310.05915, 2023.
Y. Chen and A. Yuille. Agentic-DPO: From imitation to agentic policy optimization on expert trajectories. arXiv preprint arXiv:2607.10601, 2026.
Y. Chen, H. Lai, Y. Feng, C. Han, Q. Zhang, B. Lu, M. Li, X. Wang, Z. Wang, S. Xu, Z. Li, Z. Jin, H. Wu, C. Li, and Q. Chen. Beyond semantic organization: Memory as execution state management for long-horizon agents, 2026. URL https://arxiv.org/abs/2606.06090.
Z. Chen, X. Ma, S. Zhuang, P. Nie, K. Zou, A. Liu, J. Green, K. Patel, R. Meng, M. Su, S. Sharifymoghaddam, Y. Li, H. Hong, X. Shi, X. Liu, N. Thakur, C. Zhang, L. Gao, W. Chen, and J. Lin. BrowseComp-Plus: A more fair and transparent evaluation benchmark of deep-research agent. arXiv preprint arXiv:2508.06600, 2025.
D. Deshpande, V. Gangal, H. Mehta, J. Krishnan, A. Kannappan, and R. Qian. TRAIL: Trace reasoning and agentic issue localization. arXiv preprint arXiv:2505.08638, 2025.
W. Du, H. Gong, Z. Ling, K. Liu, L. Shen, X. Yao, Y. Xu, D. Shi, Y. Yang, and J. Chen. Generalizable end-to-end tool-use rl with synthetic codegym. arXiv preprint arXiv:2509.17325, 2025.
K. Ethayarajh, W. Xu, N. Muennighoff, D. Jurafsky, and D. Kiela. KTO: Model alignment as prospect theoretic optimization. arXiv preprint arXiv:2402.01306, 2024.
A. Fox, J. Wang, P. Rosu, and B. Dhingra. PRO-LONG: Programmatic memory enables long-horizon reasoning. arXiv preprint arXiv:2607.20064, 2026.
D. Fu, K. He, Y. Wang, W. Hong, Z. Gongque, W. Zeng, W. Wang, J. Wang, X. Cai, and W. Xu. AgentRefine: Enhancing agent generalization through refinement tuning. In International Conference on Learning Representations (ICLR), 2025.
Gemini Team, R. Anil, S. Borgeaud, J.-B. Alayrac, et al. Gemini: A family of highly capable multimodal models. arXiv preprint arXiv:2312.11805, 2023. URL https://arxiv.org/abs/2312.11805.
A. Grattafiori, A. Dubey, A. Jauhri, A. Pandey, et al. The Llama 3 herd of models. arXiv preprint arXiv:2407.21783, 2024. URL https://arxiv.org/abs/2407.21783.
C. Gulcehre, T. L. Paine, S. Srinivasan, K. Konyushkova, L. Weerts, A. Sharma, A. Siddhant, A. Ahern, M. Wang, C. Gu, W. Macherey, A. Doucet, O. Firat, and N. de Freitas. Reinforced self-training (ReST) for language modeling. arXiv preprint arXiv:2308.08998, 2023. URL https://arxiv.org/abs/2308.08998.
Y. Guo, J. Lin, H. Wang, Y. Han, S. Hu, Z. Ni, L. Wang, and M. Chen. SE-Agent: Self-evolution trajectory optimization in multi-step reasoning with LLM-based agents. In NeurIPS, 2025.
Q. He, J. Cheng, C. Le, R. Wang, X. Liu, Y. Chen, J. Mei, Z. Wang, X. Chen, Y. Chen, and T. Wang. CodeRescue: Budget-calibrated recovery routing for coding agents. arXiv preprint arXiv:2607.19338, 2026. URL https://arxiv.org/abs/2607.19338.
X. Hou, S. Wang, Y. Zhao, and H. Wang. When agents do not stop: Uncovering infinite agentic loops in LLM agents, 2026. URL https://arxiv.org/abs/2607.01641.
E. J. Hu, Y. Shen, P. Wallis, Z. Allen-Zhu, Y. Li, S. Wang, L. Wang, and W. Chen. LoRA: Low-rank adaptation of large language models. In
International Conference on Learning Representations, 2022. URL https://arxiv.org/abs/2106.09685.
M. Hu, T. Chen, Q. Chen, Y. Mu, W. Shao, and P. Luo. HiAgent: Hierarchical working memory management for solving long-horizon agent tasks with large language model. In ACL, 2025.
N. Jain, K. Han, A. Gu, W.-D. Li, F. Yan, T. Zhang, S. Wang, A. Solar-Lezama, K. Sen, and I. Stoica. LiveCodeBench: Holistic and contamination free evaluation of large language models for code. In International Conference on Learning Representations, 2025. URL https://arxiv.org/abs/2403.07974.
C. E. Jimenez, J. Yang, A. Wettig, S. Yao, K. Pei, O. Press, and K. Narasimhan. SWE-bench: Can language models resolve real-world GitHub issues? In ICLR, 2024.
Y. Jung, T. Padhi, S. Shaham, D. Khullar, J. Jeong, N. Mehrabi, and E. Yang. Co-evolving agents: Learning from failures as hard negatives, 2025. URL https://arxiv.org/abs/2511.22254.
M. Kang, W.-N. Chen, D. Han, H. A. Inan, L. Wutschitz, Y. Chen, R. Sim, and S. Rajmohan. ACON: Optimizing context compression for long-horizon LLM agents. In ICML, 2026.
N. S. Keskar, B. McCann, L. R. Varshney, C. Xiong, and R. Socher. CTRL: A conditional transformer language model for controllable generation. arXiv preprint arXiv:1909.05858, 2019. URL https://arxiv.org/abs/1909.05858.
A. Kumar, V. Zhuang, R. Agarwal, Y. Su, J. D. Co-Reyes, A. Singh, K. Baumli, S. Iqbal, C. Bishop, R. Roelofs, L. M. Zhang, K. McKinney, D. Shrivastava, C. Paduraru, G. Tucker, D. Precup, F. Behbahani, and A. Faust. Training language models to self-correct via reinforcement learning. In International Conference on Learning Representations, 2025. URL https://proceedings.iclr.cc/paper_files/paper/2025/hash/871ac99fdc5282d0301934d23945ebaa-Abstract-Conference.html.
X. Lai, Z. Tian, Y. Chen, S. Yang, X. Peng, and J. Jia. Step-DPO: Step-wise preference optimization for long-chain reasoning of LLMs. arXiv preprint arXiv:2406.18629, 2024. URL https://arxiv.org/abs/2406.18629.
C. Le, J. Cheng, Q. He, R. Li, Y. Li, and X. Chen. Multi-harness reinforcement learning for coding agents: Training gains and harness dependence. arXiv preprint arXiv:2609.04518, 2026. URL https://arxiv.org/abs/2609.04518.
Z. Li, Y. Hu, and W. Wang. Encouraging good processes without the need for good answers: Reinforcement learning for LLM agent planning. In Proceedings of the 2025 Conference on Empirical Methods in Natural Language Processing: Industry Track, pages 1654–1666, Suzhou (China), Nov. 2025. Association for Computational Linguistics. doi: 10.18653/v1/2025.emnlp-industry.116. URL https://aclanthology.org/2025.emnlp-industry.116/.
J. Liu, H. Xi, S. Zhang, Y. Zeng, T. Yue, C. Wang, J. Kang, Q. Wu, and H. Wang. Who&When Pro: Can LLMs really attribute failures in AI agents? arXiv preprint arXiv:2607.09996, 2026.
S. Liu, J. Yang, B. Jiang, Y. Li, J. Guo, X. Liu, and B. Dai. Context as a tool: Context management for long-horizon SWE-agents. arXiv preprint arXiv:2512.22087, 2025.
X. Liu, H. Yu, H. Zhang, Y. Xu, X. Lei, H. Lai, Y. Gu, H. Ding, K. Men, K. Yang, S. Zhang, X. Deng, A. Zeng, Z. Du, C. Zhang, S. Shen, T. Zhang, Y. Su, H. Sun, M. Huang, Y. Dong, and J. Tang. AgentBench: Evaluating LLMs as agents. In International Conference on Learning Representations, 2024. URL https://arxiv.org/abs/2308.03688.
M. Lu, W. Sun, W. Du, Z. Ling, X. Yao, K. Liu, and J. Chen. Beyond the context window: Scaling agentic RL via end-to-end optimized context compression. In Proceedings of the 64th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 21074–21125, 2026. doi: 10.18653/v1/2026.acl-long.966. URL https://aclanthology.org/2026.acl-long.966/.
Q. Lu, L. Ding, S. Cao, X. Liu, K. Zhang, J. Zhang, and D. Tao. Runaway is ashamed, but helpful: On the early-exit behavior of large language model-based agents in embodied environments. In Findings of EMNLP, 2025.
A. Mehta and A. Datta. Plans don’t persist: Why context management is load bearing for LLM agents. arXiv preprint arXiv:2606.22953, 2026.
M. A. Merrill, A. G. Shaw, N. Carlini, et al. Terminal-Bench: Benchmarking agents on hard, realistic tasks in command line interfaces. In The Fourteenth International Conference on Learning Representations, 2026. URL https://arxiv.org/abs/2601.11868.
G. Min, L. Wu, M. Darbari, C. Chen, and L. Hong. Toward reliable context compression for long-horizon agents: An empirical study of execution instability. arXiv preprint arXiv:2608.06503, 2026.
C. Packer, S. Wooders, K. Lin, V. Fang, S. G. Patil, I. Stoica, and J. E. Gonzalez. MemGPT: Towards LLMs as operating systems. arXiv preprint arXiv:2310.08560, 2023.
Z. Pan, Q. Wu, H. Jiang, M. Xia, X. Luo, J. Zhang, Q. Lin, V. Rühle, Y. Yang, C.-Y. Lin, H. V. Zhao, L. Qiu, and D. Zhang. LLMLingua-2: Data distillation for efficient and faithful task-agnostic prompt compression. In Findings of the Association for Computational Linguistics: ACL 2024, pages 963–981, 2024. doi: 10.18653/v1/2024.findings-acl.57.
P. Putta, E. Mills, N. Garg, S. Motwani, C. Finn, D. Garg, and R. Rafailov. Agent Q: Advanced reasoning and learning for autonomous AI agents. arXiv preprint arXiv:2408.07199, 2024. URL https://arxiv.org/abs/2408.07199.
R. Rafailov, A. Sharma, E. Mitchell, C. D. Manning, S. Ermon, and C. Finn. Direct preference optimization: Your language model is secretly a reward model. In NeurIPS, 2023.
Z. Shao, P. Wang, Q. Zhu, R. Xu, J. Song, X. Bi, H. Zhang, M. Zhang, Y. K. Li, Y. Wu, and D. Guo. DeepSeekMath: Pushing the limits of mathematical reasoning in open language models. arXiv preprint arXiv:2402.03300, 2024. URL https://arxiv.org/abs/2402.03300.
W. Shi, M. Yuan, J. Wu, Q. Wang, and F. Feng. Direct multi-turn preference optimization for language agents. In Proceedings of the 2024 Conference on Empirical Methods in Natural Language Processing, pages 2312–2324, 2024. doi:10.18653/v1/2024.emnlp-main.138. URL https://aclanthology.org/2024.emnlp-main.138.
N. Shinn, F. Cassano, A. Gopinath, K. Narasimhan, and S. Yao. Reflexion: Language agents with verbal reinforcement learning. In NeurIPS, 2023.
M. Shridhar, X. Yuan, M.-A. Côté, Y. Bisk, A. Trischler, and M. Hausknecht. ALFWorld: Aligning text and embodied environments for interactive learning. In ICLR, 2021.
Y. Song, D. Yin, X. Yue, J. Huang, S. Li, and B. Y. Lin. Trial and error: Exploration-based trajectory optimization of LLM agents. In Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), 2024. URL https://aclanthology.org/2024.acl-long.409.
J. Su, R. Fang, Y. Li, X. Wang, S. Cai, P. Xie, N. Zhang, and F. Yuan. U-fold: Dynamic intent-aware context folding for user-centric agents. In Findings of the Association for Computational Linguistics: ACL 2026, pages 18043–18057, 2026. doi: 10.18653/v1/2026.findings-acl.897. URL https://aclanthology.org/2026.findings-acl.897/.
W. Sun, M. Lu, Z. Ling, K. Liu, X. Yao, Y. Yang, and J. Chen. Scaling long-horizon agent via context folding. In ICML, 2026.
J. Tang. Self-evolution for multi-turn tool-calling agents via divergence-point preference learning. arXiv preprint arXiv:2606.23112, 2026.
H. Trivedi, T. Khot, M. Hartmann, R. Manku, V. Dong, E. Li, S. Gupta, A. Sabharwal, and N. Balasubramanian. AppWorld: A controllable world of apps and people for benchmarking interactive coding agents. In Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), 2024. URL https://aclanthology.org/2024.acl-long.850.
R. Wang, P. Jansen, M.-A. Côté, and P. Ammanabrolu. ScienceWorld: Is your agent smarter than a 5th grader? In Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing, pages 11279–11298, 2022. URL https://aclanthology.org/2022.emnlp-main.775.
R. Wang, H. Li, X. Han, Y. Zhang, and T. Baldwin. Learning from failure: Integrating negative
examples when fine-tuning large language models as agents. arXiv preprint arXiv:2402.11651, 2024. URL https://arxiv.org/abs/2402.11651.
X. Wang, B. Li, Y. Song, F. F. Xu, X. Tang, M. Zhuge, J. Pan, Y. Song, B. Li, J. Singh, H. H. Tran, F. Li, R. Ma, M. Zheng, B. Qian, Y. Shao, N. Muennighoff, Y. Zhang, B. Hui, J. Lin, R. Brennan, H. Peng, H. Ji, and G. Neubig. OpenHands: An open platform for AI software developers as generalist agents. In International Conference on Learning Representations, 2025a.
Y. Wang, T. Xie, K. Shen, M. Wang, and L. Yang. RLAnything: Forge environment, policy, and reward model in completely dynamic RL system. arXiv preprint arXiv:2602.02488, 2026a.
Z. Wang, K. Wang, Q. Wang, P. Zhang, L. Li, Z. Yang, X. Jin, K. Yu, M. N. Nguyen, L. Liu, E. Gottlieb, Y. Lu, K. Cho, J. Wu, L. Fei-Fei, L. Wang, Y. Choi, and M. Li. RAGEN: Understanding self-evolution in LLM agents via multi-turn reinforcement learning. arXiv preprint arXiv:2504.20073, 2025b. URL https://arxiv.org/abs/2504.20073.
Z. Wang, H. Chen, J. Wang, and W. Wei. Memex(RL): Scaling long-horizon LLM agents via indexed experience memory. arXiv preprint arXiv:2603.04257, 2026b.
S. Welleck, I. Kulikov, S. Roller, E. Dinan, K. Cho, and J. Weston. Neural text generation with unlikelihood training. In International Conference on Learning Representations, 2020. URL https://openreview.net/forum?id=SJeYeONtvH.
X. Wu, K. Li, Y. Zhao, L. Zhang, L. Ou, H. Yin, Z. Zhang, X. Yu, D. Zhang, Y. Jiang, P. Xie, F. Huang, M. Cheng, S. Wang, H. Cheng, and J. Zhou. ReSum: Unlocking long-horizon search intelligence via context summarization. arXiv preprint arXiv:2509.13313, 2025.
W. Xiong, Y. Song, X. Zhao, W. Wu, X. Wang, K. Wang, C. Li, W. Peng, and S. Li. Watch every step! LLM agent learning via iterative step-level process refinement. In Proceedings of the 2024 Conference on Empirical Methods in Natural Language Processing, pages 1556–1572, 2024. doi:10.18653/v1/2024.emnlp-main.93. URL https://aclanthology.org/2024.emnlp-main.93.
J. Xu, X. Liu, J. Yan, D. Cai, H. Li, and J. Li. Learning to break the loop: Analyzing and mitigating repetitions for neural text generation. In Advances in Neural Information Processing Systems, 2022.
A. Yang, A. Li, B. Yang, B. Zhang, B. Hui, B. Zheng, B. Yu, et al. Qwen3 technical report. arXiv preprint arXiv:2505.09388, 2025. URL https://arxiv.org/abs/2505.09388.
J. Yang, C. E. Jimenez, A. Wettig, K. Lieret, S. Yao, K. Narasimhan, and O. Press. SWE-agent: Agent-computer interfaces enable automated software engineering. In NeurIPS, 2024a.
Z. Yang, P. Li, M. Yan, J. Zhang, F. Huang, and Y. Liu. ReAct meets ActRe: When language agents enjoy training data autonomy. arXiv preprint arXiv:2403.14589, 2024b.
S. Yao, J. Zhao, D. Yu, N. Du, I. Shafran, K. Narasimhan, and Y. Cao. ReAct: Synergizing reasoning and acting in language models. In ICLR, 2023.
S. Yeh, Y. Zhu, S. Deep, and S. Li. Tracing agentic failure from the flow of success. arXiv preprint arXiv:2607.12747, 2026.
S. Yuan, Z. Chen, Z. Xi, J. Ye, Z. Du, and J. Chen. Agent-R: Training language model agents to reflect via iterative self-training. arXiv preprint arXiv:2501.11425, 2025.
E. Zelikman, Y. Wu, J. Mu, and N. D. Goodman. STaR: Bootstrapping reasoning with reasoning. In Advances in Neural Information Processing Systems, 2022. URL https://arxiv.org/abs/2203.14465.
A. Zeng, M. Liu, R. Lu, B. Wang, X. Liu, Y. Dong, and J. Tang. AgentTuning: Enabling generalized agent abilities for LLMs. In Findings of the Association for Computational Linguistics: ACL 2024, 2024. URL https://aclanthology.org/2024.findings-acl.181/.
G. Zhang, J. Wang, J. Chen, W. Zhou, K. Wang, and S. Yan. AgenTracer: Who is inducing failure in the LLM agentic systems? arXiv preprint arXiv:2509.03312, 2025.
L. Zheng, W.-L. Chiang, Y. Sheng, S. Zhuang, Z. Wu, Y. Zhuang, Z. Lin, Z. Li, D. Li, E. P. Xing,
H. Zhang, J. E. Gonzalez, and I. Stoica. Judging LLM-as-a-judge with MT-Bench and Chatbot Arena. In Advances in Neural Information Processing Systems, Datasets and Benchmarks Track, 2023. URL https://arxiv.org/abs/2306.05685.
J. Zhou, T. Lu, S. Mishra, S. Brahma, S. Basu, Y. Luan, D. Zhou, and L. Hou. Instruction-following evaluation for large language models. arXiv preprint arXiv:2311.07911, 2023. URL https://arxiv.org/abs/2311.07911.
S. Zhou, F. F. Xu, H. Zhu, X. Zhou, R. Lo, A. Sridhar, X. Cheng, T. Ou, Y. Bisk, D. Fried, U. Alon, and G. Neubig. WebArena: A realistic web environment for building autonomous agents. In International Conference on Learning Representations, 2024. URL https://arxiv.org/abs/2307.13854.
Z. Zhou, A. Qu, Z. Wu, S. Kim, A. Prakash, D. Rus, J. Zhao, B. K. H. Low, and P. P. Liang. MEM1: Learning to synergize memory and reasoning for efficient long-horizon agents. arXiv preprint arXiv:2506.15841, 2025.
Appendix Contents
A Evaluation Details 14
B A Real Loop from CodeGym 15
C More Compression Methods and Model Sizes 15
D Setup Details 15
D.1 Gemini Runs 15
E Loop Labels 16
F How the Policy Uses Its Action Record 16
F.1 Training Suppresses the Looping Action 17
G Training Details and Additional Results 18
G.1 Training Details 18
G.2 Matched Baselines 19
G.3 More Pairs, Fewer Loops 19
G.4 How Much Cross-Domain Data to Add 19
G.5 Comparison with Agent-R-Style Splicing 20
G.6 Hyperparameters, Mining Rules, and Model Size 20
G.7 Per-Step Selectivity 20
G.8 Training Objectives on the Same Loop Signal 20
G.9 Inference-Time Controls 21
G.10 GRPO Variants 22
G.11 A Stricter Chosen Rule Does Not Help 22
G.12 Combining SFT with DPO 22
G.13 A Likelihood Anchor Brings Loops Back 22
G.14 Cross-Domain Pairs from Public Trajectories 24
G.15 General Capability Is Preserved 24
G.16 Repair Across Memory Policies 24
G.17 Other Model Families and Sizes 24
H A Formal Account of Loops and Their Repair 25
H.1 Setup and Definitions 25
H.2 Loop Ambiguity and an Activity Ceiling 25
H.3 Why Both Sides of a Pair Matter 26
I Extension Studies 26
I.1 The Policy Reacts to the Record of Its Own Executed Action . . . . . 26
I.2 Compression Amplifies Exact Repetition Most . . . . . . . . . . . 27
I.3 Random Pairs Do Not Break the Loop 27
I.4 The Loop-Breaking Action Matters 27
J Additional Analyses 28
J.1 Loops on Calls Still in Context . . . 28
J.2 The Duplicate Blocker . . . . . . 29
J.3 Gemini Models on the Same Tasks . 29
J.4 Fewer Loops Are Not Just Shorter Episodes . . . . . . . . . . . 30
A. Evaluation Details
Evaluation runs. Unless noted otherwise, every number comes from the 300 held-out CodeGym tasks under summarization at 4,096 tokens. When a number averages several evaluation runs, each run evaluates the same trained policy on the same tasks. In Table 1, the full-history agent, the compressed baseline, DeLoop, and DeLoop-Mix each average three runs, history truncation averages two, and every other row is one run. In Table 2 and Figure 8, DPO (DeLoop) and KTO average three runs, while IPO and the looping-action penalty GRPO are one run each; the KTO tokens per task come from one of its three runs. In Figure 5, the Qwen3-14B compressed baseline averages three runs and its DeLoop policy is one run; the Qwen3-32B compressed baseline averages two runs and its DeLoop policy three. In Figure 6, the summarization cells at 8,192 and 2,048 tokens and the seven memory policies are one run each. In Table 3, each cell is one run except ScienceWorld, the AppWorld DeLoop-Mix cells, and the Open-AgentRL base, which average three.
Steps and tokens per task. Steps per task count the actions the agent executes in a task. We estimate tokens per task by counting the logged trajectory with the Qwen tokenizer; the trajectory holds the task prompt, the observations, and the model's outputs, each counted once. Open-AgentRL does not record tokens, so Table 3 leaves its token cells empty.
Loop measurement. On CodeGym, the loop rate uses the structural detector of Section 3.1 (Appendix D); each environment in Table 3 uses its own native repeat detector. Figures 2 and 7 compare runs within each model's compressed setting; Appendix E gives the runs behind Figure 2.
B. A Real Loop from CodeGym
The episode below is excerpted from a training rollout of the compressed Qwen3-8B agent. The task is to count clusters of online servers on a grid:
... 13 earlier act-observe turns compressed ...
FindUnvisitedOnlineServer(start_row=3, start_col=0) → 3,0
... further act-observe turns of real work ...
FindUnvisitedOnlineServer(start_row=3, start_col=0) → 3,0
FindUnvisitedOnlineServer(start_row=3, start_col=0) → 3,0
later in the episode: MarkVisited(row=3, col=0)
The agent runs the same search three times and gets 3,0 back every time: nothing has marked that server as visited, so the search can only return the same cell. The loop sits inside an otherwise productive episode, and the action the search was waiting for, MarkVisited, appears later in the same rollout. This is the structure DeLoop mines (Section 4): the repeated search is the looping action, and MarkVisited is the loop-breaking action.
Loop-breaking actions range from tool calls that make progress to final answers. Another self-mined pair rejects a looping FindUnvisitedLand() call and chooses the agent's later Done(answer=1).
C. More Compression Methods and Model Sizes
Every compression method raises looping on Gemini 3.5 Flash-Lite. Figure 3b compares Gemini models with and without summarization. Table 5 repeats this comparison for Gemini 3.5 Flash-Lite under five compression methods. Every method raises the loop rate, from 34.0% without compression to between 47.1% and 64.4%, and every method lowers task success. The structured action trace loops most often, so an explicit record of past actions does not stop the loop on Gemini either.
The repair holds for every model we train. Table 6 gives the CodeGym results behind Figure 5, together with steps per task and a fourth model, Qwen3.5-9B. Steps per task fall at every size: from 15.00 to 4.67 on Qwen3-8B, from 15.28 to 8.18 on Qwen3-14B, and from 13.54 to 8.82 on Qwen3-32B. Qwen3.5-9B follows the same pattern: DeLoop cuts its loop rate from 54.7% to 26.0% and raises task success by 5.6 points, from 49.7% to 55.3%.
D. Setup Details
Environment and agent. CodeGym (Du et al., 2025) turns static coding problems into interactive tool-use environments. Each task exposes a function API with Observe(), task-specific actions, and Done(), and the environment server scores the agent's answer against the task's gold answer. Unless noted otherwise, the agent is Qwen3-8B with greedy decoding and a budget of 30 rounds, where a round is one model turn and a step is one executed action. Training and evaluation tasks share no task instance or code ID. Appendix A lists the evaluation runs behind each result.
Loop detector. The canonicalization of Section 3.1 normalizes each tool call for whitespace and argument order. A step is a looping action when its canonical call appeared earlier in the episode and the environment returns a byte-identical observation. Practical agent frameworks use a similar rule: the OpenHands stuck detector flags an agent when the same action returns the same observation four or more times (Wang et al., 2025a).
Compression. When the estimated history exceeds the threshold, the harness keeps the system prompt, the task, and the six most recent messages, and replaces everything in between with a summary. The same served model writes the summary at temperature zero, following an instruction that asks it to keep exact values, environment returns, and executed actions. The standard threshold is 4,096 tokens; Figures 3a and 6b also use 8,192 and 2,048 tokens and hard truncation at 4,096 tokens. Every comparison holds the model and the threshold fixed. Table 4 lists, for each context method, the share of episodes in which compression fired.
D.1. Gemini Runs
The Gemini models (Gemini Team et al., 2023) run the 300 held-out CodeGym tasks in the same harness and summarize at 1,400 tokens so that compression fires within their shorter episodes. Figure 3b compares each model's full-history run with the episodes of its summarization run in which

Figure 7: Interaction cost of looping and loop-free runs. (a) Transcript tokens and (b) steps per task for runs with a loop (red) and without one (gray), for Qwen3-8B on CodeGym and five Gemini models. Tokens use the Qwen tokenizer (Appendix A); panel (a) uses a separate scale for Qwen3-8B.
| Context method | Loop rate (%) ↓ | Success (%) ↑ | Steps/task ↓ | Tokens/task ↓ | Fired (%) |
|---|---|---|---|---|---|
| No compression (full history) | 29.0 | 31.7 | 12.23 | 24,319 | 0.0 |
| Summaries | |||||
| Standard rolling summary | 57.3 | 25.1 | 15.00 | 23,915 | 96.6 |
| Instruction-ledger summary | 50.0 | 27.0 | 12.40 | 19,535 | 95.7 |
| Claude-style compact summary | 50.3 | 26.3 | 13.67 | 20,944 | 95.0 |
| LangChain-style summary | 51.7 | 26.3 | 13.25 | 20,725 | 96.7 |
| Action-trace summary | 52.0 | 25.0 | 14.21 | 30,937 | 96.7 |
| Action-warning summary | 54.0 | 24.0 | 14.12 | 22,886 | 97.0 |
| Action-ledger summary | 62.7 | 23.3 | 15.51 | 24,509 | 96.7 |
| Memory and learned compressors | |||||
| Retrieval memory | 42.7 | 27.7 | 13.34 | 26,127 | 97.0 |
| ACON compressor | 46.3 | 29.3 | 14.84 | 20,542 | 97.7 |
| LLMLingua-2 compressor | 46.7 | 23.7 | 14.48 | 26,788 | 97.0 |
| Truncation | |||||
| Round clipping (keep 6 of 12) | 37.0 | 28.3 | 12.17 | 25,956 | 44.0 |
| History truncation | 65.3 | 18.0 | 16.05 | 34,794 | 96.7 |
Table 4: Context-management comparison. Qwen3-8B on 300 held-out CodeGym tasks. Fired: share of episodes in which compression fired. Steps and estimated tokens are per-task averages. The shaded row is the compressed baseline: summarization at 4,096 tokens.
compression fired; Figure 2 uses all 300 episodes of the summarization run.
E. Loop Labels
Loop labels in Figures 2 and 7. Both figures use the loop rate of Section 3.1: a run loops when it contains at least one looping action. Figure 2 splits each model's compressed-baseline runs by this label (Table 7): 1,500 episodes on five disjoint sets of 300 CodeGym tasks outside the evaluation set for Qwen3-8B, 400 CodeGym tasks for Qwen3-14B, and the 300 held-out tasks for the four Gemini models.
F. How the Policy Uses Its Action Record
These probes, which complement Section I.1, ask how Qwen3-8B uses the record of an action it has already run.
The record matters, its wording does not. We take 150 looping points from training-side tasks that never appear in evaluation and rebuild the context in five length-matched variants: (A) the original action–observation block; (B) a one-line



Figure 8: Training objectives on the loop signal. Qwen3-8B on CodeGym under summarization at 4,096 tokens. Task success versus loop rate, steps, and estimated tokens per task (left to right). Red square: compressed baseline; blue: DeLoop; purple: KTO, IPO, and looping-action penalty GRPO.
| Context method | Loop (%) ↓ | Success (%) ↑ |
|---|---|---|
| No compression (full history) | 34.0 | 57.0 |
| Summarization | 47.1 | 54.7 |
| Truncation | 48.7 | 46.0 |
| Claude-style compact summary | 49.0 | 56.0 |
| LangChain-style summary | 49.7 | 49.7 |
| Structured action trace | 64.4 | 46.3 |
Table 5: Compression methods on Gemini 3.5 Flash-Lite. Gemini 3.5 Flash-Lite on CodeGym. As in Figure 3b, the loop rate counts the episodes in which compression fired (all episodes without compression); task success counts all tasks.
| Model | Loop (%) ↓ | Success (%) ↑ | Steps ↓ | Tokens (k) ↓ | ||||
|---|---|---|---|---|---|---|---|---|
| Base | DeLoop | Base | DeLoop | Base | DeLoop | Base | DeLoop | |
| Qwen3-8B | 57.3 | 6.1 | 25.1 | 25.9 | 15.00 | 4.67 | 23.9 | 12.7 |
| Qwen3-14B | 42.9 | 12.3 | 45.1 | 52.3 | 15.28 | 8.18 | 13.3 | 8.6 |
| Qwen3-32B | 38.5 | 12.9 | 37.7 | 44.8 | 13.54 | 8.82 | 11.4 | 8.1 |
| Qwen3.5-9B | 54.7 | 26.0 | 49.7 | 55.3 | 19.15 | 14.95 | 8.0 | 5.8 |
Table 6: Per-model CodeGym results. CodeGym under summarization at 4,096 tokens: compressed baseline (Base) and DeLoop trained on pairs mined from the same model's rollouts. Tokens are estimated tokens per task. Shaded columns: DeLoop; green marks an improvement over the baseline.
assertion of the action and its result; (C) no record; (D) the assertion inside the summary; and (E) the returned value without saying that the agent ran the action. We sample 16 completions per point at temperature 0.7 and measure re-issue, the share of completions that repeat the looping action. For the compressed baseline, deleting the record raises re-issue from 15.3% (A) to 43.3% (C), while re- wording it keeps re-issue close to the verbatim rate (17.6% for B, 16.5% for D, 18.9% for E).
Training lowers re-issue in every condition. On the same points (Table 8), DeLoop re-issues 3.4% of the time with the verbatim record, 4.5% with the assertion, and 15.0% with the record deleted, against 15.3%, 17.6%, and 43.3% for the compressed baseline.
The deletion effect holds on an unselected sample. To avoid selecting on loops, we fix 300 decision points after compression from 253 tasks before any model call, stratified by whether the episode eventually loops. At each point, the untrained policy chooses its next action with the most recent completed action–observation record present or deleted (eight samples each). It re-issues that action 3.3% of the time with the record present and 48.8% with it deleted in this stratified sample; weighting the two strata by their population shares gives a difference of 44.3 points.
F.1. Training Suppresses the Looping Action
Two probes at 250 loop points from tasks outside all preference-training data ask what training changes (Table 9). First, we score the recorded loop-breaking action against the looping action. The untrained policy ranks the loop-breaking action higher at 49.6% of points, a coin flip; the two-source DeLoop-Mix variant (CodeGym, ALFWorld, and Open-AgentRL pairs) raises this to 69.2%. Second, we freeze each loop prefix and take one greedy action. Every trained policy re-issues the looping action less often than the untrained one
| Model | Compression | Episodes | Failure, loop (%) | Failure, no loop (%) |
|---|---|---|---|---|
| Qwen3-8B | Summ. 4,096 | 1,500 | 84.9 | 67.7 |
| Qwen3-14B | Summ. 4,096 | 400 | 70.8 | 47.7 |
| Gemini 3.5 Flash-Lite | Summ. 1,400 | 300 | 61.1 | 36.5 |
| Gemini 3.1 Flash | Summ. 1,400 | 300 | 51.3 | 23.9 |
| Gemini 3.6 Flash | Summ. 1,400 | 300 | 41.4 | 12.8 |
| Gemini 3.1 Pro | Summ. 1,400 | 300 | 47.6 | 11.7 |
Table 7: Failure rates behind Figure 2. For each model's compressed baseline on CodeGym: the compression setting, the number of episodes, and the task-failure rate of runs with and without a loop (Section 3.1).
| Policy | A: verbatim ↓ | B: assertion ↓ | C: deleted ↓ |
|---|---|---|---|
| Compressed baseline | 15.3 | 17.6 | 43.3 |
| DeLoop (ours) | 3.4 | 4.5 | 15.0 |
Table 8: Action-record probe. Re-issue rate (%) of the looping action for Qwen3-8B at 150 CodeGym looping points, with the record verbatim (A), as a one-line assertion (B), or deleted (C); 16 completions per point at temperature 0.7.
| Policy | (loop-breaking) | (looping) | Margin | Loop-breaking higher (%) |
|---|---|---|---|---|
| Compressed baseline | -3.377 | -3.514 | 0.137 | 49.6 |
| Two-source DeLoop-Mix (CodeGym, ALFWorld, Open-AgentRL pairs) | -3.979 | -5.211 | 1.232 | 69.2 |
| Policy | Looping ↓ | Loop-breaking | Done() | Other | Unparsed |
|---|---|---|---|---|---|
| Compressed baseline | 15.6 | 20.8 | 3.6 | 45.2 | 14.8 |
| DeLoop (ours) | 6.0 | 19.2 | 24.0 | 33.2 | 17.6 |
| DeLoop-Mix (ours) | 5.2 | 20.4 | 17.2 | 42.4 | 14.8 |
| Two-source DeLoop-Mix (CodeGym, ALFWorld, Open-AgentRL pairs) | 8.4 | 20.4 | 12.4 | 42.4 | 16.4 |
| Looping-action penalty GRPO | 5.6 | 18.8 | 26.0 | 32.0 | 17.6 |
Table 9: Action scores and greedy choices after training. Qwen3-8B at 250 held-out CodeGym loop points. Top: log-probabilities of the recorded loop-breaking and looping actions, their margin, and the share of points where the loop-breaking action scores higher. Bottom: one greedy action from each frozen prefix, by kind (%).
(15.6%): 6.0% for DeLoop, 5.2% for DeLoop-Mix, and 5.6% for looping-action penalty GRPO. The share that copies the recorded loop-breaking action stays between 18.8% and 20.8% for every policy, while calls to Done() rise from 3.6% to between 12.4% and 26.0%. Training thus suppresses the looping action rather than teaching one memorized recovery.
G. Training Details and Additional Results
This appendix gives the training recipe, the trained baselines of Table 1, and ablations. Unless noted otherwise, every row is Qwen3-8B on the 300 held-out CodeGym tasks under summarization at 4,096 tokens.
G.1. Training Details
Mining. We run the compressed agent on CodeGym training tasks and flag looping actions with the detector of Section 3.1, comparing canonicalized calls (whitespace and argument order normalized) and exact observations. Each looping action that the agent later breaks yields one pair: the prompt is the history just before it, the rejected action is the looping action, and the chosen action is the first later action in the same rollout that is neither a looping action nor the same call. Without the second condition, a later repeat that returns a new observation could be chosen, and both sides of the pair would be the same text.
No labels. The miner reads only actions and observations. It never reads the reward, the task status, or a gold answer, and no LLM judge takes part. Of the 8,000 CodeGym pairs, 82.6% come from runs that fail.
Hyperparameters. The Qwen3-8B DeLoop policy trains LoRA (Hu et al., 2022) adapters (, , all projection modules) from the base model with DPO for one epoch on 8,000 of the 9,403 mined pairs, with , learning rate , effective batch 16 (batch 1, 16 accumulation steps), and maximum sequence length 4,500. We chose from on a separate 128-task screening set, disjoint from the 300 evaluation tasks. Qwen3-14B and Qwen3-32B use the same mining rule and on 2,331 and 2,244 pairs mined from their own compressed CodeGym rollouts, and train for two epochs. All policies decode greedily.
Cross-domain pairs. DeLoop-Mix adds 4,635 cross-domain pairs to the 8,000 CodeGym pairs (12,635 in total) and keeps the optimizer and . Each pair again contrasts a looping action with a later loop-breaking action from the same rollout, mined with the same label-free rule: no reward, task status, gold answer, or other supervision is used. The pairs come from ALFWorld (1,712), ALFWorld tasks run in the Open-AgentRL harness (1,711), and Terminal-Bench (1,212). The ALF-World and Open-AgentRL pairs come from ALF-World training games; Table 3 evaluates both environments on the 134 unseen validation games, which share no game with the training split. A two-source variant uses the same number of cross-domain pairs, 2,511 from ALFWorld and 2,124 from the Open-AgentRL harness.
G.2. Matched Baselines
Baselines. The four offline trained baselines of Table 1 share our model, optimizer settings, and budget of 8,000 examples, and differ only in how the examples are built. Outcome DPO uses
| Method | Examples | Loop (%) | Success (%) | Steps |
|---|---|---|---|---|
| Full history | — | 29.0 | 31.7 | 12.23 |
| Compressed baseline | — | 57.3 | 25.1 | 15.00 |
| Outcome DPO | 3,910 | 49.5 | 25.8 | 12.95 |
| 8,000 | 34.7 | 25.7 | 10.99 | |
| Gold-label DPO | 3,910 | 37.5 | 26.3 | 10.23 |
| 8,000 | 22.3 | 25.7 | 8.10 | |
| SFT on solved traces | 3,910 | 44.5 | 23.7 | 11.71 |
| 8,000 | 42.7 | 21.3 | 10.61 | |
| Distillation SFT | 3,910 | 47.0 | 24.0 | 11.80 |
| 8,000 | 43.7 | 26.3 | 11.52 | |
| DeLoop (ours) | 3,910 | 18.6 | 22.2 | 7.47 |
| 8,000 | 6.1 | 25.9 | 4.67 |
Table 10: Matched baselines at two training budgets. Qwen3-8B, CodeGym, summarization at 4,096 tokens. Each offline baseline is trained on 3,910 and on 8,000 examples; the 8,000-example rows appear in Table 1.
outcome-ranked pairs (Shi et al., 2024; Song et al., 2024) whose rejected side is a random step from a failed run. SFT on solved traces imitates runs that solve the task (Gulcehre et al., 2023; Zelikman et al., 2022). Gold-label DPO also rejects looping actions but uses task outcomes to build its corpus. Distillation SFT imitates the full-history agent and, like DeLoop, uses no labels. Gold-action GRPO trains online on the same 8,000 prompts and rewards an exact match with the gold action.
More data does not close the gap. At 3,910 and at 8,000 examples, DeLoop gives the lowest loop rate (18.6% and 6.1%) and the fewest steps per task; the strongest baseline, gold-label DPO, reaches 37.5% and 22.3% (Table 10).
G.3. More Pairs, Fewer Loops
The loop rate falls as we add self-mined pairs, from 45.1% at 1k pairs to 6.1% at 8k, and steps per task fall from 11.88 to 4.67 (Table 11). The loop rate levels off after 8k pairs.
G.4. How Much Cross-Domain Data to Add
Every mixture of CodeGym and cross-domain pairs raises task success above the compressed baseline (25.1%) and DeLoop (25.9%), and keeps the loop rate at or below 24.3% up to a 50% cross-domain
| Self-mined pairs | Loop (%) ↓ | Success (%) ↑ | Steps ↓ |
|---|---|---|---|
| Compressed baseline | 57.3 | 25.1 | 15.00 |
| 1k | 45.1 | 26.4 | 11.88 |
| 2k | 34.5 | 24.7 | 9.57 |
| 3.9k | 18.6 | 22.2 | 7.47 |
| 8k (DeLoop) | 6.1 | 25.9 | 4.67 |
| 9.4k | 6.7 | 23.0 | 4.82 |
Table 11: Effect of the number of self-mined pairs. Qwen3-8B, CodeGym, summarization at 4,096 tokens; the DeLoop recipe on the number of self-mined pairs shown.
| Training data | Share | Loop (%) ↓ | Success (%) ↑ | Steps ↓ |
|---|---|---|---|---|
| Compressed baseline | — | 57.3 | 25.1 | 15.00 |
| CodeGym only (DeLoop) | 0% | 6.1 | 25.9 | 4.67 |
| + two sources | 10% | 8.3 | 27.6 | 5.55 |
| + two sources | 20% | 11.9 | 26.8 | 6.74 |
| + two sources | 37% | 19.0 | 30.9 | 8.80 |
| + three sources (DeLoop-Mix) | 37% | 10.1 | 30.3 | 5.94 |
| + two sources | 50% | 24.3 | 27.3 | 9.48 |
| Cross-domain only | 100% | 55.3 | 31.3 | 15.13 |
Table 12: Cross-domain data mixtures. Qwen3-8B, CodeGym, summarization at 4,096 tokens; DPO on the 8,000 CodeGym pairs plus cross-domain pairs at the share shown (last row: cross-domain pairs only). The highlighted rows hold the share at 37%; the three-source row is DeLoop-Mix in Table 1.
share (Table 12). A 37% share gives the highest success among the mixtures. At that share, three sources instead of two keep task success (30.3% vs. 30.9%) and lower the loop rate from 19.0% to 10.1%; this three-source mixture is DeLoop-Mix.
G.5. Comparison with Agent-R-Style Splicing
Agent-R (Yuan et al., 2025) learns from whole trajectories and task outcomes: it splices a failed path onto a reward-selected branch at the point where the two diverge. We adapt this divergence splicing to our rollouts, where it yields 1,000 training pairs, and run DeLoop on 1,000 self-mined pairs next to it. Without outcome labels, self-mined pairs lower the loop rate more (45.1% vs. 52.3%), take fewer steps per task (11.88 vs. 13.62), and keep higher task success (26.4% vs. 24.0%; Table 13).
G.6. Hyperparameters, Mining Rules, and Model Size
Hyperparameters. Changing one field of the recipe at a time, every setting lowers the loop rate below the compressed baseline's 57.3% (Table 14). The default recipe keeps the highest task success (25.9%), and gives the lowest loop rate of the values. A higher learning rate, a larger LoRA rank, or a second epoch on the 8,000 pairs lowers the loop rate further, to 0.7–1.7%, with 1.60–3.59 steps per task.
Mining rules. Changing one mining rule at a time, re-mining the same rollouts, and training on 8,000 pairs keeps the loop rate at or below 7.0%; the default rule keeps the highest task success (Table 15). The same table gives activity for the SFT control of Table 2: it shortens episodes less than the pair (11.71 rounds per task, against 5.47 for full pairs and 16.34 for the compressed baseline).
Model size. Pairs transfer across model sizes (Table 16). Qwen3-8B trained on 2,331 pairs mined from Qwen3-14B lowers its loop rate from 57.3% to 35.0% and raises task success from 25.1% to 28.7%. Qwen3-14B trained on the 8,000 Qwen3-8B pairs lowers its loop rate from 42.9% to 9.3%.
G.7. Per-Step Selectivity
Not every repeated call is wasted: re-checking a state the agent has changed returns a new observation. We split repeated calls into looping actions, which get back the same observation, and informative repeats, which get back a new one. Selectivity is the share of repeats that are informative, pooled over all scored steps.
Training removes looping actions far more than informative repeats (Table 17). DeLoop lowers looping actions from 24.9% to 2.5% of steps and informative repeats from 10.6% to 5.8%, so selectivity rises from 29.9% to 69.8%; DeLoop-Mix reaches 74.2%. The trained policies still re-check the environment, but they rarely re-issue a call whose answer they already have.
G.8. Training Objectives on the Same Loop Signal
DPO, KTO, and IPO in Table 2 and Figure 8 train Qwen3-8B on the same 8,000 self-mined CodeGym pairs; DPO uses the DeLoop recipe (Section G.1),
| Method | Budget | Labels | Loop (%) ↓ | Success (%) ↑ | Steps ↓ | Tokens/task (k) ↓ |
|---|---|---|---|---|---|---|
| Compressed baseline | — | none | 57.3 | 25.1 | 15.00 | 23.9 |
| DeLoop (ours) | 1,000 | none | 45.1 | 26.4 | 11.88 | 22.4 |
| Agent-R-style divergence splice | 1,000 | task success | 52.3 | 24.0 | 13.62 | 27.1 |
Table 13: Comparison with Agent-R-style splicing. Qwen3-8B, CodeGym, summarization at 4,096 tokens. Both trained rows use 1,000 training pairs. Labels: the supervision each method needs.
| Setting | Loop (%) ↓ | Success (%) ↑ | Steps ↓ |
|---|---|---|---|
| Compressed baseline | 57.3 | 25.1 | 15.00 |
| Default recipe (DeLoop) | 6.1 | 25.9 | 4.67 |
| DPO | |||
| 17.3 | 16.3 | 2.06 | |
| 17.7 | 23.0 | 6.88 | |
| 36.7 | 25.0 | 10.57 | |
| Learning rate | |||
| 35.3 | 23.7 | 10.33 | |
| 0.7 | 19.3 | 1.60 | |
| LoRA rank | |||
| 25.3 | 24.0 | 7.84 | |
| 1.3 | 24.0 | 3.59 | |
| Epochs and pairs | |||
| 8,000 pairs, 2 epochs | 1.7 | 25.3 | 2.85 |
| 9,403 pairs, 2 epochs | 7.0 | 20.7 | 2.80 |
| 500 pairs, 1 epoch | 52.3 | 19.7 | 14.08 |
Table 14: Training hyperparameter ablations. Qwen3-8B, CodeGym, summarization at 4,096 tokens. Each block changes one field of the default recipe.
and KTO and IPO use their published default settings. IPO (Azar et al., 2024) replaces the log-sigmoid of DPO with a squared loss that bounds the preference margin. KTO (Ethayarajh et al., 2024) drops the pairing and scores each action on its own, with loop-breaking actions as desirable and looping actions as undesirable; it still cuts the loop rate to 12.6%. Looping-action penalty GRPO uses no pairs; it penalizes every flagged step in fresh online rollouts (Section G.10). All four objectives shorten episodes: steps per task fall from 15.00 to between 4.67 (DPO) and 6.72 (IPO), and tokens per task from 23.9k to between 12.4k and 13.6k.
| Setting | Mined | Loop (%) ↓ | Success (%) ↑ | Rounds ↓ |
|---|---|---|---|---|
| Compressed baseline | — | 57.3 | 25.1 | 16.34 |
| Default (DeLoop) | 9,403 | 6.1 | 25.9 | 5.47 |
| SFT (chosen action only) | — | 37.7 | 21.3 | 11.71 |
| Mining rule (one change each) | ||||
| Random later chosen | 9,357 | 3.7 | 23.3 | 4.61 |
| Exact-string match | 9,294 | 7.0 | 22.7 | 5.02 |
| Near-identical obs. | 10,265 | 3.0 | 20.0 | 3.85 |
Table 15: Mining-rule and chosen-only ablations. Qwen3-8B, CodeGym, summarization at 4,096 tokens; 8,000 training pairs per row. “Mined”: pairs the rule yields. The variants pick a random later loop-breaking action, match actions as exact strings, or treat observations with similarity ratio ≥ 0.9 as the same. SFT trains on the loop-breaking (chosen) action alone. Rounds: agent turns per task.
| Model | Training pairs | Loop (%) ↓ | Success (%) ↑ | Rounds ↓ |
|---|---|---|---|---|
| Qwen3-8B | none | 57.3 | 25.1 | 16.34 |
| Qwen3-8B | 8,000 own | 6.1 | 25.9 | 5.47 |
| Qwen3-8B | 2,331 from 14B | 35.0 | 28.7 | 11.28 |
| Qwen3-14B | none | 42.9 | 45.1 | 15.57 |
| Qwen3-14B | 2,331 own | 12.3 | 52.3 | 8.26 |
| Qwen3-14B | 8,000 from 8B | 9.3 | 44.3 | 7.21 |
Table 16: Preference-pair transfer across model sizes. CodeGym, summarization at 4,096 tokens; DPO on pairs mined from the model's own rollouts or the other model's. Highlighted rows: DeLoop from Figure 5. Rounds: agent turns per task.
G.9. Inference-Time Controls
Table 18 lists every training-free control we ran on the compressed baseline. The exact duplicate blocker refuses to run a call that repeats an earlier one, so its loop rate counts attempted repeats. Temperature 0.7 and a token repetition
| Policy | Looping actions (% of steps) ↓ | Informative repeats (% of steps) | Selectivity (%) ↑ | Scored steps |
|---|---|---|---|---|
| Compressed baseline | 24.9 | 10.6 | 29.9 | 13,504 |
| DeLoop (ours) | 2.5 | 5.8 | 69.8 | 4,204 |
| DeLoop-Mix (ours) | 2.6 | 7.5 | 74.2 | 5,347 |
Table 17: Informative repeats and looping actions. Qwen3-8B on CodeGym under summarization at 4,096 tokens, pooled over the 300 tasks and three evaluation runs. Selectivity is the share of repeats that return new information.
penalty (Keskar et al., 2019) of 1.2 change decoding. Reflexion, stuck-stop, and stuck-nudge act when a stuck detector fires: the model critiques itself before acting, the episode ends, or the model gets a reminder.
Inference-time controls do not break the loop. Every control leaves the loop rate at 46.7% or above, against 6.1% for DeLoop. The blocker comes closest, but steps per task barely move (14.71 against 15.00) because the agent keeps proposing the blocked call. The decoding controls raise the loop rate to 63.3% and 65.7%, and the within-episode controls stay between 55.3% and 58.7%.
G.10. GRPO Variants
We train Qwen3-8B with online GRPO (Shao et al., 2024) under summarization at 4,096 tokens and vary the reward, sampling, or prompts (Table 19). Looping-action penalty GRPO penalizes every looping action; one version also mixes in prompts from other environments. Episode-level loop reward GRPO gives one sparse reward per episode, and loop-weighted SFT replaces RL with weighted imitation. Gold-action GRPO, the labeled baseline of Table 1, rewards an exact match with a gold action; its variants add partial credit and more diverse sampling. A group is informative when its rewards differ, so that it yields a gradient.
The per-step penalty is the strongest signal. It cuts the loop rate to 15.0%, and to 18.3% with 28.3% task success when prompts are mixed. A sparse episode-level reward leaves 47.3% of runs looping, and loop-weighted SFT 42.3%.
Gold-action rewards give GRPO little to learn from. With exact matching, only 2.7% of groups are informative and the loop rate stays at 52.7%. Partial credit raises informative groups to 5.3% and diverse sampling to 20.5%, and the loop rate falls with them, to 49.3% and 32.7%.
The penalty holds across context settings. Trained once under summarization at 4,096 tokens, the policy loops in 13.7% of tasks with the full history and in 11.3%, 15.0%, and 16.0% under summarization at 8,192, 4,096, and 2,048 tokens, against 29.0%, 51.0%, 57.3%, and 64.7% for the untrained agent in the same settings. Under truncation, which it never saw in training, it loops in 24.7% of tasks against 65.3%. Task success rises from 20.0% to 24.3% at 2,048 tokens and from 18.0% to 25.7% under truncation.
G.11. A Stricter Chosen Rule Does Not Help
Requiring the agent to keep receiving new observations after the loop-breaking action does not improve the pairs. At 1,726 pairs from the same rollouts, this stricter rule gives a loop rate of 41.7% and task success of 23.0%, against 38.7% and 25.0% for the standard rule at the same number of pairs.
G.12. Combining SFT with DPO
When SFT and DPO are staged, DPO must come last (Table 20). In a separate screening evaluation, SFT on solved CodeGym traces after DPO reopens loops (6.5% to 29.7%), and a final DPO stage closes them again (2.3%).
G.13. A Likelihood Anchor Brings Loops Back
Plain DPO suits self-mined pairs better than DPO with a likelihood anchor. RPO adds a negative log-likelihood term on the chosen action to the DPO loss, with weight . On the same 8,000 self-mined CodeGym pairs, the anchor raises the loop rate of Qwen3-8B from 6.1% to 27.0%, steps per task from 4.67 to 7.90, and tokens per task from 12.7k to 24.8k, and task success goes from
| Control | Loop (%) ↓ | Success (%) ↑ | Steps ↓ | Tokens/task (k) ↓ |
|---|---|---|---|---|
| Compressed baseline | 57.3 | 25.1 | 15.00 | 23.9 |
| Blocking and decoding | ||||
| Exact duplicate blocker | 46.7 | 25.3 | 14.71 | 24.9 |
| Temperature 0.7 | 63.3 | 29.3 | 16.99 | 18.5 |
| Repetition penalty 1.2 | 65.7 | 29.0 | 16.85 | 14.7 |
| Within-episode controls (act when a stuck detector fires) | ||||
| Reflexion on stuck | 55.3 | 24.3 | 14.62 | 24.1 |
| Stuck-stop (end the episode) | 57.3 | 21.7 | 13.08 | 21.6 |
| Stuck-nudge (remind the model) | 58.7 | 23.7 | 14.85 | 23.2 |
| Ours | ||||
| DeLoop (ours) | 6.1 | 25.9 | 4.67 | 12.7 |
Table 18: Inference-time controls. Qwen3-8B on CodeGym under summarization at 4,096 tokens. Every control runs on the compressed baseline without training.
| Method | Reward or signal | Loop (%) ↓ | Success (%) ↑ | Steps ↓ | Tokens/ task (k) ↓ | Informative groups (%) |
|---|---|---|---|---|---|---|
| Compressed baseline | none | 57.3 | 25.1 | 15.00 | 23.9 | — |
| Loop signal (no labels) | ||||||
| Looping-action penalty GRPO | per-step penalty | 15.0 | 24.7 | 6.39 | 13.4 | — |
| + mixed prompts | per-step penalty | 18.3 | 28.3 | 7.08 | 13.8 | — |
| Episode-level loop reward GRPO | one reward per episode | 47.3 | 25.3 | 13.53 | 21.8 | — |
| Loop-weighted SFT | weighted imitation | 42.3 | 19.0 | 9.92 | 28.6 | — |
| Gold-action reward (labels) | ||||||
| Gold-action GRPO | exact match | 52.7 | 25.0 | 14.23 | 21.0 | 2.7 |
| + partial credit | partial match | 49.3 | 27.0 | 13.22 | 22.2 | 5.3 |
| + partial credit, diverse sampling | partial match | 32.7 | 27.3 | 11.08 | 20.2 | 20.5 |
Table 19: GRPO reward and sampling variants. Qwen3-8B on CodeGym under summarization at 4,096 tokens. Informative groups are the share of sampled groups whose rewards differ.
| Training sequence | SFT demonstrations | Loop (%) ↓ | Success (%) ↑ | Steps ↓ |
|---|---|---|---|---|
| Main evaluation | ||||
| DPO only (DeLoop) | — | 6.1 | 25.9 | 4.67 |
| Screening evaluation: objective order | ||||
| DPO only | — | 6.5 | 16.4 | 4.74 |
| DPO → SFT | solved CodeGym traces | 29.7 | 12.5 | 10.79 |
| DPO → SFT → DPO | solved CodeGym traces | 2.3 | 21.1 | 4.62 |
Table 20: Sequential SFT and DPO training. Qwen3-8B on CodeGym under summarization at 4,096 tokens. The lower block is a separate screening evaluation, compared only within the block.
25.9% to 21.3%. The anchor raises loops on other training data as well: from 19.0% to 42.1% on a two-source mixed corpus, and from 34.7% to 37.3% on the outcome-ranked pairs of Table 1.
The training logs show what the anchor changes. Plain DPO pushes the looping action far down and lowers the loop-breaking action only slightly; with the anchor, the loop-breaking action rises toward imitation. Appendix H.3 derives this trade-off from the gradient of the objective and gives the log-probabilities. Imitation alone leaves many loops in place (37.7% for the chosen-only row of Table 2).
| Cross-domain source | CodeGym | ALFWorld | ||||
|---|---|---|---|---|---|---|
| Loop (%) ↓ | Success (%) ↑ | Steps ↓ | Loop (%) ↓ | Success (%) ↑ | ||
| Compressed baseline | 57.3 | 25.1 | 15.00 | 55.2 | 37.3 | |
| SWE-agent | 17.3 | 26.0 | 7.18 | 35.8 | 36.6 | |
| OpenHands | 21.0 | 28.7 | 7.88 | 33.6 | 37.3 | |
| WebArena | 22.7 | 28.3 | 8.00 | 46.3 | 41.8 | |
Table 21: Cross-domain pairs from public trajectories. Qwen3-8B on CodeGym and ALFWorld with summarization. Each shaded row trains on the self-mined CodeGym pairs plus cross-domain pairs from the named public source.
G.14. Cross-Domain Pairs from Public Trajectories
The gain from cross-domain pairs does not depend on one trajectory collection. We keep the self-mined CodeGym pairs and the size of the cross-domain portion fixed, build the cross-domain pairs from a public collection instead, either SWE-agent (Yang et al., 2024a) or OpenHands (Wang et al., 2025a) coding trajectories or WebArena (Zhou et al., 2024) browser trajectories, and train Qwen3-8B with the same DPO recipe (Table 21). With every source, the CodeGym loop rate falls from 57.3% to between 17.3% and 22.7%, task success rises from 25.1% to between 26.0% and 28.7%, and steps per task fall from 15.00 to 8.00 or fewer. The same policies also loop less on ALFWorld (33.6% to 46.3%, against 55.2%), and the WebArena pairs raise ALFWorld task success from 37.3% to 41.8%.
G.15. General Capability Is Preserved
Training on loops leaves general ability intact. We evaluate the untrained Qwen3-8B, DeLoop, and DeLoop-Mix on three non-agentic benchmarks outside agent tasks (Table 22): the 182 LiveCodeBench (Jain et al., 2025) problems released from 2025 onward, with the official prompts and greedy pass@1; MT-Bench (Zheng et al., 2023), with 80 two-turn questions, the official category temperatures, and one LLM judge for all three models; and IFEval (Zhou et al., 2023), with 541 prompts and the official strict-prompt scorer. On LiveCodeBench, the base model solves 53 problems, DeLoop 52, and DeLoop-Mix 54. DeLoop scores higher than the base model on MT-Bench (4.463 against 4.225) and on IFEval (83.5% against 82.8%), and DeLoop-Mix reaches 83.4% on IFEval.
| Policy | LiveCodeBench | MT-Bench | IFEval (%) |
|---|---|---|---|
| Qwen3-8B (untrained) | 53/182 | 4.225 | 82.8 |
| DeLoop (ours) | 52/182 | 4.463 | 83.5 |
| DeLoop-Mix (ours) | 54/182 | 4.213 | 83.4 |
Table 22: General capability evaluation. Qwen3-8B on LiveCodeBench (problems solved of 182, greedy pass@1), MT-Bench (mean judge score, 1–10), and IFEval (strict-prompt accuracy).
G.16. Repair Across Memory Policies
Table 23 gives the numbers behind Figure 6c. The seven memory policies are retrieval memory, an instruction ledger, Claude-style compaction, a LangChain summary, and summaries augmented with an action trace, an action warning, or an action ledger. Under every one of them, DeLoop-Mix lowers the loop rate, from 42.7%–62.7% to 6.3%–20.7%, along with steps per task, and it cuts tokens per task by more than half. Task success rises under four of the seven, by up to 5.7 points with the action ledger.
G.17. Other Model Families and Sizes
Llama-3.1-8B. Llama (Grattafiori et al., 2024) loops natively. With the full history, Llama-3.1-8B loops in 44.0% of CodeGym episodes, and under summarization at 4,096 tokens it loops in 43.7% (Table 24). We train it with DPO on pairs mined from its own rollouts with the same rule. The trained policy loops in 2.0% of episodes, against 43.7% for the compressed baseline, and steps per task fall from 17.51 to 5.72, while task success goes from 17.8% to 19.4%.
Qwen3-14B and Qwen3-32B. Compression raises looping at both sizes and costs task success. Summarization at 4,096 tokens raises the loop rate from 33.3% to 42.9% on Qwen3-14B and from 26.0% to 38.5% on Qwen3-32B, and lowers task success by 8.9 and 9.0 points. We train each model on pairs mined from its own compressed rollouts with the recipe of Section G.1. Both policies loop less than the agent with the full history (12.3% and 12.9%), and they win back most of the success that compression costs: 7.2 of the 8.9 points at 14B and 7.1 of the 9.0 points at 32B (Table 24).
DeLoop at 32B also helps when the history is not compressed. Evaluated with the full history, it lowers the loop rate from 25.0% to 11.7% and raises
| Memory policy | Policy | Loop (%) ↓ | Success (%) ↑ | Steps ↓ | Tokens/task (k) ↓ |
|---|---|---|---|---|---|
| Retrieval memory | Compressed baseline | 42.7 | 27.7 | 13.34 | 26.1 |
| DeLoop-Mix (ours) | 10.7 | 31.0 | 6.93 | 11.8 | |
| Instruction ledger | Compressed baseline | 50.0 | 27.0 | 12.40 | 19.5 |
| DeLoop-Mix (ours) | 7.0 | 25.3 | 5.16 | 8.8 | |
| Claude-style compact | Compressed baseline | 50.3 | 26.3 | 13.67 | 20.9 |
| DeLoop-Mix (ours) | 6.3 | 25.7 | 5.84 | 9.3 | |
| LangChain summary | Compressed baseline | 51.7 | 26.3 | 13.25 | 20.7 |
| DeLoop-Mix (ours) | 8.7 | 26.3 | 6.01 | 9.9 | |
| Action trace | Compressed baseline | 52.0 | 25.0 | 14.21 | 30.9 |
| DeLoop-Mix (ours) | 20.7 | 27.7 | 7.67 | 14.2 | |
| Action warning | Compressed baseline | 54.0 | 24.0 | 14.12 | 22.9 |
| DeLoop-Mix (ours) | 9.3 | 27.3 | 5.99 | 9.7 | |
| Action ledger | Compressed baseline | 62.7 | 23.3 | 15.51 | 24.5 |
| DeLoop-Mix (ours) | 11.3 | 29.0 | 5.60 | 9.6 |
Table 23: DeLoop-Mix across memory policies. Qwen3-8B on CodeGym. Each memory policy has a compressed-baseline row and a DeLoop-Mix row (shaded) on the same tasks. Tokens are estimated tokens per task (Appendix A).
| Model | Setting | Loop (%) ↓ | Success (%) ↑ | Steps ↓ |
|---|---|---|---|---|
| Llama-3.1-8B | Full history | 44.0 | 17.5 | 17.41 |
| Compressed baseline | 43.7 | 17.8 | 17.51 | |
| DeLoop (ours) | 2.0 | 19.4 | 5.72 | |
| Qwen3-14B | Full history | 33.3 | 54.0 | 14.36 |
| Compressed baseline | 42.9 | 45.1 | 15.28 | |
| DeLoop (ours) | 12.3 | 52.3 | 8.18 | |
| Qwen3-32B | Full history | 26.0 | 46.7 | 12.97 |
| Compressed baseline | 38.5 | 37.7 | 13.54 | |
| DeLoop (ours) | 12.9 | 44.8 | 8.82 |
Table 24: Other model families and sizes. CodeGym. For each model: the agent with the full history, the compressed baseline (summarization at 4,096 tokens), and DeLoop, trained on that model's self-mined pairs and evaluated under summarization at 4,096 tokens.
task success from 46.3% to 51.3%, compared with a base-model run matched to this test.
H. A Formal Account of Loops and Their Repair
H.1. Setup and Definitions
A trajectory alternates tool calls and observations, and is its prefix before step ; and are as in Section 3.1. For a candidate action , is the value would take if the agent issued at step . A context manager maps the history to the context the policy acts on, , with for the full history. A self-mined pair (Section 4.1) has prompt , the context the agent saw before the looping action , and chosen action .
H.2. Loop Ambiguity and an Activity Ceiling
Compression can map two histories that disagree on whether an action was already taken to the same context, which then cannot tell a new action from a looping one. Let work count the actions other than Observe and Done issued after the first compression event, and define the loop ambiguity
over these actions. We start after compression because the first action of an episode never loops.
Proposition 1 (activity ceiling). A policy that cannot tell repeats from new actions loops less only by acting less: if and the policy issues at most looping actions per task in expectation, then .
Proof. Each work action issued after compression loops with conditional probability at least , so .
Driving loops close to zero thus requires a lower or less activity, so we report steps and tokens per task next to the loop rates of Table 1. Reading the action record lowers , yet the compressed baseline loops even with summaries that record its past actions (Section 3.3); training the policy targets this gap.
H.3. Why Both Sides of a Pair Matter
The DPO gradient on a self-mined pair raises the loop-breaking action and lowers the looping action under the same context. With and , the loss of Section 4.2 is and
Up to weights, the first term alone is chosen-only SFT, which does not break the loop (Table 2); the pair does.
A likelihood anchor dilutes the contrast. Adding with raises the coefficient on the first term to and leaves the second at . The contrast share
is 1 for DPO and falls toward 0, the chosen-only limit, as grows, so the loop rate should rise with .
On the 8,000 self-mined CodeGym pairs, the loop rate follows this order: 6.1% for DPO (DeLoop), 27.0% with the anchor at (Section G.13), and 37.7% for chosen-only SFT. In the training logs of two runs that differ only in the anchor ( ), DPO lowers the loop-breaking action's mean log-probability only slightly, from -44.0 to -51.1, and drives the looping action's from -40.6 to -132.6. With the anchor, the loop-breaking action rises from -43.6 to -3.1 and the looping action rises with it, from -40.4 to -28.7, so the implied reward margin ends at 1.44 instead of 4.25.
I. Extension Studies
We report four further studies on Qwen3-8B in CodeGym: what the policy conditions on (Section I.1), why the detector uses exact repetition (Section I.2), a random-pair control (Section I.3), and what the chosen action adds (Section I.4).
I. 1. The Policy Reacts to the Record of Its Own Executed Action
We probe the moments at which the agent loops. Unlike the training-side points of Section F, these come from the compressed baseline's runs on the 300 evaluation tasks: 150 looping points, one per task at its first loop. We add 80 retry points, at which an earlier call to the same action returned a different observation, so calling it again is reasonable. At each point we rebuild the context from the raw history in six conditions: not yet executed (the history before the action was first run); proposed only (the same history plus a note that the action was proposed but not run, padded to the same length); proposed + observation (the note also states what the action would return); just executed (the history ending right after the action's first run); record present (the full history up to the decision point); and record deleted (the same history with the record of the earlier run removed). We sample eight completions per condition at temperature 0.7 and report the re-issue rate, the share of completions whose next action is the probed action (Table 25).
Untrained policy. Planning an action does not stop the agent from issuing it: with the action only proposed, the untrained Qwen3-8B re-issues it in 73.9% of completions, the same as before the action was ever run (73.7%). Stating the observation lowers re-issue to 29.0%, and the record of the agent's own execution lowers it further, to 16.5%. Deleting that record brings re-issue back to 53.3%. The effect is strongest right after the run (4.9%) and fades as history accumulates.
The record also separates loops from reasonable retries. At retry points it lowers re-issue only from 68.4% to 51.7%, while a stated observation alone lowers it to 20.6% and blocks retries that are worth making. The executed record, together with what it returned, is what tells the policy whether an action is finished or worth checking again.
Trained policies. Both trained policies still tell loops from retries. With the record present, DeLoop re-issues a looping action in 8.3% of completions and DeLoop-Mix in 6.8%, against 36.1% and 38.0% at retry points. Deleting the record raises re-issue at looping points only to 20.7% and 23.9%, against 53.3% for the untrained model, while retries return to 54.2% and 56.1%. The
| Context condition | Looping points (n=150) | Retry points (n=80) | ||||
|---|---|---|---|---|---|---|
| Base | DeLoop | DeLoop-Mix | Base | DeLoop | DeLoop-Mix | |
| Not yet executed | 73.7 | 61.4 | 57.3 | 68.4 | 63.3 | 62.2 |
| Proposed only | 73.9 | 41.0 | 24.4 | 66.7 | 31.9 | 25.2 |
| Proposed + observation | 29.0 | 2.5 | 2.2 | 20.6 | 4.7 | 7.2 |
| Just executed | 4.9 | 1.9 | 1.9 | 5.6 | 5.6 | 6.9 |
| Record present | 16.5 | 8.3 | 6.8 | 51.7 | 36.1 | 38.0 |
| Record deleted | 53.3 | 20.7 | 23.9 | 64.8 | 54.2 | 56.1 |
Table 25: Action re-issue under different context conditions. Re-issue rate (%) of the probed action under each context condition, at looping points and at retry points in Qwen3-8B CodeGym runs. Base is the untrained Qwen3-8B.
trained policies thus avoid most loops even when the record of the earlier run is missing.
I.2. Compression Amplifies Exact Repetition Most
Our detector flags only exact repeats with an identical observation. We measure four broader signatures on the same CodeGym runs: near-duplicate calls (same tool, different arguments, with an identical observation or a small argument edit), argument thrash (A–B–A argument alternation within three calls), redundant observe (an action whose observation is already in context, word for word, from a different action), and productive repeats (the same action with a different observation). Table 26 gives the results.
Exact loops are the signature that compression amplifies most. Under summarization, their share of actions rises , from 6.6% to 24.8%, while every broader signature changes by to . Near-duplicate and redundant-observe calls are common, in 77.9% and 56.3% of compressed tasks, but they behave like ordinary re-probing: with the full history they are more frequent in solved tasks (failure odds ratios 0.68 and 0.69). We therefore define the loop as exact repetition. Training lowers every signature per action, so the trained policies do not trade exact loops for near-duplicates: near-duplicate calls fall from 34.3% of actions to 19.0% under DeLoop and 23.7% under DeLoop-Mix.
I.3. Random Pairs Do Not Break the Loop
Does the loop label matter, or would any preference pair from the agent's own rollouts do? We build a random-pair corpus from the compressed baseline's CodeGym rollouts: each pair keeps a prompt and takes as its chosen and rejected actions two random later actions from the same rollout. We train on 877 random pairs and on random subsets of our 8,000 self-mined pairs with the same DPO recipe, match the number of optimizer updates to our main recipe (about 500), and evaluate on a separate 128-task held-out CodeGym set (Table 27).
At the same budget of about 500 optimizer updates, 1,003 self-mined pairs bring the loop rate to 9.4% and task success to 23.4%, while random pairs leave the loop rate at 69.5%, above the compressed baseline's 66.1%, and task success at 11.7%. Training longer on random pairs makes looping worse, from 54.8% after one epoch to 69.5% after nine. With 4,012 self-mined pairs the loop rate reaches 5.5%, the same as DeLoop trained on all 8,000. What breaks the loop is the loop label, not preference training on the agent's own rollouts.
I.4. The Loop-Breaking Action Matters
Each self-mined pair prefers the loop-breaking action to the looping action. To test what the chosen side adds, we keep the same 8,000 prompts, the same rejected actions, and the same recipe, and replace the chosen action in two ways: with a random action from the prompt's own history, or with the chosen action of a random other pair, a plausible action from the wrong state (Table 28).
The loop-breaking action carries more than “anything but the looping action”. With a random chosen action, the loop rate stays at 41.9% (random action from the history) and 36.1% (chosen action of another pair), against 5.7% with the loop-breaking action. Together with Table 2, this shows that both sides of each pair carry the signal.
| Signature | Tasks (%) | Per action (%) | Ratio (×) | Trained, per action (%) | Failure OR | |||
|---|---|---|---|---|---|---|---|---|
| Full | Comp. | Full | Comp. | DeLoop | DeLoop-Mix | |||
| Exact loop (our detector) | 28.6 | 57.0 | 6.6 | 24.8 | 3.77 | 2.3 | 2.5 | 1.62 |
| Near-duplicate | 75.7 | 77.9 | 46.7 | 34.3 | 0.73 | 19.0 | 23.7 | 0.68 |
| Argument thrash | 3.3 | 3.4 | 0.4 | 0.3 | 0.92 | 0.1 | 0.2 | 3.10 |
| Redundant observe | 52.3 | 56.3 | 21.1 | 22.5 | 1.07 | 6.7 | 7.7 | 0.69 |
| Productive repeat | 30.0 | 39.2 | 8.9 | 10.7 | 1.21 | 5.9 | 7.6 | 2.00 |
Table 26: Repetition signatures under compression. Qwen3-8B on the 300 CodeGym evaluation tasks. Tasks: share of tasks with at least one event; per action: share of actions that are events, with the full history (Full) and under summarization at 4,096 tokens (Comp.); ratio: Comp./Full per action. The DeLoop and DeLoop-Mix columns are under summarization. Failure OR: odds ratio of task failure for tasks with the signature, with the full history. Rates are recomputed from the logged trajectories of three evaluation runs, and the exact-loop task shares differ slightly from the run averages in Table 1.
| Training data | Pairs | Updates | Loop (%) ↓ | Success (%) ↑ | Steps ↓ |
|---|---|---|---|---|---|
| Compressed baseline | — | — | 66.1 | 11.5 | 19.12 |
| Random pairs | 877×1 | ≈55 | 54.8 | 11.9 | 13.26 |
| Random pairs | 877×9 | ≈495 | 69.5 | 11.7 | 16.17 |
| Self-mined pairs | 1,003×8 | ≈504 | 9.4 | 23.4 | 5.82 |
| Self-mined pairs | 4,012×2 | ≈502 | 5.5 | 20.3 | 4.95 |
| Self-mined pairs (DeLoop) | 8,000×1 | ≈500 | 5.5 | 15.6 | 4.80 |
Table 27: Random-pair control. Qwen3-8B on another 128-task held-out CodeGym set under summarization at 4,096 tokens (Following setting from Kang et al. (2026)). Each row trains with the same DPO recipe; Pairs gives pairs × epochs and Updates the number of optimizer updates. The compressed baseline is pooled over three evaluation runs.
| Chosen action | Loop (%) ↓ | Steps ↓ |
|---|---|---|
| Compressed baseline (no training) | 57.0 | 14.91 |
| Loop-breaking action (DeLoop) | 5.7 | 4.59 |
| Random action from the same history | 41.9 | 8.17 |
| Chosen action of another pair | 36.1 | 8.99 |
Table 28: Chosen-action controls. Qwen3-8B on the 300 CodeGym evaluation tasks under summarization at 4,096 tokens. All trained rows use the same prompts, rejected actions, and DPO recipe and differ only in the chosen action. Rows are recomputed from the logged trajectories of three evaluation runs and differ slightly from the run averages in Table 1.
J. Additional Analyses
This section reports four further analyses of the runs behind Table 1 and Figure 3. None of them needs new rollouts.
J.1. Loops on Calls Still in Context
Our loop rate compares each call with every earlier call in the run. Under compression, some of those earlier calls are no longer in the agent's context word for word, because the harness has replaced them with a summary. We therefore also count a loop only when the earlier call and its observation are still in the context the agent sees. We rebuild this context at every step from the compression events in the logs (Section D).
DeLoop removes loops whether or not the earlier call is still in context (Table 29). Counting only repeats of calls still in context, DeLoop lowers the loop rate of Qwen3-8B on CodeGym from 25.2% to 3.2%. For repeats of calls that had been sum-
| Policy | Loop rate | In context | Summarized |
|---|---|---|---|
| Compressed baseline | 57.3 | 25.2 | 32.1 |
| DeLoop | 6.1 | 3.2 | 2.9 |
| DeLoop-Mix | 10.1 | 4.3 | 5.8 |
| Full history | 29.0 | 29.0 |
Table 29: Loops by availability of the earlier record. Loop rate (%) of Qwen3-8B on CodeGym under summarization at 4,096 tokens, averaged over three runs; the full-history agent uses no compression. A run counts under In context if it repeats a call that is still in its context, and under Summarized if every call it repeats had been summarized.
| Policy | Repeat proposals | Loop (%) | Steps | Success (%) | |
|---|---|---|---|---|---|
| Tasks (%) | Per task | ||||
| Compressed baseline | 69.8 | 5.29 | 57.3 | 15.00 | 25.1 |
| Duplicate blocker | 71.3 | 4.77 | 5.7 | 14.71 | 25.3 |
| DeLoop | 13.6 | 0.38 | 6.1 | 4.67 | 25.9 |
| DeLoop + blocker | 13.7 | 0.25 | 1.3 | 4.84 | 27.7 |
Table 30: Proposed repeats and executed loops with a duplicate blocker. Qwen3-8B on CodeGym under summarization at 4,096 tokens; three runs for the compressed baseline and DeLoop, one run for each blocker row. Repeat proposals: tasks in which the agent proposes a call it has already run, and such proposals per task. Loop: loops among the calls that run (Section 3.1).
marized, it lowers the rate from 32.1% to 2.9%.
The split also shows where compression adds loops. The compressed agent repeats a call that is still in its context in 25.2% of runs, close to the 29.0% loop rate of the full-history agent. The added loops come from calls that the harness has summarized, even though the summarization prompt asks the model to keep executed actions and their results (Section D).
J.2. The Duplicate Blocker
The exact duplicate blocker refuses to run a call that repeats an earlier one and returns the earlier result with a warning instead (Section G.9). Its loop rate in Table 18, 46.7%, counts these refused calls, since they never run. Counting only the calls that run, as for the other rows, its loop rate is 5.7%. Neither number shows what the agent does, so we also count how often it proposes a call it has already run (Table 30).
The blocker does not change what the agent proposes. With the blocker, Qwen3-8B proposes an already executed call in 71.3% of tasks, close to the 69.8% without it, and steps and success barely move. The agent still generates every refused call in full, so the blocker saves no model compute: it uses 24.9k tokens per task, against 23.9k without it and 12.7k for DeLoop (Table 18). DeLoop lowers repeat proposals to 13.6% of tasks and cuts steps per task from 15.00 to 4.67.
| Model | Same tasks | All tasks | ||||
|---|---|---|---|---|---|---|
| Tasks | None | Summ. | None | Summ. | ||
| Gemini 3.5 Flash-Lite | 191 | 40.8 | 47.1 | 34.0 | 36.0 | |
| Gemini 3.1 Flash | 226 | 46.5 | 65.5 | 40.0 | 52.7 | |
| Gemini 3.1 Pro | 139 | 33.1 | 61.9 | 21.3 | 34.3 | |
Table 31: Gemini loop rates on matched task sets. Loop rate (%) on CodeGym without compression (None) and with summarization at 1,400 tokens (Summ.). Same tasks: the tasks on which compression fired in the summarization run. One run per model and setting.
The two methods are complementary. The blocker stops the few repeats that DeLoop still proposes, and DeLoop removes most of the calls that the blocker would refuse only after they are generated. With the blocker on, DeLoop runs a repeated call in 1.3% of tasks, uses 12.8k tokens per task, and solves 27.7% of them in a single run.
J.3. Gemini Models on the Same Tasks
Figure 3b compares each Gemini model's full-history run with the episodes of its summarization run in which compression fired. Compression fires only in longer episodes, and longer episodes loop more often even without compression. We therefore also compare the two runs on the same tasks, the ones on which compression fired (Table 31).
Compression raises the loop rate of every model on the same tasks. Gemini 3.1 Pro loops in 61.9% of these tasks with compression and in 33.1% without it, 1.9× as often (2.9× in Figure 3b). The ratio is 1.4× for Gemini 3.1 Flash and 1.2× for Gemini 3.5 Flash-Lite. Comparing against full-history episodes long enough for compression to fire gives similar ratios (1.8×, 1.4×, and 1.1×). Over all 300 tasks, including short episodes in which compression never fires, the ratios are 1.6×, 1.3×, and 1.1×.
| Policy | Step index | |||
|---|---|---|---|---|
| 0–4 | 5–9 | 10–14 | 15–19 | |
| Compressed baseline | 4.1 | 22.3 | 32.8 | 42.8 |
| DeLoop | 0.8 | 4.1 | 7.0 | 25.7 |
| DeLoop-Mix | 1.8 | 3.6 | 4.5 | 7.3 |
| Full history | 2.3 | 6.8 | 11.3 | 13.9 |
Table 32: Loop hazard by step index. Loop hazard (%): the share of steps that are looping actions among the steps an episode reaches, by step index. Qwen3-8B on CodeGym under summarization at 4,096 tokens (full history: no compression), pooled over three runs per policy.
J.4. Fewer Loops Are Not Just Shorter Episodes
DeLoop shortens episodes from 15.00 to 4.67 steps (Table 1), and a shorter episode has fewer chances to loop. We therefore measure looping in two ways that do not depend on episode length.
First, we compute the loop hazard: among the steps that episodes reach at a given step index, the share that are looping actions (Table 32). DeLoop lowers it at every step index, from 22.3% to 4.1% at steps 5–9 and from 32.8% to 7.0% at steps 10–14. Second, we compare episodes of similar length. Among episodes of 6–10 steps, the loop rate falls from 33.2% to 13.1%, and among episodes of 11–20 steps from 69.1% to 29.2%.
DeLoop also answers earlier without losing accuracy on those tasks. It answers within four steps on average on 164 of the 300 tasks. On these tasks it solves 30.1% of runs in 2.7 steps, and the compressed baseline solves the same 30.1% in 13.0 steps (paired difference +0.0 points, 95% bootstrap interval over tasks [-6.3, +6.1]). The result is similar with a cutoff of three to six steps.