-
Couldn't load subscription status.
- Fork 2.2k
fix: add loop detection for doom loop models (GLM-4.6, Grok Code) - fix #3444 #3445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
| "glm-4.6": `⚠️ Loop detected! You have been calling "%TOOL%" with the same parameters repeatedly. This is causing an infinite loop. Please STOP calling this tool and try a different approach or modify the parameters.`, | ||
| "grok-code": `⚠️ Loop detected! You're stuck repeating "%TOOL%" with identical inputs. Break this pattern and try a different strategy or change the parameters.`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it be model specific? Almost seems like it should be model agnostic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made it model-specific since only GLM-4.6 and Grok Code are known to have this issue. Other models work fine and we don't want to add overhead for them. Could make it agnostic later if more models show this behavior.
| const key = `${value.toolName}|${JSON.stringify(value.input)}` | ||
| const count = (loopCounts.get(key) || 0) + 1 | ||
| loopCounts.set(key, count) | ||
|
|
||
| if (count >= LOOP_DETECTION_THRESHOLD) { | ||
| await Session.updatePart({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this how everyone else does loop detection too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this is how everyone else does it, but this approach should work. Tool+input tracking with thresholds using simple Map-based counting with O(1) performance keeps it lightweight and effective.
fix: add loop detection for doom loop models (GLM-4.6, Grok Code)
GLM-4.6 and Grok Code models are prone to "doom loops" - infinite repetition of same tool call with identical parameters. This causes wasted tokens, poor user experience with stuck sessions, and server resource waste.
This commit adds targeted loop detection that monitors tool calls for problematic models and injects breaking messages when loops are detected. The implementation uses Map-based counting with O(1) performance and only affects specific models known to have this issue.
Key changes:
DOOM_LOOP_MODELSconstant for model-specific configuration (glm-4.6, grok-code)Fixes infinite loop issue while maintaining performance and extensibility for additional problematic models.
fix #3444