fix: add path-based repetition detection for read_file tool #11073
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.