Skip to content

The agent that grows with you

fix(tools): read_file dispatch honors the advertised 2000-line default when the model omits limit

Teknium3009efe75e77
diff --git a/tests/tools/test_file_tools.py b/tests/tools/test_file_tools.py
index 762b6d7fdab..48f22f381df 100644
--- a/tests/tools/test_file_tools.py
+++ b/tests/tools/test_file_tools.py
@@ -32,6 +32,22 @@ class TestReadFileHandler:
mock_ops.read_file.assert_called_once_with("/tmp/test.txt", 1, 2000)
+ @patch("tools.file_tools._get_file_ops")
+ def test_dispatch_without_limit_uses_schema_default(self, mock_get):
+ """The model omits ``limit`` on most reads; the dispatch handler must fall
+ back to the SAME default the schema advertises (drifted to 500 vs 2000)."""
+ from tools.file_tools import READ_FILE_SCHEMA, _handle_read_file
+ mock_ops = MagicMock()
+ result_obj = MagicMock()
+ result_obj.content = "x"
+ result_obj.to_dict.return_value = {"content": "x", "total_lines": 1}
+ mock_ops.read_file.return_value = result_obj
+ mock_get.return_value = mock_ops
+
+ _handle_read_file({"path": "/tmp/test.txt"}, task_id="t-default")
+ schema_default = READ_FILE_SCHEMA["parameters"]["properties"]["limit"]["default"]
+ assert mock_ops.read_file.call_args.args[2] == schema_default
+
@patch("tools.file_tools._get_file_ops")
def test_exception_returns_error_json(self, mock_get):
mock_get.side_effect = RuntimeError("terminal not available")
diff --git a/tools/file_tools.py b/tools/file_tools.py
index e355a6eede7..38d210b8b87 100644
--- a/tools/file_tools.py
+++ b/tools/file_tools.py
@@ -22,6 +22,7 @@ from agent.file_safety import get_read_block_error
from tools.binary_extensions import has_binary_extension
from tools.file_operations import (
ShellFileOperations, normalize_read_pagination, normalize_search_pagination)
+from tools.file_operations_common import DEFAULT_READ_LIMIT
from tools import file_state
from agent.redact import redact_sensitive_text
from tools.file_tools_paths import (
@@ -536,7 +537,7 @@ def _record_successful_read(task_data: dict, task_id: str, path: str, resolved_s
return count
-def read_file_tool(path: str, offset: int = 1, limit: int = 2000, task_id: str = "default") -> str:
+def read_file_tool(path: str, offset: int = 1, limit: int = DEFAULT_READ_LIMIT, task_id: str = "default") -> str:
"""Read a file with pagination and line numbers.
Guard order: device-path blocklist (no I/O) → stat-based special-file
@@ -979,7 +980,7 @@ READ_FILE_SCHEMA = {
"properties": {
"path": {"type": "string", "description": "Path to the file to read (absolute, relative, or ~/path)"},
"offset": {"type": "integer", "description": "Line number to start reading from (1-indexed, default: 1)", "default": 1, "minimum": 1},
- "limit": {"type": "integer", "description": "Maximum number of lines to read (default: 2000, max: 2000). Reads are additionally capped at a ~100K-character budget with a next_offset continuation.", "default": 2000, "maximum": 2000}
+ "limit": {"type": "integer", "description": "Maximum number of lines to read (default: 2000, max: 2000). Reads are additionally capped at a ~100K-character budget with a next_offset continuation.", "default": DEFAULT_READ_LIMIT, "maximum": 2000}
},
"required": ["path"]
}
@@ -1123,7 +1124,7 @@ SEARCH_FILES_SCHEMA = {
def _handle_read_file(args, **kw):
tid = kw.get("task_id") or "default"
- return read_file_tool(path=args.get("path", ""), offset=args.get("offset", 1), limit=args.get("limit", 500), task_id=tid)
+ return read_file_tool(path=args.get("path", ""), offset=args.get("offset", 1), limit=args.get("limit", DEFAULT_READ_LIMIT), task_id=tid)
def _handle_write_file(args, **kw):