Skip to content

[Bug]: Read tool accepts offset <= 0, negative-slicing the file and returning its tail labeled with line numbers 0 or negative #3291

Closed

Description

@BlueX888

Prerequisites

  • I have searched the existing issues and discussions, and this is not a duplicate.
  • This is a bug, not a usage question. (For questions, please use Discussions instead.)

Background / Description

The Read tool's parameter schema declares offset as a 1-based line number with ge=1, and limit with ge=1, le=2000 (src/agentscope/tool/_builtin/_read.py), but nothing enforces them at runtime. When a caller passes offset=0 (an easy 0-based off-by-one mistake for an LLM) or a negative offset, the slice lines[start_idx:end_idx] with a negative start_idx walks backwards from the end of the file, so the tool silently returns the tail of the file labeled with line numbers 0 or negative — with a success state. limit=0 likewise returns empty text with a success state.

Since the tool reports success, the model has no signal to self-correct; it receives content from the wrong part of the file labeled with impossible line numbers.

The sibling tools already reject this class of input at runtime: Grep returns Error: offset must be non-negative. / Error: head_limit must be non-negative. and Glob does the same for its pagination arguments.

Error Messages

No error is produced — that is the bug. On main (2.0.10dev), reading a 10-line file with offset=0 succeeds and returns:

--- offset=0, state=running ---
     0	line 10
--- offset=-3, state=running ---
    -3	line 7
    -2	line 8
    -1	line 9
     0	line 10
--- limit=0, state=running ---
''

Steps to Reproduce

  1. Code:
import asyncio, os, tempfile
from agentscope.tool import Read

async def main():
    d = tempfile.mkdtemp()
    p = os.path.join(d, "sample.txt")
    with open(p, "w") as f:
        for i in range(1, 11):
            f.write(f"line {i}\n")
    read = Read()
    for offset in (0, -3):
        chunk = await read.call(file_path=p, offset=offset)
        print(f"offset={offset}: state={chunk.state}")
        print(chunk.content[0].text)
    chunk = await read.call(file_path=p, limit=0)
    print(f"limit=0: state={chunk.state} text={chunk.content[0].text!r}")

asyncio.run(main())
  1. Run: python repro.py
  2. See the file tail returned with line numbers 0/negative and state=running instead of an error.

Expected: an error chunk (like Grep/Glob pagination validation), e.g. Error: offset must be at least 1, got: 0.

Environment

  • AgentScope Version: 2.0.10 (main)
  • Python Version: 3.12.14
  • OS: macOS 15

Activity

  1. added
    triage/verifyingA bot is verifying whether this bug is real
    triage/confirmedVerified: the reported defect exists
    and removed
    triage/verifyingA bot is verifying whether this bug is real
    on Oct 13, 2026
  2. SSK988I commented on Oct 13, 2026

    @SSK988I
    Contributor

    /assign

  3. github-actions commented on Oct 13, 2026

    @github-actions
    Contributor

    It's yours, @SSK988I. If there is no pull request and no word from you by 2026-10-27 the claim is released so nobody is blocked — a comment here renews it.

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

Metadata

Metadata

Assignees

Labels

triage/confirmedVerified: the reported defect exists

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions