feat: implement loop detection for thinking and text#21112
Open
M0dEx wants to merge 1 commit intoanomalyco:devfrom
Open
feat: implement loop detection for thinking and text#21112M0dEx wants to merge 1 commit intoanomalyco:devfrom
M0dEx wants to merge 1 commit intoanomalyco:devfrom
Conversation
6 tasks
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate Found:
The current PR #21112 and PR #15852 both focus on implementing loop detection mechanisms for repetitive thinking/reasoning patterns and appear to be addressing the same underlying issues (#12716, #14343, #15271, #3743). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
#12716 - "Doom loop is not caught when during reasoning or output"
The doom loop guard previously only caught tool call loops, not reasoning/output loops. This branch adds detection for repetitive reasoning blocks.
#14343 - "Kimi K2.5 frequently gets in a reiteration loop"
Kimi K2.5 specifically gets stuck repeating the same reasoning patterns. The thinking loop detector catches these repetitions and intervenes.
#15271 - "Models get stuck in reasoning loop - making changes only in thinking, not actually executing tool calls"
Models plan changes in their thinking block but never actually call tools. The detector identifies when reasoning becomes repetitive and sends a reminder or compacts context.
#3743 - "Loop in certain models"
General issue with models (including GLM) getting stuck in loops.
Type of change
What does this PR do?
Some models (especially GLM-5 and Kimi K2.5) get stuck in loops (reasoning or text ouput) where they repeat the same thoughts over and over without actually doing anything. This PR adds detection for that behavior.
When the model starts repeating a block of text (10-2000 chars) twice in a row, we:
This is configurable via the
experimental.loopconfig section. It's on by default since models that loop waste tokens and never complete tasks.How did you verify your code works?
Unit tests for the detector module (true/false positives, recovery escalation) and an integration test using a mock HTTP server that exercises the full nudge→abort flow. Also tested manually on workflows that previously caused loops.
Checklist