Skip to content

The agent that grows with you

fix(gateway): alias the reserved 'hermes' handle to the default profile on /p/<profile>/ mirrors

chelsealongf9d8bc31e43b
diff --git a/gateway/platforms/api_server.py b/gateway/platforms/api_server.py
index 06a641eb4ca..8e49568f526 100644
--- a/gateway/platforms/api_server.py
+++ b/gateway/platforms/api_server.py
@@ -1515,7 +1515,15 @@ class APIServerAdapter(OpenAICompatRoutesMixin, BasePlatformAdapter):
served = {name for name, _ in profiles_to_serve(multiplex=True)}
except Exception:
return _PROFILE_REJECTED
- return profile if profile in served else _PROFILE_REJECTED
+ if profile in served:
+ return profile
+ # 'hermes' is the reserved @handle a peer always advertises its default profile
+ # under (apps/desktop hermes-bots/data.ts:botHandle), never a real profile name.
+ # Addressing the mirror by that handle must reach the same profile it labels
+ # (#118076), unless a profile is actually named 'hermes'.
+ if profile == "hermes" and "hermes" not in served and "default" in served:
+ return "default"
+ return _PROFILE_REJECTED
@staticmethod
def _profile_scope(profile: Optional[str]):
diff --git a/tests/gateway/test_multiplex_api_server_routing.py b/tests/gateway/test_multiplex_api_server_routing.py
index 9fc9b057283..24efcdf3838 100644
--- a/tests/gateway/test_multiplex_api_server_routing.py
+++ b/tests/gateway/test_multiplex_api_server_routing.py
@@ -56,6 +56,41 @@ class TestApiServerProfileResolution:
is _PROFILE_REJECTED
)
+ def test_hermes_handle_aliases_to_default_profile(self, monkeypatch):
+ """A peer advertises its default profile's @handle as 'hermes' (botHandle()), but the
+ mirror is keyed by profile name — '/p/hermes/' must reach the same profile '/p/default/'
+ does (#118076), not 404."""
+ adapter = _make_adapter(multiplex=True)
+ monkeypatch.setattr(
+ "hermes_cli.profiles.profiles_to_serve",
+ lambda multiplex: [
+ ("default", "/profiles/default"),
+ ("worker", "/profiles/worker"),
+ ],
+ )
+
+ assert (
+ adapter._resolve_request_profile(cast(Any, _FakeReq("hermes")))
+ == "default"
+ )
+
+ def test_real_hermes_profile_is_not_shadowed_by_the_alias(self, monkeypatch):
+ """A gateway that genuinely serves a profile literally named 'hermes' must keep
+ resolving to itself, never silently redirect to 'default'."""
+ adapter = _make_adapter(multiplex=True)
+ monkeypatch.setattr(
+ "hermes_cli.profiles.profiles_to_serve",
+ lambda multiplex: [
+ ("default", "/profiles/default"),
+ ("hermes", "/profiles/hermes"),
+ ],
+ )
+
+ assert (
+ adapter._resolve_request_profile(cast(Any, _FakeReq("hermes")))
+ == "hermes"
+ )
+