Skip to content

The agent that grows with you

fix(dashboard): preserve exported terminal overrides

Gille3a8172114707
diff --git a/hermes_cli/web_server.py b/hermes_cli/web_server.py
index 23dd7b53132..944ad9e0ca8 100644
--- a/hermes_cli/web_server.py
+++ b/hermes_cli/web_server.py
@@ -16382,21 +16382,29 @@ def _resolve_chat_argv(
from hermes_cli.config import (
TERMINAL_CONFIG_ENV_MAP,
apply_terminal_config_to_env,
+ read_raw_config,
)
if profile_dir is not None:
# The dashboard process already bridged its own terminal config
- # into os.environ at startup. build_subprocess_env() snapshots that
- # process env, so remove every bridged value before applying the
- # selected profile or omitted keys leak from the launch profile.
- for env_var in TERMINAL_CONFIG_ENV_MAP.values():
+ # into os.environ at startup. Remove only keys explicitly owned by
+ # that launch profile before applying the selected profile. Values
+ # exported by the operator for keys omitted from the launch profile
+ # remain valid fallbacks, matching apply_terminal_config_to_env().
+ raw_launch_terminal = read_raw_config().get("terminal")
+ if not isinstance(raw_launch_terminal, dict):
+ raw_launch_terminal = {}
+ for config_key in raw_launch_terminal:
+ env_var = TERMINAL_CONFIG_ENV_MAP.get(config_key)
+ if env_var is None:
+ continue
env.pop(env_var, None)
with _config_profile_scope(requested):
apply_terminal_config_to_env(env=env)
else:
apply_terminal_config_to_env(env=env)
except Exception:
- _log.debug("Failed to apply terminal config bridge for dashboard chat", exc_info=True)
+ _log.warning("Failed to apply terminal config bridge for dashboard chat", exc_info=True)
_apply_tui_python_env(env)
env.setdefault("NODE_ENV", "production")
# Browser-embedded chat should prefer stable wheel-based scrollback over
diff --git a/tests/hermes_cli/test_web_server_profile_unification.py b/tests/hermes_cli/test_web_server_profile_unification.py
index db941056e1d..3cc479777e1 100644
--- a/tests/hermes_cli/test_web_server_profile_unification.py
+++ b/tests/hermes_cli/test_web_server_profile_unification.py
@@ -655,6 +655,12 @@ class TestProfileScopedChatPty:
):
import hermes_cli.web_server as web_server
+ (isolated_profiles["default"] / "config.yaml").write_text(
+ "terminal:\n"
+ " backend: docker\n"
+ " docker_image: launch-profile-image\n",
+ encoding="utf-8",
+ )
(isolated_profiles["worker_beta"] / "config.yaml").write_text(
"terminal:\n"
" backend: ssh\n"
@@ -664,7 +670,7 @@ class TestProfileScopedChatPty:
)
monkeypatch.setenv("TERMINAL_ENV", "docker")
monkeypatch.setenv("TERMINAL_DOCKER_IMAGE", "launch-profile-image")
- monkeypatch.setenv("TERMINAL_SSH_USER", "launch-profile-user")
+ monkeypatch.setenv("TERMINAL_SSH_USER", "operator-user")
monkeypatch.setattr(
"hermes_cli.main._make_tui_argv",
lambda root, tui_dev=False: (["cat"], None),
@@ -679,7 +685,56 @@ class TestProfileScopedChatPty:
assert env["TERMINAL_SSH_HOST"] == "worker.example.test"
assert env["TERMINAL_CWD"] == "~"
assert env["TERMINAL_DOCKER_IMAGE"] != "launch-profile-image"
- assert "TERMINAL_SSH_USER" not in env
+ assert env["TERMINAL_SSH_USER"] == "operator-user"
+
+ def test_chat_argv_default_profile_preserves_exported_terminal_values(
+ self, isolated_profiles, monkeypatch
+ ):
+ import hermes_cli.web_server as web_server
+
+ (isolated_profiles["default"] / "config.yaml").write_text(
+ "terminal:\n backend: docker\n",
+ encoding="utf-8",
+ )
+ monkeypatch.setenv("TERMINAL_ENV", "docker")
+ monkeypatch.setenv("TERMINAL_SSH_USER", "operator-user")
+ monkeypatch.setattr(
+ "hermes_cli.main._make_tui_argv",
+ lambda root, tui_dev=False: (["cat"], None),
+ raising=False,
+ )
+
+ _argv, _cwd, env = web_server._resolve_chat_argv()
+
+ assert env is not None
+ assert env["TERMINAL_ENV"] == "docker"
+ assert env["TERMINAL_SSH_USER"] == "operator-user"
+
+ def test_chat_argv_warns_when_profile_terminal_bridge_fails(
+ self, isolated_profiles, monkeypatch, caplog
+ ):
+ import logging
+
+ import hermes_cli.config as config_mod
+ import hermes_cli.web_server as web_server
+
+ monkeypatch.setattr(
+ "hermes_cli.main._make_tui_argv",
+ lambda root, tui_dev=False: (["cat"], None),
+ raising=False,
+ )
+ monkeypatch.setattr(
+ config_mod,
+ "apply_terminal_config_to_env",
+ lambda **kwargs: (_ for _ in ()).throw(RuntimeError("bridge failed")),
+ )
+
+ with caplog.at_level(logging.WARNING, logger=web_server._log.name):
+ _argv, _cwd, env = web_server._resolve_chat_argv(profile="worker_beta")
+
+ assert env is not None
+ assert env["HERMES_HOME"] == str(isolated_profiles["worker_beta"])
+ assert "Failed to apply terminal config bridge for dashboard chat" in caplog.text
class TestProfileScopedAudio: