Skip to content

The agent that grows with you

fix(gateway): unmanaged launch of the default profile ignores a sticky active_profile

teknium1cf94baf2c835
diff --git a/hermes_cli/gateway_runtime_start.py b/hermes_cli/gateway_runtime_start.py
index 973027f91b9..3ba95e0fdb4 100644
--- a/hermes_cli/gateway_runtime_start.py
+++ b/hermes_cli/gateway_runtime_start.py
@@ -18,7 +18,11 @@ def spawn_unmanaged_gateway(profile_home: Path, *, deadline: float) -> subproces
"""
home = profile_home.resolve()
root = Path(__file__).resolve().parent.parent
- command = [sys.executable, "-m", "hermes_cli.main", "gateway", "run", "--quiet"]
+ # A root home is only pinned by an explicit selector: without one the child's
+ # _apply_profile_override follows the sticky active_profile and boots the wrong
+ # profile's daemon. A <root>/profiles/<name> home is already trusted as-is.
+ selector = [] if home.parent.name == "profiles" else ["--profile", "default"]
+ command = [sys.executable, "-m", "hermes_cli.main", *selector, "gateway", "run", "--quiet"]
env = dict(os.environ)
if sys.platform == "win32":
from hermes_cli.gateway_windows import windowless_gateway_restart_spec
diff --git a/tests/hermes_cli/test_gateway_runtime_ensure.py b/tests/hermes_cli/test_gateway_runtime_ensure.py
index f9431a4eb5c..ff258d18ebc 100644
--- a/tests/hermes_cli/test_gateway_runtime_ensure.py
+++ b/tests/hermes_cli/test_gateway_runtime_ensure.py
@@ -277,3 +277,37 @@ def test_native_launchd_ambiguous_domains_cannot_start(tmp_path, monkeypatch):
with pytest.raises(RuntimeStartError, match="service_scope_conflict"):
discover_existing_gateway_service(tmp_path.resolve(), deadline=time.monotonic()+5)
assert len(calls) == 2 and all(argv[1] == "print" for argv in calls)
+
+
[email protected]_gateway_lookalike # stub interpreter records the resolved home then exits; reaped below
+def test_unmanaged_root_home_child_ignores_sticky_active_profile(tmp_path, monkeypatch):
+ """Explicit default selection survives the CLI child's own profile bootstrap (F15): with
+ active_profile=other sticky, the spawned `gateway run` must still resolve the root home."""
+ from hermes_cli import gateway_runtime_start as start
+ root = tmp_path / ".hermes"
+ (root / "profiles" / "other").mkdir(parents=True)
+ (root / "active_profile").write_text("other", encoding="utf-8")
+ witness = tmp_path / "resolved.json"
+ real = start.subprocess.Popen
+
+ def boundary(argv, **kwargs):
+ assert argv[:3] == [sys.executable, "-m", "hermes_cli.main"]
+ # Same argv and env as the real child; the module-import bootstrap is what resolves the profile.
+ code = ("import json, os, sys\nsys.argv = ['hermes', *sys.argv[1:]]\nimport hermes_cli.main\n"
+ f"open({str(witness)!r}, 'w').write(json.dumps({{'home': os.environ['HERMES_HOME'], 'argv': sys.argv}}))")
+ return real([sys.executable, "-c", code, *argv[3:]], **kwargs)
+
+ monkeypatch.setattr(start.subprocess, "Popen", boundary)
+ monkeypatch.setenv("HOME", str(tmp_path))
+ monkeypatch.setenv("PYTHONPATH", str(Path(__file__).resolve().parents[2]))
+ child = start.spawn_unmanaged_gateway(root, deadline=time.monotonic() + 5)
+ try:
+ assert child.wait(timeout=30) == 0
+ finally:
+ if child.poll() is None:
+ child.kill()
+ child.wait(timeout=5)
+ resolved = json.loads(witness.read_text())
+ assert resolved["home"] == str(root), resolved
+ assert resolved["argv"] == ["hermes", "gateway", "run", "--quiet"], resolved