Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jan 29, 2026

Related GitHub Issue

Closes: #11071

Description

This PR attempts to address Issue #11071 where GLM4.5 (and potentially other models) gets stuck in a loop reading the same file repeatedly with different parameters (e.g., different line ranges).

The Problem:
The existing ToolRepetitionDetector only catches byte-for-byte identical tool calls. When a model reads the same file with slightly different parameters (like different line ranges), each call is considered unique and bypasses detection.

The Solution:
This PR adds path-based repetition detection specifically for read_file tool calls:

  1. Track consecutive read_file calls that target the same file path(s)
  2. Block execution when the same file is read more than N times consecutively, regardless of other parameters (like line ranges)
  3. Keep existing identical-call detection as the primary mechanism
  4. Reset tracking when a different tool is used, allowing recovery

Key Implementation Details:

  • Added checkReadFilePathRepetition() method that extracts file paths and tracks repetitions
  • Supports both params-based and nativeArgs-based formats
  • Uses same limit as identical call detection by default, but can be configured separately
  • Added translation key for the new error message

This approach is provider-agnostic and will work regardless of which API provider is used (LM Studio, OpenAI-compatible, or others).

Feedback and guidance are welcome!

Test Procedure

  1. Run the new test cases:
    cd src && npx vitest run core/tools/__tests__/ToolRepetitionDetector.spec.ts
  2. All 39 tests pass, including 8 new tests for path-based detection:
    • Detection of same file with different line ranges
    • Detection with nativeArgs format
    • Allowing different files consecutively
    • Resetting counter when different tool is used
    • Custom readFilePathLimit configuration
    • Recovery after limit is reached
    • Non-interference with other tools

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Documentation Updates

  • No documentation updates are required.

Additional Notes

This fix provides a more robust solution that works at the tool detection level rather than targeting specific providers. The user reported the issue affects both LM Studio and OpenAI-compatible endpoints, so a provider-agnostic approach is more appropriate.


Important

Adds path-based repetition detection for read_file tool in ToolRepetitionDetector to prevent loops when reading the same file with different parameters.

  • Behavior:
    • Adds path-based repetition detection for read_file in ToolRepetitionDetector.ts.
    • Blocks execution if the same file is read more than N times consecutively, regardless of parameters.
    • Resets tracking when a different tool is used.
  • Implementation:
    • Adds checkReadFilePathRepetition() to track file path repetitions.
    • Supports both params and nativeArgs formats.
    • Configurable readFilePathLimit added to constructor.
  • Tests:
    • Adds 8 new tests in ToolRepetitionDetector.spec.ts for path-based detection.
    • Tests include different line ranges, nativeArgs format, and custom limits.
  • Localization:
    • Adds readFilePathRepetitionLimitReached message to tools.json.

This description was created by Ellipsis for 538ecae. You can customize this summary. It will automatically update as commits are pushed.

This enhances the ToolRepetitionDetector to detect when the same file is
being read repeatedly with different parameters (e.g., different line ranges).

Previously, the detector only caught byte-for-byte identical tool calls.
This change adds secondary detection specifically for read_file calls
that target the same file path, regardless of other parameters.

This helps prevent models like GLM4.5 from getting stuck in loops where
they read the same file over and over with slightly different line ranges.

Fixes #11071
@roomote
Copy link
Contributor Author

roomote bot commented Jan 29, 2026

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

The implementation is well-designed and follows existing patterns:

  • Path-based repetition detection correctly catches models reading the same file with different parameters
  • Path extraction handles both native protocol and legacy formats
  • Tests are comprehensive (8 new tests, all passing)
  • Recovery mechanism works correctly

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

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

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

[BUG] GLM4.5 via LMStudio as well as via an OpenAI-compatible endpoint stuck repeating file reads

1 participant