Manuscript Offprint

arXiv:2610.24715

When Do Repetition Loops Lock? Truncation Sampling, Bounded Penalties, and a Blind Spot in DRY

Yichuan Chen, Xin Wang

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

Abstract

Language models sometimes repeat verbatim until the generation limit. We study the exit rather than the entrance: given that a span has already been repeated n times, when is escape still possible? Along the loop the context is deterministic, so loop survival under any sampler can be computed exactly from one forward pass. Pure sampling leaves a positive escape probability at every step; top-p with threshold π>1/2\pi > 1/2 locks a position exactly when the continuation probability reaches π\pi. A bounded penalty can leave a position locked; a penalty that outgrows the model's preference for the loop over unseen tokens guarantees escape under top-p. The same analysis predicts a blind spot in the widely deployed DRY sampler: its sequence breakers cap the penalty at λbg−1−a\lambda b^{g-1-a} for loops whose longest breaker-free run has g tokens. On eleven open models, 66% of locked units with g = 6 stay locked under DRY and 1% with g = 8. In free generation with llama.cpp, all 109 loops that survive DRY have g≤7g \leq 7. We propose DRY-C, which adds a term that grows exponentially with the number of verbatim recurrences, up to its look-back window. With it, none of 720 structured-output generations looped to the length limit, and task completion stayed close to DRY's.

1 Introduction

Open-weight models can repeat a line until the token budget is exhausted, including inside reasoning, JSON and tool calls. The phenomenon is old (Holtzman et al., 2020), and its onset has been studied from several angles: the self-reinforcing rise of repetition probability (Xu et al., 2022), properties of the transition matrix (Fu et al., 2021), training data (Li et al., 2023), and, most recently, learning errors in reasoning models (Pipis et al., 2025).

This paper asks the complementary question. Suppose a loop has started. Why can the model not get out, and which decoding-time interventions can in principle get it out?

Our starting observation is that, conditioned on staying in a loop, the context is a deterministic sequence. Every sampler, including history-dependent penalties, therefore assigns a deterministic probability to “continue the loop” at each step, and the probability that a loop survives m more repetitions is a product of such numbers (Proposition 1). Teacher forcing supplies the logits without sampling loop trajectories.

Truncation can remove the exit. Under pure sampling every step has a positive escape probability. Under top-p with the usual threshold π>1/2\pi > 1/2, a position is locked (the loop token is the only candidate) exactly when its raw probability q satisfies q≥πq \geq \pi (Theorem 1). Measured reinforcement curves cross this threshold within a few repetitions. In our finite-horizon tests, 80%-100% of sampled units are locked through the last ten repetitions under top-p 0.9, compared with none under pure sampling; the units include corpus sentences and hand-written structured spans.

Penalty growth determines the available guarantee. For an additive logit penalty dd on the loop token, locking persists whenever \logit(q)−d≥\logit(π)\logit(q) - d \geq \logit(\pi) (Theorem 2). A bounded penalty only raises the threshold at which locking sets in. Escape is guaranteed under top-pp once the penalty outgrows ln⁡(q/r∘)\ln(q/r^\circ), where r∘r^\circ is the raw mass of tokens not yet in the context and therefore unpenalized (Corollary 2). A full-context frequency penalty grows fast enough as long as r∘r^\circ stays bounded below; presence penalties and windowed frequency penalties come with no such guarantee.

DRY has a blind spot, and it can be closed. DRY (Weidmann, 2024; Weidmann et al., 2026b) penalizes a token exponentially in the length of the verbatim match it would extend, and is widely used in local inference. To protect formatting, matches may not cross sequence breakers (newline, colon, quote, asterisk). We show that for a loop whose longest breaker-free run has g tokens, the penalty on the loop token is at most λbg−1−a\lambda b^{g-1-a} (Proposition 4): on such loops DRY is a bounded penalty. The prediction is borne out in a dose-response experiment, in the unmodified llama.cpp sampler, and in free generation, where every one of the 109 loops that appear with DRY enabled has g≤7g \leq 7. We then add a count term that penalizes how many times the same continuation has already occurred, prove that the resulting sampler, DRY-C, penalizes every loop exponentially, breakers or not, up to its look-back window (Proposition 5), and show that it eliminates run-to-the-limit loops in two model families.

This matters most for structured output: under default settings our prose prompts loop in 0%–7% of generations and structured prompts in 16%–21%, and breakers are densest there.

References (39)