dsh-degeneration-guard: Thinking segment repetition detection and auto-resume

Preface

When running agents in DeepSeek Harness (DSH), models sometimes spin their wheels in the “deep thinking” segment: confirmation phrases and short sentences appear alternately, neither advancing the task nor doing anything but bloating the context. A common workaround is a whitelist plus a consecutive hit count. However, a low threshold unfairly flags normal confirmations, while a high threshold fails to block non-contiguous fragmented repetitions like “Okay. Do. Start. Do.”

dsh-degeneration-guard is a community-maintained DSH plugin that focuses solely on the reasoning-delta (the thinking segment). It uses a sliding window for generic repetition detection and, upon a hit, truncates the generation, optionally automatically pushing the next step to the model. The following section introduces its positioning, criteria, installation, and configuration.

What is this

The plugin detects repetition in the thinking segment during streaming output, truncates the current generation, and continues execution via the agent mechanism when “Auto Continue” is enabled. A collapsed notice remains in the chat, and the client may display a one-time popup. Main text and tool calls are passed through as-is and are not subject to repetition judgment.

Why not use a whitelist

The README compares this to the whitelist approach: hits are only counted if an entire line exactly matches a fixed short phrase in the list, and they require N consecutive hits. If the threshold is set to 1, normal confirmations are easily false-flagged; if set to 2 or higher, the consecutive count resets to zero whenever a word not in the list (e.g., Do., Start.) appears in the repetition string, making triggers nearly impossible. Real degeneration is often composed of alternating fragments, so this plugin switches to a sliding window count without consulting a word list.

Core Functions and Criteria

Monitoring Scope

Monitors only reasoning-delta. Explicitly excluded from judgment: empty lines, lines inside code fences (``` / ~~~), and decorative lines composed purely of numbers or punctuation (e.g., 1., ---, ===).

Line Repetition (Always Enabled)

Counts the occurrences of entire lines within the most recent sliding window. The window size is max(9, threshold × 3) lines; if the same entire line appears within the window reaching the “Repetition Count Threshold,” it is judged as degeneration. Because it looks at the window rather than requiring “consecutive equality,” alternating repetitions can also be caught.

In-line Repetition (Optional, Default Disabled)

Detects cases where a single line consists of repeated identical units, such as Okay. Okay. Okay.. When disabled, it only recognizes whole-line repetitions across newlines (independent paragraphs).

Behavior After Interception

  1. The triggering delta is allowed through as usual, followed by a block-end to close the thinking block and a finish(stop). To the agent-loop, this is equivalent to a normal completion.
  2. In agent/turn-stopping, it calls agent.steer(...) to inject the “Interception Prompt,” allowing the current turn to continue on its own (requires Auto Continue to be enabled).
  3. The cumulative interception count is incremented and written back to the config; if a hit occurs in the same stream segment, it ends immediately to prevent repeated truncation within a single turn.

README Example (Chat prompt after thinking segment is truncated):

[Deep Thinking]
  First check server status and crash logs.
  Key: look at latest logs and crash-reports.
  Execute.            ← Hit
  Okay.
  Do.
  Start.
  Do.              ← This line appears three times

[Repetition Interruption] Truncated · 3rd time · Auto-continued

(The summary text in the chat can be customized in settings; it defaults to placeholders like {count}.)

Installation and Activation

Requires DSH / dsh-agent 0.1.7 or higher (0.2.x is also fine). Node engine requirement is >=20 (see package.json).

Plugin Market: Search for dsh-degeneration-guard in the Harness “Plugin Market” for one-click installation.

Command Line (The desktop version usually does not have dsh in PATH, so use npx):

npx -y @deepseek-ai/dsh@latest plugin --profile desktop add dsh-degeneration-guard

Fill in your profile name for --profile. The default for the desktop version is desktop (if unsure, check the directory name under ~/.dsh/profiles/). If the CLI launched by npx is inconsistent with the desktop version causing profile incompatibility, you can switch to the Plugin Market for installation.

Once installed, configure it in Settings → Repetition Interruption.

Settings

Item Default Description
Cumulative Intercepts 0 Number of interceptions since the last reset. Persistently saved and not reset to zero when the plugin loads.
Repetition Count Threshold 3 How many times the same sentence must appear in the window to be judged as repetition; 2 is most sensitive, 3 is the most stable.
In-line Repetition Detection Off When off, only detects independent paragraphs (whole-line repetition across newlines).
Auto Continue On Automatically pushes the next step to the model after interruption, no manual continuation needed.
Interception Prompt See below The segment pushed to the model. Supports {count} / {line}.
Summary Prompt Repetition interrupted ({count}th time) · Auto-continued The text for the collapsed prompt in the chat. Visible only to the user.

Default Interception Prompt:

[Repetition Intercepted]
Your previous thinking segment showed reasoning degeneration, and the system has truncated it.
Please directly continue executing the next step. Do not output any confirmations, pleasantries, or empty words.

{count} represents the cumulative number of interceptions, and {line} is the line that triggered the interception. Both can be inserted into the prompt and summary.

Relationship with dsh-repeat-guard

The two have overlapping functionality; do not enable them simultaneously: running both will cause double interception, and the old plugin resets the count to zero on every load. The README recommends installing only this plugin.

Use Cases and Notes

Suitable for: Long-running agent tasks, models that frequently output meaningless repetitive short sentences in the thinking segment, and DSH users who want to minimize manual clicks on “Continue”.

Notes:

  • The plugin runs under the permissions of the current dsh process. Please review the source repository and the MIT license before installation.
  • The community catalog SkillHub is an independent site and has no official affiliation with DeepSeek / High-Flyer; the plugin is maintained by a community author. Stars and versions are subject to the repository and catalog page.
  • For sensitive tasks, you can adjust the “Repetition Count Threshold” to 3, or disable “In-line Repetition” first to observe false positives. If interruptions are still frequent, fine-tune the threshold and prompt.

Conclusion

dsh-degeneration-guard uses a sliding window to perform generic repetition detection in the thinking segment, optionally auto-steers to continue after interruption, and allows modifying thresholds, in-line detection, and prompt text in the settings. For installation or issues, refer to the community catalog page and GitHub:

  • Catalog Page: https://www.skillhub.cn/plugins/bluemika111/dsh-degeneration-guard
  • Repository: https://github.com/bluemika111/dsh-degeneration-guard
羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye