Skip to main content
T

dsh-loop-recover

terry2010/dsh-loop-recover

Loop guard for DeepSeek Harness: detects and stops repeated output mid-stream, prunes and compacts context, then automatically resumes the task without a restart.

Install

dsh plugin --profile web add github:terry2010/dsh-loop-recover

README

dsh-loop-recover

dsh-loop-recover

Detects model dead loops and auto-rescues — the task resumes in place.

npm version GitHub stars MIT license GUI configurable
English · 中文


What It Does

Small local models (Ornith, some Qwen variants, etc.) can collapse into literal token loops (ssssss...) or semantic analysis loops — re-reasoning the same paragraphs forever. Plain loop guards just cut and stop; the task dies.

dsh-loop-recover breaks the full rescue chain:

  • Detect — 5-layer detector: periodic, n-gram, anchor, char-run, sentence-pool + intent-level tool-query tracking
  • Prune — cuts the repeated suffix mid-stream, leaves a one-line marker so the model knows something was removed
  • Compact — replaces the poisoned context with a checkpoint summary (v4 compaction/* transaction) so the model can't replay the same reasoning
  • Resume — auto-followups the same task with fresh sampling params — no new session, no restart

All inside one agent loop — the model keeps working after rescue.

Install

Open Plugins → Add plugin, search dsh-loop-recover, click Install.

CLI

dsh plugin --profile desktop add dsh-loop-recover
# then restart the app

Configuration

Everything is editable on the plugin page — no YAML needed. 32 fields grouped: Basics / Rescue / Resume / Intent / Detection / Detector (Advanced).

GroupKey fields
Basicsmode (rescue/cut/observe), watch, language, keepLanguage, marker, debugLog
RescuemaxConsecutiveRescues, compactOnRescue, stallCalls
ResumeretryTemperature, retryReasoningEffort, retryRequests
IntentintentEnabled, intentNoveltyThreshold, intentConfirmCount

Modes — rescue (cut+prune+compact+resume, default), cut (prune only, no resume), observe (log only, zero intervention — use this to evaluate thresholds on your workload first).

Why not other loop plugins

Different tools solve different problems — don't stack them:

PluginWhat it doesConflict
dsh-agent-loop-guardCuts at loop detection, stops turnBoth wrap llm/stream → double-cut, confused state
dsh-client-auto-continueResumes after interruptionTriggers extra resume → two conflicting continuation commands
dsh-session-shiftContext-pressure compaction → new sessionOverlapping rescue → one compacts while the other shifts

Disable them when using this plugin.

How it works

llm/stream (agent calls only)
  ↓ StreamLoopDetector — watches reasoning & text blocks
loop hit → cut repeated suffix → rewrite block-end → finish: stop
  ↓ commitLoopCompaction — v4 transaction, old context → checkpoint
  ↓ followup() — resume same task, fresh sampling params

Non-agent requests (title/summary generation) pass through untouched.

Development

npm test        # 66 unit + integration tests
npm run check   # plugin load smoke

License

MIT · NOTICE for upstream attributions (dsh-compaction helpers adapted).

Related plugins