Repository navigation
Detect and recover from degenerate repeated model output (repetition guard) / ๆฃๆตๅนถๆขๅค้ๅ็้ๅคๆจกๅ่พๅบ๏ผ้ๅคๅฎๅซ๏ผ #3480
filantropo17
started this conversation in
Ideas
Replies: 1 comment
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Problem / ้ฎ้ข
Models sometimes degenerate into repeating one word, phrase, or n-gram until the output-token ceiling. The harness currently accepts such responses as an ordinary completed turn: the stream finishes with
stopormax-tokens, neither of which is a failure, so nothing truncates the loop and no retry is triggered. The user is left with a long, unusable, token-wasting reply, and the session log is polluted with the repeated content.ๆจกๅๆๆถไผ้ๅไธบๅๅค่พๅบๅไธไธชๅ่ฏใ็ญ่ฏญๆ n-gram๏ผ็ดๅฐๆๆปก่พๅบ token ไธ้ใๅฝๅ harness ไผๆ่ฟ็ฑปๅๅบๅฝไฝๆฎ้็ๆญฃๅธธๅฎๆ turn๏ผๆตไปฅ
stopๆmax-tokens็ปๆ๏ผไธค่ ้ฝไธ็ฎๅคฑ่ดฅ๏ผๅ ๆญคๆฒกๆไปปไฝๆบๅถๆชๆญๅพช็ฏๆ่งฆๅ้่ฏใ็จๆทๅช่ฝๅพๅฐไธๆฎตๅ้ฟใไธๅฏ็จไธๆตช่ดน token ็ๅๅค๏ผไผ่ฏๆฅๅฟไน่ขซ้ๅคๅ ๅฎนๆฑกๆใProposal / ๆ่ฎฎ
A stream-level repetition guard: wrap the existing
llm/streamwaterfall, detect when the trailing text is one unit repeated N times, truncate the stream, and fail the request with a new provider-neutral codeDEGENERATE_OUTPUT, so the existingagent/request-errorโdsh-llm-retrypath retries it under the provider policy. No agent-loop changes are needed โ thellm/streamwaterfall already sits at exactly the right seam.ๆต็บง้ๅคๅฎๅซ๏ผๅ ่ฃ ็ฐๆ็
llm/stream็ๅธ๏ผๅฝๅฐพ้จๆๆฌๅบ็ฐๅไธๅๅ ่ฟ็ปญ้ๅค N ๆฌกๆถๆชๆญๆต๏ผๅนถไปฅๆฐ็ provider ๆ ๅ ณ้่ฏฏ็ DEGENERATE_OUTPUTๅคๅคฑ่ดฅ๏ผไป่่ฎฉ็ฐๆ็agent/request-errorโdsh-llm-retry่ทฏๅพๆ provider ็ญ็ฅ้่ฏใๅฎๅ จไธ้่ฆๆน agent ไธปๅพช็ฏโโllm/stream็ๅธๆญฃๅฅฝไฝไบๆญฃ็กฎ็ๆฅ็ผไธใI built this as an ecosystem plugin (
dsh-llm-repetition-guard) to prove the approach:ๆๆๅฎๅฎ็ฐไธบ็ๆๆไปถ๏ผ
dsh-llm-repetition-guard๏ผๆฅ้ช่ฏ่ฏฅๆนๆก๏ผๆฏไธชๆตไธไธช็ฌ็ซๆฃๆตๅจ๏ผๆๅๅจๅ้ๆปๅจ็ชๅฃ๏ผ้ป่ฎค 1024 ๅญ็ฌฆ๏ผๅ ็ดฏ่ฎกๆๆฌใ
ๆฃๆตไพๆฎๆฏๆๅๅ ๅจๆๆๅฏน้ฝๆนๅผไธ็ๆ้ฟๅฐพ้จ่ฟ็ปญๅบ็ฐโโ"data data data โฆ" ๆ ่ฎบๆๅไธไธชๅๅ ๆฏๅฆๆฐๅฅฝ่ฝๅจ็ชๅฃ่พน็ไธ้ฝ่ฝ่ขซๆ่ทใ
textdeltas are guarded by default;reasoningdeltas are ignored unless opted in (reasoning text is pattern-heavy and would trip conservative thresholds); tool-call argument streams are never guarded (JSON legitimately repeats keys and separators).้ป่ฎคๅชๆฃๆต
textdelta๏ผreasoningdelta ้ป่ฎคๅฟฝ็ฅ๏ผๆจ็ๆๆฌๅคฉ็ถๆจกๅผๅ๏ผไฟๅฎ้ๅผๅฎนๆ่ฏฏไผค๏ผ๏ผๅทฅๅ ท่ฐ็จๅๆฐๆตๆฐธไธๆฃๆต๏ผJSON ๅๆณๅฐ้ๅค้ฎไธๅ้็ฌฆ๏ผใDEGENERATE_OUTPUTerror finish and truncates the stream; the loop retries under the provider retry policy, and truncated chunks never enter derived messages.ๆฃๆตๅฐๆถไบงๅบ็ปๆญขๆง็
DEGENERATE_OUTPUTerror finish ๅนถๆชๆญๆต๏ผไธปๅพช็ฏๆ provider ้่ฏ็ญ็ฅ้่ฏ๏ผ่ขซๆชๆญ็ chunk ๆฐธไธ่ฟๅ ฅๆดพ็ๆถๆฏใไฟๅฎ้ป่ฎคๅผ๏ผ็ดฏ่ฎก 64 ไธชๅญ็ฌฆๅๅผๅงๆฃๆต๏ผๅไธ 8 ๅญ็ฌฆๅๅ ่ฟ็ปญๅบ็ฐ โฅ6 ๆฌกๅณ่งฆๅใๆๆ้ๅผๅๅฏ้ ็ฝฎใ
What I'd like feedback on / ๅธๆๅพๅฐๅ้ฆ
retryableCodes. ShouldDEGENERATE_OUTPUTjoin the default retryable set indsh-llm? The published package currently omits it, so deployments must opt in explicitly. BothEMPTY_RESPONSEandDEGENERATE_OUTPUTare content-quality failures that produced no usable output, so repeating them is safe.้ป่ฎค
retryableCodesใDEGENERATE_OUTPUTๆฏๅฆๅบ่ฏฅๅ ๅ ฅdsh-llm็้ป่ฎคๅฏ้่ฏ้ๅ๏ผๅฝๅๅทฒๅๅธ็ๅ ๆชๅ ๅซๅฎ๏ผ้จ็ฝฒๆนๅฟ ้กปๆพๅผ้ ็ฝฎใEMPTY_RESPONSEไธDEGENERATE_OUTPUT้ฝๆฏๆชไบง็ๅฏ็จ่พๅบ็ๅ ๅฎน่ดจ้็ฑปๅคฑ่ดฅ๏ผ้ๅคๅฎไปฌ้ฝๆฏๅฎๅ จ็ใllm/streamwrapper pattern) rather than relying on ecosystem plugins for this class of checks?ๆ ธๅฟ vs. ็ๆใ harness ๆฏๅฆๅบ่ฏฅๅจๆ ธๅฟไธญๆไพๅ ๅฎน่ดจ้ๆฉๅฑ็น๏ผ
llm/streamๅ ่ฃ ๆจกๅผ๏ผ๏ผ่ไธๆฏไพ่ต็ๆๆไปถๆฅๆฟ่ฝฝ่ฟ็ฑปๆฃๆฅ๏ผ้ๅผใ "็ดฏ่ฎก 64 ๅญ็ฌฆๅ๏ผ8 ๅญ็ฌฆๅๅ ่ฟ็ปญ้ๅค โฅ6 ๆฌก"ไฝไธบไฟๅฎ้ป่ฎคๅผๆฏๅฆๅ็๏ผ็ๅฎ่ด่ฝฝไธๆฏๅฆๆ่ฏฏๆฅ็ป้ช๏ผ
้่ฟ็ปญ้ๅคใ ไบคๆฟ็ญ่ฏญๆ็จ็ๆฃๅธ็ญๅๅ ็่พๅบ็ฎๅๆ ๆณๆฃๆตโโ่ฟไธ็ฑปๆฏๅฆๅผๅพ่ฆ็๏ผ
The plugin is published as
dsh-llm-repetition-guardand carries an./invariantcompanion that verifies the truncation contract (nothing follows aDEGENERATE_OUTPUTfinish within one attempt).ๆไปถไปฅ
dsh-llm-repetition-guardๅๅธ๏ผๅนถ้ๅธฆ./invariantไผด้ๆไปถ๏ผ็จไบ้ช่ฏๆชๆญๅฅ็บฆ๏ผไธๆฌก attempt ๅDEGENERATE_OUTPUTfinish ไนๅไธๅพๅๆๅ ๅฎน๏ผใAll reactions