Skip to content

The agent that grows with you

fix(gateway): use the multiplexer record for an unscoped served-profile backend

unsupportedpastels1108bb080032
diff --git a/hermes_cli/web_routers/status.py b/hermes_cli/web_routers/status.py
index 7cf70917d98..ae72114b93a 100644
--- a/hermes_cli/web_routers/status.py
+++ b/hermes_cli/web_routers/status.py
@@ -312,14 +312,16 @@ async def _resolve_gateway_status(profile_dir: Optional[Path], health_url) -> di
if runtime is None and remote_health_body and remote_health_body.get("gateway_state"):
runtime = remote_health_body
mux_runtime = liveness.runtime
- if mux_runtime is None and gateway_running and profile_dir is not None:
+ if mux_runtime is None and gateway_running:
# The PID rung answers before the multiplexer rung, and a served profile's gateway.lock is
# held by the multiplexer itself, so the ladder returns without its record while the
# profile's own gateway_state.json may be a retired standalone gateway's (#139080). When the
# lock holder IS the multiplexer serving this profile, its record is the live one; a
# profile's own (--force) gateway holds the lock under a different PID and keeps its record.
try:
- served = await run_in_threadpool(multiplexer_liveness_for_profile, profile_dir)
+ # Unscoped, the profile is the process's own home (a named `hermes -p X serve`).
+ served = await run_in_threadpool(multiplexer_liveness_for_profile,
+ profile_dir or get_process_hermes_home())
except Exception: # health: allow BLE001 -- status route must never 500; traceback is logged
# A failed lookup keeps the profile's own record. A missing multiplexer record does
# not raise: the helper returns (pid, {}), which still replaces it on a PID match.
diff --git a/tests/hermes_cli/test_web_server_gateway_topology.py b/tests/hermes_cli/test_web_server_gateway_topology.py
index 28122726ad1..366ecc1133c 100644
--- a/tests/hermes_cli/test_web_server_gateway_topology.py
+++ b/tests/hermes_cli/test_web_server_gateway_topology.py
@@ -521,6 +521,32 @@ class TestStatusEndpointTopology:
assert data["gateway_platforms"]["telegram"]["state"] == "connected"
assert data["gateway_shared_with"] is None
+ def test_unscoped_status_on_a_served_profiles_own_backend_uses_multiplexer_record(self, monkeypatch, tmp_path):
+ # `hermes -p coder serve` answers plain /api/status (no ?profile=) for its own home. That
+ # home's gateway.lock is the multiplexer's too, so the same live record applies.
+ import hermes_cli.web_routers.status as status_router
+
+ self._scope_to_served_profile(
+ monkeypatch, tmp_path,
+ own_runtime={"gateway_state": "stopped", "platforms": {"telegram": {"state": "disconnected"}}},
+ lock_pid=4242, mux_pid=4242,
+ mux_runtime={
+ "gateway_state": "running",
+ "served_profiles": ["default", "coder"],
+ "platforms": {"telegram": {"state": "disconnected"},
+ "coder:telegram": {"state": "connected"}},
+ },
+ )
+ monkeypatch.setattr(status_router, "get_process_hermes_home", lambda: tmp_path / "profiles" / "coder")
+
+ resp = self.client.get("/api/status")
+
+ assert resp.status_code == 200
+ data = resp.json()
+ assert data["gateway_state"] == "running"
+ assert data["gateway_platforms"]["telegram"]["state"] == "connected"
+ assert data["gateway_shared_with"] == ["default", "coder"]
+
def test_profile_scoped_status_keeps_own_record_when_multiplexer_lookup_raises(self, monkeypatch, tmp_path):
# The multiplexer lookup is optional: a failure there must not 500 the status route or
# drop the record the ladder already selected.