fix(exec): clean up sessions on shutdown

This commit is contained in:
KDB
2026-07-21 13:48:51 +08:00
committed by Xubin Ren
parent 7cf3c71e3a
commit 8981995474
10 changed files with 390 additions and 12 deletions
+1
View File
@@ -37,6 +37,7 @@ def _make_loop(tmp_path):
patch("nanobot.agent.loop.SessionManager"), \
patch("nanobot.agent.loop.SubagentManager") as mock_sub_mgr:
mock_sub_mgr.return_value.cancel_by_session = AsyncMock(return_value=0)
mock_sub_mgr.return_value.close = AsyncMock()
loop = AgentLoop(bus=bus, provider=provider, workspace=tmp_path)
return loop
+18
View File
@@ -65,6 +65,24 @@ async def _drain_subagent_tasks(sm: SubagentManager) -> None:
await asyncio.sleep(0)
@pytest.mark.asyncio
async def test_close_cancels_tasks_before_closing_exec_sessions(tmp_path):
sm = _manager(tmp_path)
task = asyncio.create_task(asyncio.Event().wait())
sm._running_tasks["t1"] = task
async def close_exec_sessions() -> int:
assert task.done()
return 0
sm._exec_session_manager.close_all = AsyncMock(side_effect=close_exec_sessions)
await sm.close()
assert task.cancelled()
sm._exec_session_manager.close_all.assert_awaited_once()
# ---------------------------------------------------------------------------
# SubagentStatus defaults
# ---------------------------------------------------------------------------