Skip to content

The agent that grows with you

fix(gateway): key the status fold on the profile name, not the root basename

liuhao1024dae66906da14
diff --git a/hermes_cli/web_routers/status.py b/hermes_cli/web_routers/status.py
index faab5ffd33f..6309c7c6787 100644
--- a/hermes_cli/web_routers/status.py
+++ b/hermes_cli/web_routers/status.py
@@ -308,7 +308,12 @@ async def _resolve_gateway_status(profile_dir: Optional[Path], health_url) -> Di
# Served by the multiplexer: its record is this profile's runtime, with the profile's own
# adapters under ``<profile>:<platform>`` re-keyed to the standalone shape. Unscoped, the
# profile is the process's own home (a pooled ``hermes --profile X serve``).
- served_name = profile_dir.name if profile_dir is not None else profile_name_for_home(get_process_hermes_home())
+ # The fold keys on the profile NAME, never the directory basename: scoped to "default" the
+ # resolved dir IS the root (".hermes" or any custom HERMES_HOME name), so ``profile_dir.name``
+ # never matched — the scoped readout kept ``gateway_platforms: {}`` while bare /api/status
+ # was already fixed, and the basename read as a named id, fabricating ``/p/<basename>/``
+ # mirror URLs (#123088, same defect as the messaging call site).
+ served_name = profile_name_for_home(profile_dir or get_process_hermes_home())
runtime = {**liveness.runtime,
"platforms": profile_platforms_from_multiplexer(liveness.runtime, served_name or "")}
diff --git a/tests/hermes_cli/test_web_server_gateway_topology.py b/tests/hermes_cli/test_web_server_gateway_topology.py
index 5a6e6a7db3a..5330bd21904 100644
--- a/tests/hermes_cli/test_web_server_gateway_topology.py
+++ b/tests/hermes_cli/test_web_server_gateway_topology.py
@@ -380,6 +380,69 @@ class TestStatusEndpointTopology:
assert data["components"]["platforms"]["configured"] == 2
assert data["components"]["platforms"]["connected"] == 2
+ def test_profile_scoped_status_folds_default_flat_adapters_on_default_root(self, monkeypatch, tmp_path):
+ # ?profile=default resolves the DEFAULT ROOT directory itself — the shipped root is
+ # ``~/.hermes``, so the directory's basename (".hermes") is not the profile id. The
+ # re-key used to fold on that basename: the multiplexer rung's flat keys never matched
+ # (the ``gateway_platforms: {}`` symptom of #123088, one call site over from the fix
+ # bare /api/status got), and the basename read as a NAMED profile, so the mirror arm
+ # fabricated ``/p/<basename>/...`` ingress URLs for a profile that does not exist.
+ from contextlib import nullcontext
+
+ from gateway.status import GatewayLiveness
+ import hermes_cli.web_routers.status as status_router
+ import hermes_cli.web_server_profiles as web_server_profiles
+
+ home = tmp_path / ".hermes" # the shipped default root: basename != profile id
+ home.mkdir()
+ # The resolver names a default root by IDENTITY, not basename: only the root the
+ # process resolves (HERMES_HOME here) folds as "default".
+ monkeypatch.setenv("HERMES_HOME", str(home))
+ record = {
+ "gateway_state": "running",
+ "served_profiles": ["default", "coder"],
+ "platforms": {
+ "telegram": {"state": "connected", "writer_pid": 101, "writer_start_time": 5},
+ "webhook": {"state": "connected"},
+ "coder:discord": {"state": "connected"},
+ },
+ }
+ monkeypatch.setattr(web_server_profiles, "_resolve_profile_dir", lambda name: home)
+ monkeypatch.setattr(web_server_profiles, "_config_profile_scope", lambda profile: nullcontext())
+ monkeypatch.setattr(
+ status_router, "resolve_gateway_liveness",
+ lambda **kwargs: GatewayLiveness(
+ running=True, pid=4242, source="multiplexer", runtime=record))
+ monkeypatch.setattr(
+ _web_server_gateway,
+ "_load_configured_gateway_platforms",
+ lambda: {"telegram", "webhook"},
+ )
+ monkeypatch.setattr(
+ _web_server_gateway, "_collect_profile_gateway_topology",
+ lambda: {
+ "profiles": ["default", "coder"],
+ "gateway_mode": "multiplex",
+ "gateways": [],
+ "profile_platforms": {},
+ },
+ )
+
+ resp = self.client.get("/api/status", params={"profile": "default"})
+
+ assert resp.status_code == 200
+ data = resp.json()
+ platforms = data["gateway_platforms"]
+ assert platforms["telegram"]["state"] == "connected"
+ assert "writer_pid" not in platforms["telegram"]
+ assert platforms["webhook"]["state"] == "connected"
+ # The default's own adapters are never presented as shared-listener mirrors.
+ assert "mirrored_from" not in platforms["webhook"]
+ # A secondary's entry never projects onto the default's readout.
+ assert "coder:discord" not in platforms
+ assert data["components"]["platforms"]["configured"] == 2
+ assert data["components"]["platforms"]["connected"] == 2
+
def test_status_rejects_malformed_namespaced_platform_key(self, monkeypatch):
monkeypatch.setattr(_gw_status, "get_running_pid_cached", lambda: 123)
monkeypatch.setattr(