mirror of
https://github.com/usestrix/strix.git
synced 2026-08-23 03:12:37 +02:00
fix(context): keep tool-output retrieval reliable and stream pages
Exempt read_tool_output from result-bounding so paging a large stored output isn't re-spilled under a new id, byte-cap each page in place, and stream the requested window with islice instead of loading the whole file per page.
This commit is contained in:
@@ -110,3 +110,14 @@ async def test_chat_completions_filesystem_custom_tool_becomes_function_tool() -
|
||||
factory._configure_filesystem_tools(toolset, chat_completions=True)
|
||||
|
||||
assert isinstance(toolset.read_file, FunctionTool)
|
||||
|
||||
|
||||
def test_read_tool_output_is_not_result_bounded() -> None:
|
||||
# Every other FunctionTool gets the result-bounding wrapper, but the
|
||||
# retrieval tool must be exempt or paging a large stored output would be
|
||||
# re-spilled under a new id.
|
||||
agent = factory.build_strix_agent(is_root=True)
|
||||
by_name = {t.name: t for t in agent.tools}
|
||||
|
||||
assert getattr(by_name["read_tool_output"], "_strix_bounded", False) is False
|
||||
assert getattr(by_name["think"], "_strix_bounded", False) is True
|
||||
|
||||
@@ -114,6 +114,25 @@ def test_read_stored_output_paginates(tmp_path: Path) -> None:
|
||||
assert "offset=10" in page
|
||||
|
||||
|
||||
def test_read_stored_output_page_is_bounded_without_new_spill(tmp_path: Path) -> None:
|
||||
# A page of very long lines must be byte-capped in place, never re-spilled
|
||||
# under a fresh output_id (which would make paging loop forever).
|
||||
configure_output_store(tmp_path)
|
||||
text = "\n".join("z" * 5_000 for _ in range(50))
|
||||
output_id = re.search(
|
||||
r'output_id="([0-9a-f]{32})"',
|
||||
bound_and_store(text, max_lines=4, max_bytes=1_000),
|
||||
)
|
||||
assert output_id is not None
|
||||
|
||||
page = read_stored_output(output_id.group(1), offset=0, limit=2_000)
|
||||
|
||||
assert len(page.encode("utf-8")) <= 60 * 1024
|
||||
# No brand-new spill id in the returned page.
|
||||
ids = re.findall(r'output_id="([0-9a-f]{32})"', page)
|
||||
assert ids == [output_id.group(1)] or ids == []
|
||||
|
||||
|
||||
def test_read_stored_output_rejects_traversal(tmp_path: Path) -> None:
|
||||
configure_output_store(tmp_path)
|
||||
assert "Invalid output_id" in read_stored_output("../../etc/passwd")
|
||||
|
||||
Reference in New Issue
Block a user