[PR #3445] fix: add doom loop detection #10646

Closed
opened 2026-02-16 18:15:22 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/3445

State: closed
Merged: Yes


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:

  • Added DOOM_LOOP_MODELS constant for model-specific configuration (glm-4.6, grok-code)
  • Added Map-based tracking of tool+input combinations with threshold of 3 repetitions
  • Added non-blocking warning message injection with model-specific templates
  • Zero impact on non-target models, <1% overhead for target models
  • Memory efficient with automatic cleanup

Fixes infinite loop issue while maintaining performance and extensibility for additional problematic models.

fixes: #3444

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/3445 **State:** closed **Merged:** Yes --- ## 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: - Added `DOOM_LOOP_MODELS` constant for model-specific configuration (glm-4.6, grok-code) - Added Map-based tracking of tool+input combinations with threshold of 3 repetitions - Added non-blocking warning message injection with model-specific templates - Zero impact on non-target models, <1% overhead for target models - Memory efficient with automatic cleanup Fixes infinite loop issue while maintaining performance and extensibility for additional problematic models. fixes: #3444
yindo added the pull-request label 2026-02-16 18:15:22 -05:00
yindo closed this issue 2026-02-16 18:15:22 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#10646