Repository navigation
[Bug] Agent output enters an infinite repetition loop that runs for ~10 minutes with no circuit breaker — only a manual abort stops it #2848
Replies: 3 comments
|
确认当前只有“重复工具调用提醒”,没有针对模型文本流退化重复的保护。这个行为不应直接写进 agent-loop;按现有架构,更适合做一个可配置的 llm/stream middleware 插件。 建议实现独立的 output-repetition guard:
Provider 的 frequency/presence/repetition penalty 只能作为可选能力,DeepSeek 思考模式和许多兼容网关并不保证支持,不能替代 harness 级熔断。有限的 adapter 默认 maxTokens 与提前 compaction 也应保留,但两者只是第二道防线。 回归测试应覆盖:同一句话采用不同 chunk 切分仍触发、长重复字符/句子、合法重复代码不触发、触发后 upstream return() 被调用、只有一个 error finish、无 assistant/message 持久化,以及用户手动 abort 仍保持最高优先级。 |
|
This is a good example of why circuit breakers need to live outside the model's own token stream. I've been building Redlynr (redlynr.com), an external guardrail check for exactly this class of failure (plus cost/depth/retries). It wouldn't fix the root generation issue, but it'd stop the 10-minute/420k-character bleed before it got that far. Open to you (or anyone here) trying it free against a repro if useful. |
|
Thanks — this report is worth separating from the tool-call guards, because it is not a tuning problem. Why nothing catches it today. Both in-tree guards arm only on a tool call ( @tianhao8687's comment is the right design, so rather than sketch it I implemented it: It counts consecutive identical trimmed Two mechanics that comment leaves open — both cost me a wrong first implementation, so they are worth recording:
On your four points specifically:
For your session file: I also extended the plugin's offline analyzer, which replays a session jsonl through the same decision rule the installed guard runs (and reads both durable attempt formats, v1 Replayed against a session shaped like yours, it reports A criterion to judge it by: does that call now stop at ~60 identical chunks instead of running for ten minutes, and does the next step come back corrected instead of resuming the sentence? If it still runs to the ceiling, the likely cause is that the repeats differ by whitespace or tokenization and the identical-chunk run never reaches the threshold — in that case send the session and I will adjust the matching (the buffer-level n-gram shape above is the fallback). |
Uh oh!
There was an error while loading. Please reload this page.
Summary
When an agent's context gets very large (long-running session plus a broad "verify everything after an upgrade" task), the model can enter a degenerate repetition loop: it streams the same sentence over and over as assistant text chunks. DSH has no repetition guard or circuit breaker, so the loop runs until max_tokens is hit or the user manually aborts. In our case it streamed about 420,000 characters of identical text over 10 full minutes.
Environment
Reproduction (what we observed in the session log)
The archived session (a plugin project workspace) had:
Evidence in the log: the step produced text-chunks events forever, with no finish chunk, no stop reason, and no assistant/message - just endless identical text deltas.
A related failure appeared in the same project's other session: turn 23 sent 467,456 input tokens and immediately hit max-tokens with 1 output token (empty text). Both failures point to context saturation plus model degeneration, with no harness-level protection.
Root cause (from code inspection)
Searching the DSH and pi-ai stack for frequency_penalty, presence_penalty, repetition_penalty, or any "N consecutive identical chunks - abort" logic returns nothing. The only "repeat" handling in dsh-agent is about status transitions and dispatcher dedup - nothing about degenerate model output.
So the only exit conditions are:
Neither is a reasonable guardrail for a stuck model.
Suggested fix (any of, ideally a combination)
Notes
All reactions