Skip to content

feat(core): enhance loop detection with thought and action stagnation checks#3176

Closed
euxaristia wants to merge 1 commit intoQwenLM:mainfrom
euxaristia:feat/loop-detection-improvements
Closed

feat(core): enhance loop detection with thought and action stagnation checks#3176
euxaristia wants to merge 1 commit intoQwenLM:mainfrom
euxaristia:feat/loop-detection-improvements

Conversation

@euxaristia
Copy link
Copy Markdown
Contributor

Summary

Enhance the LoopDetectionService with additional loop detection patterns to catch more subtle looping behaviors that were previously undetected.

Changes

New Loop Detection Patterns

  • Repetitive Thoughts: Detects when the model produces the same thought patterns repeatedly, indicating cognitive loops
  • Read File Loop: Detects excessive file read operations without meaningful progress
  • Action Stagnation: Tracks turns without meaningful action progress, catching subtle loops where the model keeps performing different but equally unproductive actions

Improvements

  • Added REPETITIVE_THOUGHTS, READ_FILE_LOOP, and ACTION_STAGNATION to the LoopType enum in telemetry types
  • Enhanced LoopDetectionService with thought tracking and action stagnation counters
  • Improved test coverage for edge cases including:
    • Content loops with interspersed tool calls (to prevent false negatives)
    • Repetitions far apart with unique filler content
    • Long code blocks with repeating tokens
    • Reset behavior verification

Telemetry

All new loop types are properly logged via logLoopDetected and will appear in telemetry when loop detection is triggered.

History note

This update addresses edge cases where the model could enter subtle loop patterns that weren't caught by the existing identical tool call and content repetition checks. Examples include:

  • Repeating the same internal thought/rationale multiple times
  • Continuously reading files without taking action
  • Performing different but equally unproductive actions turn after turn

… checks

Add detection for repetitive thoughts, read file loops, and action
stagnation in LoopDetectionService. Expand telemetry LoopType enum
with new loop categories and improve test coverage for edge cases.

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
@tanzhenxin
Copy link
Copy Markdown
Collaborator

Thanks for the contribution, @euxaristia! The idea of enhancing loop detection with thought and action stagnation checks sounds useful.

However, this PR touches 100 files, which makes it very difficult to review safely. Could you break this down into smaller, focused PRs? For example, separate the core stagnation detection logic from any refactoring or test changes. That would make it much easier to review and merge incrementally.

Happy to revisit once it's split up into more manageable pieces!

@tanzhenxin tanzhenxin closed this Apr 13, 2026
@euxaristia
Copy link
Copy Markdown
Contributor Author

Oops! Something must have gone wrong with my PR and my agents. I'll fix it soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants