dsh-output-loop-guard: Intercepting model self-repetition degradation loop in streaming output

Preface

When running agents in DeepSeek Harness (DSH), the model occasionally gets stuck decoding the “same short text” repeatedly. In the reasoning channel, it keeps repeating “Okay. → (execution) → Okay. → Write. → …” indefinitely, without issuing a tool call. The official @deepseek-ai/dsh-repeat-tool-reminder only monitors consecutive duplicate tool calls (same tool, same parameters, 3/5/8 consecutive times) and is powerless against text loops in the reasoning channel; automatic compaction also does not always trigger in time. The result is that output rolls up increasingly longer, polluting session logs, and manually clicking stop often becomes the only way out.

Below, we introduce the community plugin dsh-output-loop-guard (maintainer ADistanceThereIs): it listens to real-time agent/assistant-stream frames, determines whether a degenerate loop has occurred based on text structure, aborts the runaway turn, and injects a corrective notice to wake the agent to continue work.

What is this

dsh-output-loop-guard is a bundle plugin for DSH, positioned as an “output self-repetition watchdog”: it detects degenerate loops in reasoning or visible text, aborts the current generation turn, and injects a corrective explanation to the agent, without requiring a manual stop or a user inputting “continue”.

  • Requires DSH >= 0.2.0-rc.2, ESM packaged, with zero runtime dependencies.
  • Classified as admin-security in the SkillHub community catalog.
  • See the GitHub repository for source code and documentation; current release version 0.1.0 (MIT).

Differences from repeat-tool-reminder

Capability repeat-tool-reminder output-loop-guard
Observation target Duplicate tool calls The streaming text itself
Reasoning channel loops Invisible Detectable
Flooding output without tool calls Does not trigger Can abort and steer

In the motivating session documented in the README, the model repeated approximately 112,109 characters, 50,196 streaming shards, and decoded for about 126 seconds with zero tool calls—repeat-tool-reminder could not intervene; in playback calibration of this corpus, this plugin recorded detections for this pattern (see “Calibration Data” below).

Core Functionality: How it detects and how it handles

Sliding window and four signals

It maintains a sliding window of 1,200 characters on the streaming output by default, checking once every new 64 characters. The four rules are as follows:

Signal Rule Summary Main Coverage
repeated-block Shortest period block (≥2 newlines, ≥2 distinct non-whitespace characters) repeated ≥6 times Multi-line short-period loops
dominant-gram An n-gram occupies ≥55% of the window, appears ≥24 times, and spans ≥2 lines Ragged tail but repetition is already dominant
repeated-line Single line consecutive repetition: reasoning channel ≥40, visible text ≥60 (singleLineTextMinRepeats, set to 0 to disable) Single line idling or line-level flooding in answers
flat-tic Non-whitespace short gram occupies ≥25% of window, appears ≥48 times, reasoning channel only Stuttering-style repetition without newlines (e.g., “Okay. Okay. Okay.”)

There are two design points deliberately tightened to avoid false positives: it only recognizes the shortest period multi-line block (to avoid judging normal lists as loops); and it treats the channel differently—visible text has a higher threshold for single lines, and indented blocks, ====/---- separator lines, and blank line runs do not trigger it.

Actions after triggering

  1. Calls agent.cancel({ kind: 'hook', reason: 'output-loop-guard: …' }) to abort the ongoing generation and record it as an interruption, preventing further growth of the degenerate text.
  2. Calls agent.steer(<notice>); since generation is aborted, steer is upgraded to a new turn, driving the agent to correct according to the notice (stop repeating, issue the next action, or end).
  3. If triggered more than maxTripsPerTurn times within the same turn, it will not automatically continue, but only inject a notice to prevent a bad model from infinitely spinning.

Installation and Activation

The plugin is installed as a DSH bundle: the loader reads dsh.bundle.patch in package.json, and cordis.patch.yml inserts the output-loop-guard line. Choose one of the following methods (replace <profile> with your profile name; Method A requires replacing <commit> with a specific commit):

# A. Install from git host, pinned to a specific commit (git must be on the PATH of the DSH process)
dsh plugin --profile <profile> add "github:ADistanceThereIs/dsh-output-loop-guard#<commit>"

