Skip to content

The agent that grows with you

fix(gateway): a single-profile gateway start clears an inherited served_profiles list

teknium1aed011d88a0c
diff --git a/gateway/run_adapters.py b/gateway/run_adapters.py
index 2b8b940f7f7..1246f3542fe 100644
--- a/gateway/run_adapters.py
+++ b/gateway/run_adapters.py
@@ -829,6 +829,12 @@ class GatewayAdapterLifecycleMixin:
from gateway.run import MultiplexConfigError, _multiplex_profile_homes
from gateway.run_profile_reconcile import profile_serve_signature
if not self._multiplex_on():
+ # ``write_runtime_status`` re-stamps the previous writer's record in place, so a multiplexer's
+ # ``served_profiles`` would outlive it into this single-profile run and `hermes -p X ...`
+ # would keep refusing (exit 78) / reporting "served" for profiles nobody serves.
+ with _log_suppressed(logging.DEBUG, "could not clear served_profiles", exc_info=True):
+ from gateway.status import write_runtime_status
+ write_runtime_status(served_profiles=[])
return 0
try:
from hermes_cli.profiles import get_active_profile_name
diff --git a/tests/gateway/test_multiplex_adapter_registry.py b/tests/gateway/test_multiplex_adapter_registry.py
index ca0680edbcd..1165f237b63 100644
--- a/tests/gateway/test_multiplex_adapter_registry.py
+++ b/tests/gateway/test_multiplex_adapter_registry.py
@@ -865,6 +865,23 @@ class TestSecondaryProfileConfigHandling:
assert "bad" not in runner._profile_adapters
assert "Failed to start adapters for profile 'bad'" in caplog.text
+ @pytest.mark.asyncio
+ async def test_single_profile_start_clears_inherited_served_profiles(self, monkeypatch, tmp_path):
+ """``write_runtime_status`` re-stamps the previous writer's record in place, so a multiplexer's
+ ``served_profiles`` survived into a later single-profile run and every `hermes -p X` surface
+ kept treating X as served (exit 78 on start, "running via multiplexer" on status)."""
+ import json
+ from gateway.status import read_runtime_status
+
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))
+ (tmp_path / "gateway_state.json").write_text(json.dumps(
+ {"pid": 1, "gateway_state": "stopped", "served_profiles": ["default", "coder"]}))
+ runner = GatewayRunner.__new__(GatewayRunner)
+ runner.config = GatewayConfig(multiplex_profiles=False)
+
+ assert await runner._start_secondary_profile_adapters() == 0
+ assert read_runtime_status(tmp_path / "gateway_state.json")["served_profiles"] == []
+
@pytest.mark.asyncio
async def test_multiplexer_propagates_security_config_error(self, monkeypatch):
from pathlib import Path