refactor(exec): centralize process-tree lifecycle (#6623)
Co-authored-by: chengyongru <chengyongru.ai@gmail.com>
This commit is contained in:
1 parent
c37af82e3f
commit
8607b6445c
16 files changed
+356
-534
No files matched your search
@@ -20,6 +20,7 @@ from nanobot.agent.tools.exec_session import (
|
||||
)
|
||||
from nanobot.agent.tools.registry import is_tool_error_result
|
||||
from nanobot.agent.tools.shell import ExecTool
|
||||
from nanobot.execution import processes
|
||||
|
||||
|
||||
def _python(code: str) -> list[str]:
|
||||
@@ -443,11 +444,12 @@ async def test_execution_stop_stops_pipe_inheriting_child_after_root_exits(
|
||||
if not early_root_exit:
|
||||
parent_code += f"while not Path({str(release_root)!r}).exists(): time.sleep(0.02)\n"
|
||||
|
||||
real_spawn = ExecTool._spawn
|
||||
real_spawn = processes.spawn_process_tree
|
||||
spawn_returned = asyncio.Event()
|
||||
|
||||
async def spawn_with_exit_order(*args, **kwargs):
|
||||
process = await real_spawn(*args, **kwargs)
|
||||
tree = await real_spawn(*args, **kwargs)
|
||||
process = tree.process
|
||||
if early_root_exit:
|
||||
async with asyncio.timeout(5):
|
||||
while process.returncode is None:
|
||||
@@ -456,9 +458,9 @@ async def test_execution_stop_stops_pipe_inheriting_child_after_root_exits(
|
||||
else:
|
||||
assert process.returncode is None
|
||||
spawn_returned.set()
|
||||
return process
|
||||
return tree
|
||||
|
||||
monkeypatch.setattr(ExecTool, "_spawn", staticmethod(spawn_with_exit_order))
|
||||
monkeypatch.setattr(processes, "spawn_process_tree", spawn_with_exit_order)
|
||||
owner = RequestContext(channel="cli", chat_id="pipe-budget", session_key="cli:pipe-budget")
|
||||
manager = ExecSessionManager()
|
||||
max_runtime = 12 if stop_reason == "owner_closed" else 2
|
||||
|
||||
Reference in new issue
Block a user