Introduction¶
When building agents with DeepSeek Harness (DSH), the model can sometimes enter a “reasoning degradation” state: it keeps generating reasoning-delta events without making any tool calls, or even only outputs low-entropy repeated short phrases (such as Good. Execute. Good.). The built-in guard/ family in DSH (such as guard/timeout-policy and guard/repeat-tool-reminder) mainly monitors tool calls, so it cannot capture this “zero-tool, pure reasoning” loop. As a result, a turn can never settle. The interface shows “thinking,” but the task is actually stuck and can only be aborted manually.
What Is It¶
mrweicodes/dsh-loop-guard is a thinking-loop guard plugin for DSH. When it detects that the model has fallen into a degraded loop that produces no results, it automatically cuts off the current call from inside the llm/stream waterfall and injects a corrective prompt, allowing the task to continue without manual intervention.
- Maintainer: MrWeiCodes
- License: MIT
- Core value: Resolves the “think only, no action” dead loop without interrupting the session flow.
Core Features¶
- Five-layer detection mechanism: Covers pure-reasoning idle spinning, repetition of the previous step’s material, visible-output cyclic loops, visible-output phrase reordering, and phrase reordering inside reasoning.
- In-stream cutoff: Does not rely on a post-call decision; it detects and truncates directly inside the stream, handling “turns that never end.”
- Task continuity: Cutoff affects only the current call; the turn ends with a normal completion (
completed), the session remains alive, tool call results are retained, and subsequent tasks can continue directly. - Low false-positive rate: In testing, zero false positives occurred among 119 productive calls; in a scan of 735 sessions, 12 were misjudged (blocked by the concentration guardrail).
- Precise criteria: Uses exact-cycle and cross-call repetition as decision evidence, rather than duration or simple ratios.
- Behavior restraint: By default, it does not automatically retry, preventing a degraded model from being fed back into the loop; the injected prompt only asks to “continue completing the task” and does not guide it to finish immediately.
- Offline analyzer: Provides
tools/analyze-session.mjs, which can replay and analyze historical sessions using the runtime detector. - Observability: On cutoff, it writes a warn log and displays the injected prompt in the trajectory view.
Installation¶
This plugin depends on DSH’s llm/stream waterfall feature and requires DSH 0.1.2-rc.1 or later.
Install command:
dsh plugin --profile web add @mrweicodes/dsh-loop-guard
Note: There is a same-named package dsh-loop-guard (without scope) on npm. It is unrelated to this plugin. Use @mrweicodes/dsh-loop-guard.
Usage¶
The plugin works out of the box and can block common reasoning degradation loops without extra configuration. By default, it automatically interrupts pure-reasoning idle spinning and spam-like repeated visible output.
If you want it to automatically continue after a cutoff, enable resumeAfterBreak in the configuration:
- id: loop-guard
config:
resumeAfterBreak: true
Considerations¶
- Use automatic resumption cautiously: By default, after a cutoff the task remains in an
idlestate and waits for user confirmation. WhenresumeAfterBreakis enabled, it automatically enters the next turn. Because the cutoff happens before the model acts independently, it is recommended to enable this option for unattended long-running tasks, but pay attention to the content of the corrective prompt after cutoff. - DSH version requirement: You must use a DSH version that supports
llm/stream.
Conclusion¶
For DSH workflows that require long-running execution and high reasoning effort, dsh-loop-guard is an effective solution to “thinking deadlock.” By intervening inside the stream, it ensures task continuity; combined with a low false-positive rate and offline analysis tools, it can significantly improve the stability of agent execution.
- Plugin page: https://www.skillhub.cn/plugins/MrWeiCodes/dsh-loop-guard
- GitHub repository: https://github.com/MrWeiCodes/dsh-loop-guard