This repository was archived by the owner on May 15, 2026. It is now read-only.
fix: add path-based repetition detection for read_file tool - #11073
Draft
ghost wants to merge 1 commit into
Draft
Conversation
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
Author
Review complete. No issues found. The implementation is well-designed and follows existing patterns:
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
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
ToolRepetitionDetectoronly 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_filetool calls:read_filecalls that target the same file path(s)Key Implementation Details:
checkReadFilePathRepetition()method that extracts file paths and tracks repetitionsThis 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
Pre-Submission Checklist
Documentation Updates
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_filetool inToolRepetitionDetectorto prevent loops when reading the same file with different parameters.read_fileinToolRepetitionDetector.ts.checkReadFilePathRepetition()to track file path repetitions.paramsandnativeArgsformats.readFilePathLimitadded to constructor.ToolRepetitionDetector.spec.tsfor path-based detection.readFilePathRepetitionLimitReachedmessage totools.json.This description was created by
for 538ecae. You can customize this summary. It will automatically update as commits are pushed.