# B. Install from Release tarball (no git needed)
#    Download dsh-output-loop-guard-0.1.0.tgz from the Releases page first, then execute:
dsh plugin --profile <profile> add ./dsh-output-loop-guard-0.1.0.tgz

# C. Install directly from Release asset URL (requires Node to trust system CA)
dsh plugin --profile <profile> add \
  https://github.com/ADistanceThereIs/dsh-output-loop-guard/releases/download/v0.1.0/dsh-output-loop-guard-0.1.0.tgz

All three methods append the package to dsh.profile.bundles and merge the bundle’s patch layer. A restart of DSH is required after modifying the bundle so that the corresponding line takes effect.

Uninstallation:

dsh plugin --profile <profile> remove dsh-output-loop-guard

Configuration

Override the line in the profile’s cordis.patch.yml (the patch replaces the entire config section, so all retained items must be written back):

- id: output-loop-guard
  name: dsh-output-loop-guard
  config:
    dryRun: false                 # true = only detect and log, do not cancel
    autoContinue: true            # Use corrective notice to wake agent
    maxTripsPerTurn: 2            # Auto-continue budget per turn
    windowChars: 1200
    checkEveryChars: 64
    minPeriodRepeats: 6
    singleLineMinRepeats: 40
    singleLineTextMinRepeats: 60  # Visible text single line threshold, 0 = disabled
    useDominantGram: true
    dominantGramCoverage: 0.55
    dominantGramMinCount: 24
    useFlatTic: true
    ticMinCount: 48
    ticMinCoverage: 0.25
    verbose: false

If you want to observe hits in your local session before officially aborting, you can set dryRun: true first.

Typical Usage and Verification Strategy

  1. Install the bundle and restart DSH, confirming that the output-loop-guard line appears in cordis.patch.yml.
  2. Run several real tasks with dryRun: true before going to production to see if there are reasonable detections in the logs.
  3. After turning off dryRun, when the model enters a structured self-repetition loop, the session should show a turn/end where reason.kind is hook, reason.reason contains output-loop-guard, and a user-directed notification with the source output-loop-guard appears.

An end-to-end example log snippet provided in the README (the task was designed to repeat two lines 300 times):

{"type":"turn/end","data":{"turn":1,"reason":{"kind":"aborted","reason":{"kind":"hook","reason":"output-loop-guard: repeated output (repeated-block)"}}}}
{"type":"assistant/message","interrupted":true}
{"type":"user/message","source":{"kind":"output-loop-guard","form":"notice"}}

The intent is: stop the runaway output, rather than abandon the task—in the example, the agent subsequently wrote the same content into a file instead of continuing to flood the screen with repetition.

Running npm test in the repository runs 21 self-contained regression tests (not dependent on corpus files), covering behaviors such as real degeneracies being aborted, healthy long documents being unaffected, normal output like lists/code blocks/tables not triggering false positives, dryRun not canceling, and disabled plugins not mounting.

Calibration Data and Limitations

The author published corpus playback results (27 real sessions / 1,783 assistant steps) in the README: 24 detections, 0 false positives; every loop in the step of the motivating session was hit; the 112,109-character runaway was truncated at approximately 2,944 characters (2.6%), and most other loops triggered within 1,152–7,808 characters.

Please note the following when using:

  • Visible text requires ≥60 consecutive identical lines to trigger a single-line repetition; legitimate fixtures and lists might be protected. If not needed, set singleLineTextMinRepeats: 0.
  • Detection is based on structural features like period and density; semantic “near duplicates” might slip past repeated-block, but dominant-gram / flat-tic can often compensate.
  • The plugin runs with the permissions of the current DSH process; please review the source code and the MIT license yourself before installation; the community catalog SkillHub plugin page and GitHub are independent sources of information, and have no official affiliation with DeepSeek / High-Flyer.

Conclusion

The DSH ecosystem emphasizes “everything is a plugin”; when duplicate tool call reminders cannot cover reasoning channel flooding, dsh-output-loop-guard uses four structural signals on streaming text to automatically cancel and steer, replacing “manual stop” with a configurable watchdog. For further information on classification and entry details, open the SkillHub catalog page; for installation and configuration details, refer to the GitHub README.

羽毛球分组比赛记分
小程序二维码

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

Xiaoye