From a01b36afe80983ca878b2c4dcdc25f8559a25308 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Sun, 25 Oct 2026 05:59:39 +0100 Subject: [PATCH] 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 --- backend/open_webui/tools/builtin.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/backend/open_webui/tools/builtin.py b/backend/open_webui/tools/builtin.py index 2b28f46846..29000b5d30 100644 --- a/backend/open_webui/tools/builtin.py +++ b/backend/open_webui/tools/builtin.py @@ -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: