Skip to content

The agent that grows with you

fix(delegation): a child routed back to the launch profile uses its container

Tekniumc68b1847ba84
diff --git a/tests/tools/test_delegation_profile_route.py b/tests/tools/test_delegation_profile_route.py
index 025172f2e20..d36d052af05 100644
--- a/tests/tools/test_delegation_profile_route.py
+++ b/tests/tools/test_delegation_profile_route.py
@@ -366,3 +366,23 @@ def test_profile_child_uses_the_target_profiles_persistent_container(two_profile
finally:
clear_session_vars(tokens)
+
+def test_child_routed_back_to_the_launch_profile_uses_the_launch_profiles_container(two_profiles):
+ """A ``coder`` chat on a default-launched gateway (its turn bound to coder, HERMES_SESSION_PROFILE=coder) routing
+ a child to ``default`` runs that child in default's persistent container, not the parent chat's."""
+ from gateway.session_context import clear_session_vars, set_session_vars
+ from tools import terminal_tool
+ from tools.delegate_tool_routes import delegated_profile_scope
+
+ launch, coder = two_profiles
+ for home in (launch, coder):
+ _set_config(home, terminal={"backend": "docker", "container_persistent": True})
+ tokens = set_session_vars(session_key="agent:coder:telegram:dm:1", profile="coder")
+ try:
+ with delegated_profile_scope(coder):
+ assert terminal_tool._resolve_container_task_id("parent-task") == "profile:coder"
+ with delegated_profile_scope(launch):
+ assert terminal_tool._resolve_container_task_id("child-task") == "default"
+ assert terminal_tool._resolve_container_task_id("parent-task") == "profile:coder"
+ finally:
+ clear_session_vars(tokens)
diff --git a/tools/terminal_tool.py b/tools/terminal_tool.py
index 2006af241ea..c6dd30c15f2 100644
--- a/tools/terminal_tool.py
+++ b/tools/terminal_tool.py
@@ -119,16 +119,20 @@ def _current_session_profile() -> str:
def _container_profile() -> str:
- """Profile whose persistent container a session-bound command uses: a bound routed (non-launch) home's
- profile (a profile-routed subagent runs in its target's home while the session, and the delivery identity
- HERMES_SESSION_PROFILE carries, stay the parent's), else the session's. The launch home's own work keeps
- the session's key whatever the launch profile is named."""
+ """Profile whose persistent container a session-bound command uses: the bound home's profile when it is not
+ the session's own (a profile-routed subagent runs in its target's home while the session, and the delivery
+ identity HERMES_SESSION_PROFILE carries, stay the parent's; that target may be the launch profile, reached
+ from a routed profile's chat), else the session's. A session with no profile name is the launch profile's,
+ so the launch home's own work keeps the session's key whatever the launch profile is named."""
from hermes_constants import get_hermes_home_override, profile_name_for_home
from tools.environments.local import _is_routed_home
override = get_hermes_home_override()
- routed = profile_name_for_home(override) if override and _is_routed_home(override) else None
- return routed or _current_session_profile() or "default"
+ session = _current_session_profile()
+ bound = profile_name_for_home(override) if override else None
+ if bound and (bound != session if session else _is_routed_home(override)):
+ return bound
+ return session or "default"
from tools.approval import (