Skip to content

Your lightweight open-source personal agent.

fix(subagent): cascade exec session termination on /stop

yorkhellen7b1d81a868f3
diff --git a/nanobot/agent/subagent.py b/nanobot/agent/subagent.py
index 74d1eab42..4743e0429 100644
--- a/nanobot/agent/subagent.py
+++ b/nanobot/agent/subagent.py
@@ -457,6 +457,7 @@ class SubagentManager:
t.cancel()
if tasks:
await asyncio.gather(*tasks, return_exceptions=True)
+ await self._exec_session_manager.terminate_by_owner(session_key)
return len(tasks)
async def close(self) -> None:
diff --git a/nanobot/agent/tools/exec_session.py b/nanobot/agent/tools/exec_session.py
index 24738dfc1..2fad2e0b8 100644
--- a/nanobot/agent/tools/exec_session.py
+++ b/nanobot/agent/tools/exec_session.py
@@ -334,6 +334,19 @@ class ExecSessionManager:
)
return len(sessions)
+ async def terminate_by_owner(self, owner_session_key: str) -> int:
+ """Terminate all sessions owned by owner_session_key. Returns count."""
+ async with self._lock:
+ victims = []
+ for sid, s in list(self._sessions.items()):
+ if s.owner_session_key == owner_session_key:
+ victims.append(self._sessions.pop(sid))
+ await asyncio.gather(
+ *(s.kill() for s in victims),
+ return_exceptions=True,
+ )
+ return len(victims)
+
async def _cleanup_locked(self) -> None:
now = time.monotonic()
stale = [