Skip to content

The agent that grows with you

fix(gateway): keep the default profile's flat platforms in the multiplexer re-key

liuhao1024f373cff9d506
diff --git a/gateway/status.py b/gateway/status.py
index b8efbf169a4..858ddcc752f 100644
--- a/gateway/status.py
+++ b/gateway/status.py
@@ -1497,6 +1497,13 @@ def profile_platforms_from_multiplexer(runtime: Optional[dict[str, Any]], profil
prefix = f"{profile}:"
own = {key[len(prefix):]: value for key, value in plats.items()
if isinstance(key, str) and key.startswith(prefix) and isinstance(value, dict)}
+ if profile == "default":
+ # The record's flat keys ARE the default's own adapters — only secondaries get the
+ # ``<profile>:`` prefix — so the standalone shape promised above is the flat map itself.
+ # Without this arm, readers that re-key through this helper (``/api/status``) reported no
+ # platforms at all for the one profile the multiplexer records un-prefixed (#123088).
+ own.update({key: value for key, value in plats.items()
+ if isinstance(key, str) and ":" not in key and isinstance(value, dict)})
return {**shared_listener_mirror_platforms(runtime, profile), **own}
diff --git a/tests/hermes_cli/test_served_profile_mirror_platforms.py b/tests/hermes_cli/test_served_profile_mirror_platforms.py
index 26d976f3f2e..174e06e7f4e 100644
--- a/tests/hermes_cli/test_served_profile_mirror_platforms.py
+++ b/tests/hermes_cli/test_served_profile_mirror_platforms.py
@@ -70,6 +70,25 @@ def test_served_profile_projects_the_default_listener_mirrors_with_their_url(ser
assert "ingress_url" not in profile_platforms_from_multiplexer(live.runtime, "default").get("api_server", {})
+def test_default_profile_keeps_its_flat_adapters_when_rekeyed(served_root):
+ """The default's own adapters are the record's FLAT keys (only secondaries get the
+ ``<profile>:`` prefix), so re-keying the multiplexer record for ``default`` must keep them:
+ ``/api/status`` used to report ``gateway_platforms: {}`` for the default profile under
+ ``gateway.multiplex_profiles`` while its adapters were connected and delivering (#123088)."""
+ from gateway.status import profile_platforms_from_multiplexer, resolve_gateway_liveness
+ alpha = served_root / "profiles" / "alpha"
+ live = resolve_gateway_liveness(profile_dir=alpha, health_probe=None, use_cache=False)
+ plats = profile_platforms_from_multiplexer(live.runtime, "default")
+ # The default's un-prefixed entries survive the re-key, exactly as a standalone gateway for
+ # "default" would have written them — a live api_server and its own fatal webhook.
+ assert plats["api_server"]["state"] == "connected"
+ assert "listener_base" in plats["api_server"] # the listener's own entry, never a mirror
+ assert plats["webhook"]["state"] == "fatal"
+ # Nothing is mirrored onto the default and no secondary's entry leaks in.
+ assert all("ingress_url" not in entry for entry in plats.values() if isinstance(entry, dict))
+ assert "telegram" not in plats # that entry belongs to alpha
+
+
def test_messaging_card_for_a_served_profile_reads_connected_not_restart_needed(served_root, monkeypatch):
from hermes_cli.web_routers import messaging
monkeypatch.setattr(messaging, "_platform_enablement", lambda *a, **k: (True, True, None))
diff --git a/tests/hermes_cli/test_web_server_gateway_topology.py b/tests/hermes_cli/test_web_server_gateway_topology.py
index bf1b85a6b59..5a6e6a7db3a 100644
--- a/tests/hermes_cli/test_web_server_gateway_topology.py
+++ b/tests/hermes_cli/test_web_server_gateway_topology.py
@@ -336,6 +336,50 @@ class TestStatusEndpointTopology:
assert platforms["telegram"]["state"] == "connected"
assert platforms["reviewer:discord"]["error_code"] == "duplicate_credential"
+ def test_status_reports_the_default_profiles_flat_adapters_under_multiplex(self, monkeypatch):
+ # Under gateway.multiplex_profiles the default's own adapters are the FLAT keys of the
+ # multiplexer's record (only secondaries get ``<profile>:`` prefixes). /api/status
+ # re-keys the record through profile_platforms_from_multiplexer whenever the
+ # multiplexer rung answers, and that re-key used to keep only prefixed keys — so the
+ # one profile the record stores un-prefixed reported ``gateway_platforms: {}`` and
+ # ``components.platforms.configured: 0`` while its adapters were up and delivering
+ # (#123088).
+ from gateway.status import GatewayLiveness
+ import hermes_cli.web_routers.status as status_router
+
+ 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(
+ 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"},
+ )
+
+ resp = self.client.get("/api/status")
+
+ assert resp.status_code == 200
+ data = resp.json()
+ platforms = data["gateway_platforms"]
+ assert platforms["telegram"]["state"] == "connected"
+ # Writer-identity stamps stay private on the re-keyed map too.
+ assert "writer_pid" not in platforms["telegram"]
+ assert platforms["webhook"]["state"] == "connected"
+ # 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(