fix(file-tools): cap read_file result size to prevent context window overflow

Set max_result_size_chars=100_000 on the read_file registry entry (was
float('inf')), closing the Layer 2 defense-in-depth gap in
tool_result_storage.py. The existing Layer 1 guard inside
_handle_read_file already returns a JSON error for oversized reads;
this aligns the registry cap with every other tool.

Update test_read_file_never_persisted → test_read_file_result_size_cap
to assert 100_000, and add test_read_file_registry_cap_is_100k as an
explicit regression guard against re-introducing float('inf').

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ioodu 2026-04-27 19:09:30 +08:00 committed by Teknium
parent 5b6d413476
commit e50809b771
2 changed files with 16 additions and 3 deletions

View file

@ -516,12 +516,25 @@ class TestPerToolThresholds:
except ImportError:
pytest.skip("terminal_tool not importable in test env")
def test_read_file_never_persisted(self):
def test_read_file_result_size_cap(self):
from tools.registry import registry
try:
import tools.file_tools # noqa: F401
val = registry.get_max_result_size("read_file")
assert val == float("inf")
assert val == 100_000
except ImportError:
pytest.skip("file_tools not importable in test env")
def test_read_file_registry_cap_is_100k(self):
"""Regression test: read_file must have a 100_000 char registry cap (Layer 2 safety net)."""
from tools.registry import registry
try:
import tools.file_tools # noqa: F401
val = registry.get_max_result_size("read_file")
assert val == 100_000, (
f"read_file registry cap must be 100_000, got {val!r}. "
"float('inf') is not allowed — it disables the Layer 2 result-size guard."
)
except ImportError:
pytest.skip("file_tools not importable in test env")