Introduction

The philosophy of DSH (DeepSeek Harness) is “everything is a plugin,” but when building agents, most extensions add capabilities to the Agent, while few people manage the execution rhythm. When running long tasks with DeepSeek V4 Flash combined with reasoningEffort: max, two typical anomalies appear:

  1. Thinking then stopping: After the model outputs complete reasoning, it ends the turn normally without body content, without tool calls, and the task remains hanging—manifested as “doing nothing.”
  2. Infinite reasoning loop: Reasoning enters repetitive idling, continuing for several minutes without stopping. Actual testing shows a single step full save to disk can reach 1.32 million characters—manifested as “running endlessly.”

The common response is manual monitoring: manually stop when idling, manually prompt when stalled, which is time-consuming and unstable for long tasks. dsh-run-guard fills in both ends at the plugin layer. Below are introductions of its positioning, mechanism, installation configuration, and precautions.

What is it

dsh-run-guard is a DeepSeek Harness plugin, positioned as an Agent runtime rhythm guardian, maintained by Dis2017, MIT license (© 2026 Dis2017). In one sentence: guard (brake) intercepts infinite reasoning loops, continue (gas) prevents premature stopping without working.

The brake and gas share a set of state perception and do not interfere with each other: turns interrupted by guard end with an error, and continue only triggers when completed, preventing false triggers; conversely, if the new turn pushed by continue falls into a loop again, guard will intercept immediately.

Core Functions

guard (brake): Intercept infinite reasoning loops

  • Listens to the llm/stream stream, performs sliding window repetition rate detection, and sets hard limits as a double safety mechanism.
  • Infinite loops are interrupted within 1~2 seconds, rather than idling for minutes.
  • Automatically retries after interruption, defaulting to 2 times per turn (configurable); stops only if still failing, and provides a Chinese error message.

recovery (recovery): Automatic retry for upstream transient failures

Transient upstream failures like PI_AI_ERROR will be automatically retried even if they are not in the default llm-retry set; the error code whitelist is extensible and shares the per-turn retry limit with guard.

continue (gas): Prevent premature stopping

Automatically continues running after the turn ends normally, working in two scenarios:

  • Has unfinished todo: Injects current state to guide continuation; consecutive continuations without output have a count limit (continue.maxAutoFollowups, default 3).
  • No todo but model thinks then stops (only reasoning at the end, no body, no tool calls): Injects a short prompt to continue, with no limit.

pause_work: Manual pause anytime

The model can call the pause_work tool to pause actively; once marked, neither guard nor continue will automatically continue.

Extension Points and Settings Page

The plugin hooks into the host via four extension points: llm/stream (waterfall), session/event, systemPrompt.context, tools.register. It also provides a settings page (Settings → Run guard), allowing editing of all configuration items, which takes effect after saving to disk and restarting.

Installation and Enablement

Install using the GitHub release version:

dsh plugin --profile web add "github:Dis2017/dsh-run-guard#v0.1.16"

The #v0.1.16 in the command corresponds to the repository’s release tag; just replace it with a new tag when upgrading. After execution, do verification first, then regular usage:

  1. Restart GUI.
  2. Open Settings → Plugins → Plugin list, and confirm dsh-run-guard is Mounted / Enabled.
  3. Open Settings → Run guard, and check or modify configuration.

After the above steps, the plugin enters an active state: infinite loops will be interrupted within 1~2 seconds and automatically retried; after “thinking then stopping,” you will automatically receive a continuation prompt.

Typical Usage

Development Mode

When debugging, there’s no need to repeatedly build and publish. Mount lib/index.js with an absolute path in ~/.dsh/profiles/web/cordis.patch.yml, and code changes take effect immediately:

# ~/.dsh/profiles/web/cordis.patch.yml
- insert:
    - id: run-guard
      name: /绝对/路径/dsh-run-guard/lib/index.js?v=1

Testing and Upgrading

pnpm install
pnpm test

There are a total of 54 unit/integration tests. After the repository is tagged with a new version, execute dsh plugin --profile web add ... again, or remove then add, to complete the upgrade.

Main Configuration Items

Config Item Default Value Description
enabled true Global switch
guard.enabled true Infinite loop interception switch
guard.windowChars 2000 Sliding window size (characters)
guard.substrLen 32 Substring length for repetition detection
guard.repeatRatio 0.7 Window repetition ratio threshold
guard.checkEvery 50 Check every N blocks (frequency reduction)
guard.maxBlocks 10000 Hard limit: single call reasoning block count limit
guard.maxChars 500000 Hard limit: single call reasoning character count limit
guard.maxGuardRetries 2 Max automatic retries per turn after interruption
guard.autoRetryErrors ["PI_AI_ERROR"] Error code whitelist for extra automatic retry
continue.enabled true Auto-continue switch
continue.maxAutoFollowups 3 Max consecutive no-output continuations in todo scenarios

All the above configuration items can be edited on the settings page, taking effect after saving to disk and restarting.

Applicable Scenarios and Notes

Suitable for DSH users running long tasks with DeepSeek V4 Flash and reasoningEffort: max, who have encountered “thinking then stopping” or infinite reasoning loops; if you want these anomalies to be automatically handled at the plugin layer instead of relying on manual monitoring, this plugin is worth trying.

A few points to note before use:

  1. Permissions and Review: The plugin runs with the permissions of the current dsh process; you should check the source code and license (MIT) before installing.
  2. Dependency Requirements: The plugin’s @deepseek-ai/* dependencies must be placed in peerDependencies (provided as a singleton by the host); placing them in dependencies will create a second copy at the top level of the profile, resulting in the error Cannot read properties of undefined (reading 'prepare') at runtime. If you encounter this error, move the dependencies back to peerDependencies, clean up the top-level copy of the profile, and restart.
  3. Historical Sessions: Historical sessions where infinite reasoning has been saved to disk (single step can reach 1.32 million characters) may freeze when opened; data needs to be cleaned up or archived; the plugin only guarantees that no new ones will be produced afterwards.
  4. Continuation Limits: For todo scenarios, consecutive continuations without output have a default limit of 3 times; for no-todo “thinking then stopping” continuations, there is no limit; after the model calls pause_work, neither path will continue.

Conclusion

dsh-run-guard manages the brake and gas simultaneously with a set of state perception: guard ensures the Agent won’t work infinitely, continue ensures it won’t stop working; for long tasks, it is a small yet practical safety net.

  • Community Plugin Directory Page: https://www.skillhub.cn/plugins/Dis2017/dsh-run-guard (Independent site, no official affiliation with DeepSeek / Huanfang)
  • GitHub Repository: https://github.com/Dis2017/dsh-run-guard