feat: implement thinking loop detection with automatic handler#15852
Closed
M0dEx wants to merge 2 commits intoanomalyco:devfrom
Closed
feat: implement thinking loop detection with automatic handler#15852M0dEx wants to merge 2 commits intoanomalyco:devfrom
M0dEx wants to merge 2 commits intoanomalyco:devfrom
Conversation
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Found a potential related PR:
|
M0dEx
commented
Mar 3, 2026
6a0893b to
59f535a
Compare
551378b to
c969329
Compare
c969329 to
e0d801c
Compare
|
Nice. Def want doc updates. Also It would be nice to see a comprehensive test which demonstrated the full workflow, I looked through the tests it didn't really look like that existed. |
Author
Replaced by #21112, which implements this for text output as well, with integration tests. |
6 tasks
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 reasoning loops 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 (20-1000 chars) 3+ times in a row, we:
This is configurable via the experimental.thinking_loop config section. It's on by default since models that loop waste tokens and never complete tasks.
How did you verify your code works?
Tested on some workflows that caused the models to loop without it and saw successful nudging breaking the loops.
Checklist