fix: file reading tools skip text when paging with line numbers on (#33155)

When a model reads a file or knowledge-base file in pages with line numbers turned on, the position it was told to continue from pointed past the end of the previous page, so a chunk of text between pages was silently skipped and never returned. The gap grew with every page, dropping a few percent of a large file. Reading now continues from the right place and returns every character exactly once; paging with line numbers off is unchanged.

Fixes #33099
This commit is contained in:
Classic298 2026-10-25 05:59:39 +01:00 • committed by GitHub
parent 7f1b618727
commit a01b36afe8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2909,7 +2909,8 @@ async def view_file(
return JSONCodec.dumps(result, ensure_ascii=False)
sliced = content[offset : offset + max_chars]
is_truncated = (offset + len(sliced)) < total_chars
returned_chars = len(sliced)
is_truncated = (offset + returned_chars) < total_chars
if line_numbers:
start_ln = content[:offset].count('\n') + 1
@ -2927,10 +2928,10 @@ async def view_file(
if is_truncated or offset > 0:
result['truncated'] = is_truncated
result['total_chars'] = total_chars
result['returned_chars'] = len(sliced)
result['returned_chars'] = returned_chars
result['offset'] = offset
if is_truncated:
result['next_offset'] = offset + len(sliced)
result['next_offset'] = offset + returned_chars
return JSONCodec.dumps(result, ensure_ascii=False)
except Exception as e:
@ -3052,7 +3053,8 @@ async def view_knowledge_file(
return JSONCodec.dumps(result, ensure_ascii=False)
sliced = content[offset : offset + max_chars]
is_truncated = (offset + len(sliced)) < total_chars
returned_chars = len(sliced)
is_truncated = (offset + returned_chars) < total_chars
if line_numbers:
start_ln = content[:offset].count('\n') + 1
@ -3073,10 +3075,10 @@ async def view_knowledge_file(
if is_truncated or offset > 0:
result['truncated'] = is_truncated
result['total_chars'] = total_chars
result['returned_chars'] = len(sliced)
result['returned_chars'] = returned_chars
result['offset'] = offset
if is_truncated:
result['next_offset'] = offset + len(sliced)
result['next_offset'] = offset + returned_chars
return JSONCodec.dumps(result, ensure_ascii=False)
except Exception as e: