Skip to content

The agent that grows with you

fix(delegation): a profile child uses the target profile's persistent container

Teknium5b9387a62739
diff --git a/tests/tools/test_delegation_profile_route.py b/tests/tools/test_delegation_profile_route.py
index 63d54f98bf0..b3278dddc26 100644
--- a/tests/tools/test_delegation_profile_route.py
+++ b/tests/tools/test_delegation_profile_route.py
@@ -346,3 +346,23 @@ def test_profile_child_reads_the_starting_directory_seeded_for_it(two_profiles,
assert get_session_cwd(run.child_task_id) == (worktree or {}).get("path", "/work/repo")
finally:
clear_session_cwd("parent-task")
+
+
+def test_profile_child_uses_the_target_profiles_persistent_container(two_profiles):
+ """Persistent Docker keys its container by profile: a child routed to ``coder`` inside a launch-profile
+ session runs in coder's container (coder's image, mounts, env), while the session's delivery identity
+ (HERMES_SESSION_PROFILE, read by notifications) stays the parent's."""
+ from gateway.session_context import clear_session_vars, get_session_env, set_session_vars
+ from tools import terminal_tool
+ from tools.delegate_tool_routes import delegated_profile_scope
+
+ _, coder = two_profiles
+ _set_config(coder, terminal={"backend": "docker", "container_persistent": True})
+ tokens = set_session_vars(session_key="agent:main:telegram:dm:1", profile="default")
+ try:
+ with delegated_profile_scope(coder):
+ assert terminal_tool._resolve_container_task_id("child-task") == "profile:coder"
+ assert get_session_env("HERMES_SESSION_PROFILE", "") == "default"
+ finally:
+ clear_session_vars(tokens)
+
diff --git a/tools/terminal_tool.py b/tools/terminal_tool.py
index cbde564d30e..2006af241ea 100644
--- a/tools/terminal_tool.py
+++ b/tools/terminal_tool.py
@@ -118,6 +118,19 @@ def _current_session_profile() -> str:
return get_session_env("HERMES_SESSION_PROFILE", "")
+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."""
+ 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"
+
+
from tools.approval import (
check_all_command_guards as _check_all_guards_impl,
)
@@ -518,7 +531,7 @@ def _resolve_container_task_id(task_id: Optional[str]) -> str:
return _routed_home_task_key(scope.docker_profile_scoped) or "default"
if not scope.docker_profile_scoped:
return _qualify_task_key(f"session:{session_key}")
- profile = _current_session_profile() or "default"
+ profile = _container_profile()
base = "default" if profile == "default" else f"profile:{profile}"
return _workspace_container_key(base, task_id)