Skip to content

The agent that grows with you

fix(terminal): session-less work for a routed profile keys its own terminal environment

teknium1551497dcbfd5
diff --git a/tests/tools/test_terminal_scope_multiplex.py b/tests/tools/test_terminal_scope_multiplex.py
index 1ad67eda64c..58ba7c7fcb0 100644
--- a/tests/tools/test_terminal_scope_multiplex.py
+++ b/tests/tools/test_terminal_scope_multiplex.py
@@ -110,7 +110,9 @@ def test_routed_turn_reads_every_terminal_consumer_from_profile(
assert cfg["cwd"] == str(b_cwd)
assert cfg["docker_volumes"] == []
assert cfg["docker_shared_container_key"] == ""
- assert tt._resolve_container_task_id(None) == "default"
+ # Session-less (cron) work for routed B keys B's own environment, never the launch
+ # profile's shared "default" one (which carries A's env and terminal policy).
+ assert tt._resolve_container_task_id(None) == f"home:{os.path.realpath(home)}"
assert gbase._parse_docker_volume_mounts() == []
assert not any(
"alpha-shared" in c for c in gbase._docker_sandbox_dir_candidates("agent:bee:x")
diff --git a/tools/terminal_tool.py b/tools/terminal_tool.py
index 80cfaf9fd04..998b7fcb22a 100644
--- a/tools/terminal_tool.py
+++ b/tools/terminal_tool.py
@@ -430,6 +430,25 @@ def _docker_session_isolation_enabled() -> bool:
return _session_scope().docker_session_isolated
+def _routed_home_task_key() -> Optional[str]:
+ """Key for a session-less task serving a routed (non-launch) profile home, else None.
+
+ A multiplexed host runs every profile's cron jobs without a session key; collapsing them all onto
+ ``"default"`` made profile B's cron tool calls reuse the environment the launch profile's job
+ created (its ``.env`` residue, its bridged ``TERMINAL_*``, its shell), so B ran with A's settings.
+ """
+ from hermes_constants import get_hermes_home_override
+ from tools.environments.local import _is_routed_home
+
+ override = get_hermes_home_override()
+ if not override or not _is_routed_home(override):
+ return None
+ try:
+ return f"home:{os.path.realpath(override)}"
+ except OSError:
+ return f"home:{override}"
+
+
def _resolve_container_task_id(task_id: Optional[str]) -> str:
"""Map a tool-call ``task_id`` to the ``_active_environments`` key. Order matters —
earlier branches are authoritative where they apply:
@@ -470,7 +489,7 @@ def _resolve_container_task_id(task_id: Optional[str]) -> str:
# ONE container/cache slot (and sandbox dir) regardless of profile name (#84671).
return f"shared:{shared}"
if not session_key:
- return "default"
+ return _routed_home_task_key() or "default"
if not scope.docker_profile_scoped:
return f"session:{session_key}"
profile = _current_session_profile() or "default"