fix(tools): scope file state by session

Made-with: Cursor
This commit is contained in:
Xubin Ren
2026-05-01 19:15:07 +08:00
committed by Xubin Ren
parent 58ae2d5b7e
commit fae38319ca
4 changed files with 102 additions and 37 deletions
+30
View File
@@ -127,6 +127,36 @@ class TestReadDedupSessionIsolation:
)
assert "line 0" in second
@pytest.mark.asyncio
async def test_shared_loop_tool_uses_bound_session_state(self, tmp_path):
f = tmp_path / "shared.txt"
f.write_text("\n".join(f"line {i}" for i in range(10)), encoding="utf-8")
# AgentLoop registers one shared ReadFileTool instance. The session
# boundary is the task-local FileStates binding, not the tool object.
shared_tool = ReadFileTool(workspace=tmp_path)
session_a = file_state.FileStates()
session_b = file_state.FileStates()
token = file_state.bind_file_states(session_a)
try:
first = await shared_tool.execute(path=str(f))
repeat = await shared_tool.execute(path=str(f))
finally:
file_state.reset_file_states(token)
assert "line 0" in first
assert "unchanged" in repeat.lower()
token = file_state.bind_file_states(session_b)
try:
second_session_read = await shared_tool.execute(path=str(f))
finally:
file_state.reset_file_states(token)
assert "unchanged" not in second_session_read.lower()
assert "line 0" in second_session_read
# ---------------------------------------------------------------------------
# PDF support