Skip to content

The agent that grows with you

fix(dashboard): /api/status reports only the ports the live gateway binds

John Paul Soliva4935536e2a38
diff --git a/hermes_cli/web_server_gateway.py b/hermes_cli/web_server_gateway.py
index fafb4beb6c2..c4b00ee8dc3 100644
--- a/hermes_cli/web_server_gateway.py
+++ b/hermes_cli/web_server_gateway.py
@@ -172,11 +172,14 @@ def _collect_profile_gateway_topology() -> Dict[str, Any]:
if name == "default" and len(served) > 1:
multiplex = True
plats = (runtime or {}).get("platforms")
+ owned: dict = {}
if isinstance(plats, dict) and plats:
owned = _owned_profile_platforms(_profile_gateway_writer_identity(home, runtime), plats)
if owned:
profile_platforms[name] = owned
- entry: Dict[str, Any] = {"profile": name, "ports": _profile_platform_ports(home, runtime)}
+ # Ports from the OWNED entries too: a platform entry a previous process left "connected"
+ # reported a port the live gateway does not bind.
+ entry: Dict[str, Any] = {"profile": name, "ports": _profile_platform_ports(home, {"platforms": owned})}
if served:
entry["served_profiles"] = served
gateways.append(entry)
diff --git a/tests/hermes_cli/test_web_server_gateway_topology.py b/tests/hermes_cli/test_web_server_gateway_topology.py
index a0b98ba8bf9..bf1b85a6b59 100644
--- a/tests/hermes_cli/test_web_server_gateway_topology.py
+++ b/tests/hermes_cli/test_web_server_gateway_topology.py
@@ -202,6 +202,29 @@ class TestCollectProfileGatewayTopology:
topo = _collect_profile_gateway_topology()
assert set(topo["profile_platforms"].get("coder", {})) == {"signal"}
+ def test_a_stale_platform_entry_reports_no_port(self, tmp_path, monkeypatch):
+ # The live case: a Feishu entry left "connected" by a gateway process from a week earlier
+ # (the platform has since been removed) put its port into ``gateways[].ports`` beside the
+ # ports the live gateway really binds. Ports follow the same writer-identity ownership as
+ # the platform map: a port the current process does not bind is not reported.
+ homes = [("default", tmp_path / "d")]
+ runtimes = {
+ "default": {
+ "platforms": {
+ "api_server": {"state": "connected", "writer_pid": 200, "writer_start_time": 222},
+ "feishu": {"state": "connected", "writer_pid": 34105, "writer_start_time": 178945520374},
+ }
+ },
+ }
+ _patch_topology(monkeypatch, homes, running={"default"}, runtimes=runtimes)
+ monkeypatch.setattr(
+ _web_server_gateway,
+ "_profile_gateway_writer_identity",
+ lambda home, runtime: (200, 222),
+ )
+ topo = _collect_profile_gateway_topology()
+ assert set(topo["gateways"][0]["ports"]) == {"api_server"}
+
def test_no_live_process_means_no_aggregation(self, tmp_path, monkeypatch):
# When the record's PID doesn't validate against a live gateway
# process, nothing in it is current — the whole map is excluded.