fix(my): scope subagent snapshots to the current session (#5976)
* fix(my): scope subagent snapshots to the current session * test(my): reuse runtime fixture in session isolation checks
This commit is contained in:
1 parent
f18423800e
commit
66f5f2df15
6 files changed
+102
-6
No files matched your search
@@ -169,6 +169,17 @@ class SubagentManager:
|
||||
"""Return the observable task statuses used by runtime-control snapshots."""
|
||||
return self._task_statuses
|
||||
|
||||
def statuses_for_session(self, session_key: str | None) -> Mapping[str, SubagentStatus]:
|
||||
"""Return only tasks owned by the given session, never a global fallback."""
|
||||
if not session_key:
|
||||
return {}
|
||||
task_ids = self._session_tasks.get(session_key, set())
|
||||
return {
|
||||
task_id: status
|
||||
for task_id, status in self._task_statuses.items()
|
||||
if task_id in task_ids
|
||||
}
|
||||
|
||||
def set_provider(self, provider: LLMProvider, model: str) -> None:
|
||||
"""Update the deprecated runtime source used by legacy ``spawn`` calls."""
|
||||
warnings.warn(
|
||||
|
||||
@@ -7,6 +7,8 @@ from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Protocol, TypeAlias, runtime_checkable
|
||||
|
||||
from nanobot.agent.tools.context import current_request_session_key
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from nanobot.agent.subagent import SubagentManager, SubagentStatus
|
||||
from nanobot.agent.tools.shell import ExecToolConfig
|
||||
@@ -268,7 +270,7 @@ def _snapshot_subagent_statuses(
|
||||
) -> dict[str, dict[str, object]]:
|
||||
return {
|
||||
task_id: _snapshot_subagent_status(status)
|
||||
for task_id, status in manager.runtime_statuses().items()
|
||||
for task_id, status in manager.statuses_for_session(current_request_session_key()).items()
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -393,6 +393,10 @@ class MyTool(Tool):
|
||||
def _inspect(self, key: str | None) -> str:
|
||||
if not key:
|
||||
return self._inspect_all()
|
||||
if key == "subagents" or key.startswith("subagents."):
|
||||
request_ctx = current_request_context()
|
||||
if request_ctx is None or not request_ctx.session_key:
|
||||
return ToolResult.error("Error: current session context is unavailable")
|
||||
if key == "request" or key.startswith("request."):
|
||||
request_ctx = current_request_context()
|
||||
if request_ctx is None:
|
||||
|
||||
Reference in new issue
Block a user