fix: add loop detection for doom loop models (GLM-4.6, Grok Code) - fix #3444 #3445
+33
−0
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.
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