{{ message }}
Repository navigation
Conversation
The Read schema declares offset >= 1 and 1 <= limit <= 2000, but nothing enforced them at runtime: a non-positive offset negative-sliced the file and silently returned its tail (e.g. offset=0 returned the last line labeled "0"), and limit <= 0 returned empty text, both with a success result. Return an error chunk instead so the model can self-correct, matching the Grep/Glob pagination validation.
Contributor
Contributor
Author
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

AgentScope Version
2.0.10
Description
Fixes #3291.
What Problem This Solves
This PR fixes a pagination validation gap in the builtin
Readtool.The
Readschema already declaresoffsetas a 1-based line number withge=1, andlimitwithge=1, le=2000(src/agentscope/tool/_builtin/_read.py:60-72), but — unlikeGrepandGlob— nothing validated them at runtime, so tool calls whose arguments bypass schema validation reached the slicing step unvalidated._read_text_fileslices withlines[start_idx:end_idx]wherestart_idx = offset - 1(src/agentscope/tool/_builtin/_read.py:533-535). A non-positiveoffsetmakesstart_idxnegative, so Python addresses the list from its end and the tool returns the tail of the file labeled with line numbers0or negative, with a success state.limit <= 0returns empty text, also with a success state. Reading a 10-line file onmain:Because the tool reports success, the model receives content from the wrong part of the file with impossible line numbers and no signal to self-correct.
Change
Add runtime validation in
_read_text_file, before any slicing, mirroring theGrep/Globpagination guards:offset < 1->Error: offset must be at least 1, got: {offset}.limit < 1 or limit > 2000->Error: limit must be between 1 and 2000, got: {limit}.Both return a
ToolResultState.ERRORchunk so the model can retry with valid arguments. Valid reads are unchanged, and sinceoffset/limitonly apply to plain text files, the guards live in_read_text_fileso the PDF and image paths are untouched.Testing
main(before the fix):pytest tests/builtin_read_test.py->20 passed in 0.86spytest tests/builtin_read_test.py tests/builtin_write_test.py tests/builtin_edit_test.py tests/builtin_grep_test.py tests/builtin_glob_test.py tests/builtin_bash_test.py tests/builtin_file_cache_test.py->122 passed, 61 subtests passed in 2.13spytest tests->2746 passed, 147 skipped, 600 subtests passed in 167.54spre-commit run --files src/agentscope/tool/_builtin/_read.py tests/builtin_read_test.py-> all hooks passed (mypy, black, flake8, pylint, pyroma)Checklist
Please check the following items before code is ready to be reviewed.