viego-qiin/dsh-loop-detector
Dead-loop / repetition detector for DeepSeek Harness agents — hard-interrupts text loops and same-topic search retries that soft reminders miss.
Project Overview项目介绍
dsh-loop-detector is a repetition-detection plugin for DeepSeek Harness (dsh). It monitors the assistant stream in real time, catching text-level loops (period scan, 64-char n-gram, 512-char large anchor) and intent-level loops in web_search queries (keyword topic set, <25% novel tokens twice). On hit, it calls agent.steer() for guided retry or agent.cancel() to hard-abort the turn. Use it when local or quantized models ignore soft reminders and get stuck repeating output or re-searching the same topic. Note: detection is heuristic and per-session only; tune minLen and thresholds for your model.
dsh-loop-detector 是 DeepSeek Harness(dsh)的死循环与重复检测插件。它实时监测助手流,识别文本级重复(周期扫描、n-gram、512 字符大锚点)和 web_search 工具调用意图级重复(基于关键词主题集),命中后通过 agent.steer() 引导或 agent.cancel() 强制中断。适用于本地量化或推理模型在长输出或连续搜索时陷入同义循环而内置提醒无效的场景。注意:检测为启发式且仅在单会话内生效,需按模型调优 minLen 与阈值。
请帮我了解并安装插件:【dsh-loop-detector】【https://github.com/viego-qiin/dsh-loop-detector】
Send this message to DSH in your current session. CLI install commands may not be accurate across systems — DSH will figure it out for you.把上面这条消息直接发给当前会话里的 DSH,让它帮你了解并安装。安装命令不一定准确,发给 DSH 更稳。
Or use CLI install (for developers)或使用命令行安装(适合开发者)
CLI Install命令行安装
dsh plugin --profile web add dsh-loop-detector
把 viego-qiin/dsh-loop-detector 加入你的 DSH 配置(web profile)即可启用。
READMEREADME
dsh-loop-detector
Dead-loop / repetition detector plugin for DeepSeek Harness (dsh).
Local LLMs (especially quantized / RL-tuned reasoning models) sometimes get stuck:
repeating the same sentence forever, or re-running web_search with reworded queries
for the same topic without gaining any new information. This plugin watches the
agent's stream in real time, detects both kinds of loops, and interrupts them
hard — not a soft reminder the model can ignore.
中文文档见 README.zh.md.
Features
- Text-level repetition detection — watches
assistant/chunk(text-delta+ optionalreasoning-delta) with three layered detectors:- Period scan: tail repeats with a fixed period (8–256 chars)
- n-gram: a 64-char block seen ≥3 times in the recent window
- Large-scale anchor: a 512-char tail block reappearing earlier (catches whole-paragraph repetition, e.g. a model re-planning the same answer twice)
- Tool-call intent-level repetition detection — watches
tools/executeforweb_search: extracts query keywords, keeps a "topic set" (union of the last 3 queries), and if a new query brings <25% novel tokens twice in a row, it judges the model is re-searching the same topic with different wording (intent-level loop, invisible to plain string matching). - Hard interrupt: on hit,
agent.steer()injects a guidance message (auto retry, configurable); when retries are exhausted,agent.cancel()forcibly aborts the turn. Counters reset onturn/end.
Why hard interrupt? dsh's built-in repeat-tool-reminder only reminds the model.
We observed local models (e.g. Qwen/Ornith 35B MoE with thinking off) ignore the
reminder and keep looping — that's what this plugin exists for.
Quick start
Prereqs: a running dsh profile (see deepseek-harness docs).
Option A (recommended): install from npm (published to npm registry)
dsh plugin --profile web add dsh-loop-detector
dsh web # restart to activate
Option B: install from a local copy
cp -r dsh-loop-detector $env:USERPROFILE\.dsh\profiles\web\node_modules\dsh-loop-detector
Then, in both cases, mount it via your profile's permanent patch layer
($env:USERPROFILE\.dsh\profiles\web\cordis.patch.yml):
- insert:
- id: loop-detector
name: 'dsh-loop-detector'
config:
minLen: 512 # only check output >= 512 chars (avoid short-text false positives)
maxRetries: 1 # auto-retry 1x via steer; cancel when exhausted
checkReasoning: true # also check reasoning-delta (thinking content)
Restart and verify:
dsh web
You should see the plugin loaded; when a loop is caught, the log shows:
[loop-detector] session xxx 检测到死循环(1/1): large-scale repeat: ...;steer 引导重试
[loop-detector] session xxx 连续 2 次搜索同一主题(无新信息): "...";steer 引导停止搜索
A ready-to-use cordis.patch.yml example is included in this repo.
Configuration
| Field | Default | Meaning |
|---|---|---|
minLen |
512 |
Start text detection only after this many characters (avoid false positives on short replies) |
maxRetries |
1 |
Times to auto-retry via steer before hard cancel |
checkReasoning |
true |
Also scan reasoning (thinking) content for repetition |
How the detectors work
Text-level (detectRepetition)
1) period scan tail 4 periods identical, period T in [8..256] -> loop
2) n-gram 64-char block seen >= 3x in last 2048 chars -> loop
3) large anchor 512-char tail block reappears earlier, extends >=512 -> loop
Tool-call intent-level
topic set = union of keywords of the last 3 web_search queries
new query -> novel ratio = (# tokens not in topic set) / total tokens
novel ratio < 25% twice in a row -> intent-level repetition -> steer/cancel
Verified against real cases: a Qwen3.5-9B stuck on an 82-char sentence (period=132 caught), a 2120-char duplicated planning block caught, and an 11-query same-topic search streak caught at query #8 (no false positive on the first 7 queries that each introduced new dimensions).
Scope & limitations
- Intent-level detection currently targets
web_search; other tools can be added by extending theexec.namefilter. - The detectors are heuristic — tune
minLen/ thresholds for your model. - Detection is per-session and resets on
turn/end(no cross-turn carryover).
License
MIT — see LICENSE.
GanyuanRan/Aegis
shengsheng90/DSH-taskboard
pengyue-polaron/deepseek-harness-genui
Jayden-X-L/forkprobe
BeforeWave/dsh-with-chatgpt
sluminositys/dsh-nested-followups
Meredith2328/dsh-sticky-note
cloader/dsh-taskboard