Preface¶
In long-context scenarios, some models (especially deepseek v4.1 flash) can easily enter a “thinking degradation” state. While generating thinking content, they may repeatedly loop over short sentences. This “singing” behavior can consume a large number of tokens at high speed without producing useful information. In addition, even when a tool call is clearly required, the model may emit redundant short sentences before moving into another line of thought. This causes the context to expand rapidly, and users often only notice it while the thinking process is being displayed.
What Is This¶
dsh-repeat-guard is a model inference plugin maintained by xiaozhuyuqing. It detects fragmented repetition in the model’s thinking process, intercepts whitelisted short phrases and interrupts the output, then forces the model to proceed directly to the next step and restore the normal agent-loop.
Core Capabilities¶
This plugin provides the following capabilities:
- Fragment detection: Detects fragmented repetition in the model’s thinking process.
- Whitelist interception: Intercepts whitelisted short phrases and interrupts output.
- Forced execution: After truncation, displays a prompt and forces the model to move directly to the next step without outputting confirmations or pleasantries.
- Loop recovery: Injects a prompt to restore the agent-loop.
- Incremental checking: Checks
reasoning-deltachunk by chunk.
Installation and Version Requirements¶
Install the plugin by running the following command:
dsh plugin --profile web add dsh-repeat-guard
Version compatibility must be considered. The plugin requires DSH 0.1.7 or later.
* From 0.1.7 onward: The host validates the plugin’s peer declaration before loading. The configuration form now uses an entry Config model, so older syntax no longer works.
* 0.1.0-rc.8 to 0.1.6: Install 0.1.5.
The host interfaces used by this plugin have not changed in 0.2.0, so the peer range no longer has an upper limit starting from 0.2.2.
Typical Usage and Behavior¶
When the model outputs a looping sentence (such as Let me do it.) or fragmented repetition (such as 好。做。开始。做。), the output is truncated.
After truncation, the following prompt is displayed:
你上一段思考退化成了碎片复读(反复输出'好。'一类的空话),已被系统截断。
请直接继续执行下一步,不要再输出任何确认语、寒暄或空话。
The model then continues directly to the next step without continuing the ineffective repetition.
Configuration and Notes¶
View the configuration in Settings → Repetition Interrupt. Changes take effect after saving; no restart is required.
The main configuration items include:
- Cumulative interception count: Records the number of interruptions and provides a reset button.
- Intercept phrases: The whitelist that triggers interruption. Punctuation must be included.
- Consecutive hit count: The threshold for consecutive hits. With the default configuration, the branching thinking process after even a single short phrase may also be intercepted.
- Inline repetition detection: When enabled, detects repetitions packed within the same line. This option is intended for models such as qwen 35B; this issue does not occur with deepseek.
- Resume instruction: The prompt pushed to the model after truncation.
- Collapsed line summary: User-visible concise information for the injected segment.
Note: Truncation events may be frequent. This is the cost of restoring the agent-loop.