dsh-repetition-guard
English | Česky
Stops a model from "looping" during generation — when it starts repeating the
same word over and over (wait wait wait …, počkat počkat …), sometimes
hundreds or thousands of times, burning tokens for nothing.
How it works
The plugin hooks the llm/stream waterfall (DSH's official extension point
around every streaming model call) and watches both reasoning-delta chunks
(the thinking text) and text-delta chunks (the visible answer). As soon as
the tail of either stream contains 12 identical words in a row (threshold
configurable), it stops the stream.
Stopping the stream makes the adapter abort its fetch → the provider stops
generating further tokens. The rest behaves like a normal end (the assembler
treats finish = stop), so the turn ends cleanly with whatever was generated
before the loop.
Why it can't hurt normal output
- It only triggers on ≥ 12 identical consecutive words — normal reasoning or
prose never contains a run like that (one "wait" is fine, twelve aren't).
- It inspects only the last
tailChars characters (160), so it doesn't slow
the stream or grow memory.
- It deletes nothing — it just stops reading the stream; already-emitted blocks
are preserved.
Install
dsh plugin --profile web add dsh-repetition-guard
Restart the DSH session; it then guards every model call (including subagents).
Configuration
- word threshold:
config.threshold (default 12)
- inspected tail length:
config.tailChars (default 160)
- on trigger it logs:
repetition-guard: stopped a repeated-word loop…
License
MIT