The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): GATEWAY_RELAY_URL env stamp disables direct messaging platforms
Ben Barclay67292ec5b81d
diff --git a/gateway/config.py b/gateway/config.pyindex a00fa0f9a1c..590bb5ebe86 100644--- a/gateway/config.py+++ b/gateway/config.py@@ -2761,5 +2761,39 @@ def _apply_env_overrides(config: GatewayConfig) -> None:relay_config = _enable_from_env(Platform.RELAY)relay_config.extra["relay_url"] = relay_url_val.rstrip("/")+ # Relay-exclusive: a GATEWAY_RELAY_URL env stamp marks a connector-fronted+ # deployment where the connector owns every platform connection. Any+ # directly-connected messaging adapter in the same process would be a+ # second, unmanaged ingress path (duplicate deliveries, split sessions,+ # and a live socket that disarms scale-to-zero), so the env stamp disables+ # all other messaging platforms — including ones explicitly enabled in+ # config.yaml. Non-messaging surfaces (local, api_server, webhook — the+ # same exclusion set as the scale-to-zero arm gate) are untouched.+ # Deployments that configure relay only via gateway.relay_url in+ # config.yaml keep the old additive behavior (relay beside direct+ # adapters).+ if relay_url_env:+ non_messaging = {Platform.LOCAL, Platform.API_SERVER, Platform.WEBHOOK}+ for platform, platform_config in config.platforms.items():+ if platform is Platform.RELAY or platform in non_messaging:+ continue+ if not platform_config.enabled:+ continue+ if platform_config.extra.get("_enabled_explicit"):+ logger.warning(+ "Relay connector is configured via GATEWAY_RELAY_URL; "+ "disabling directly-connected platform '%s' even though "+ "it is explicitly enabled in config.yaml. All messaging "+ "goes through the connector on this deployment.",+ platform.value,+ )+ else:+ logger.info(+ "Relay connector is configured via GATEWAY_RELAY_URL; "+ "disabling directly-connected platform '%s'.",+ platform.value,+ )+ platform_config.enabled = False+for platform_config in config.platforms.values():platform_config.extra.pop("_enabled_explicit", None)diff --git a/tests/gateway/test_config.py b/tests/gateway/test_config.pyindex 29c71a387bc..8e110714df8 100644--- a/tests/gateway/test_config.py+++ b/tests/gateway/test_config.py@@ -686,6 +686,66 @@ class TestLoadGatewayConfig:assert Platform.RELAY in config.get_connected_platforms()+ def test_relay_env_url_disables_other_messaging_platforms(self, tmp_path, monkeypatch):+ """A GATEWAY_RELAY_URL env stamp means the connector owns all platform+ connections: directly-connected messaging platforms must be disabled,+ even when explicitly enabled in config.yaml, while non-messaging+ surfaces (api_server et al.) survive."""+ hermes_home = tmp_path / ".hermes"+ hermes_home.mkdir()+ config_path = hermes_home / "config.yaml"+ config_path.write_text(+ "gateway:\n"+ " platforms:\n"+ " telegram:\n"+ " enabled: true\n"+ " bot_token: '123:abc'\n"+ " api_server:\n"+ " enabled: true\n",+ encoding="utf-8",+ )+ monkeypatch.setenv("HERMES_HOME", str(hermes_home))+ monkeypatch.setenv("GATEWAY_RELAY_URL", "https://connector.example/relay")+ # Credential-based auto-enable path must be suppressed too.+ monkeypatch.setenv("DISCORD_BOT_TOKEN", "fake-token-for-test")++ config = load_gateway_config()++ assert config.platforms[Platform.RELAY].enabled is True+ assert config.platforms[Platform.TELEGRAM].enabled is False+ discord_cfg = config.platforms.get(Platform.DISCORD)+ assert discord_cfg is None or discord_cfg.enabled is False+ # Non-messaging surfaces are untouched.+ assert config.platforms[Platform.API_SERVER].enabled is True+++ def test_relay_yaml_url_keeps_other_platforms_enabled(self, tmp_path, monkeypatch):+ """gateway.relay_url in config.yaml (no env stamp) keeps the old+ additive behavior: relay runs beside directly-connected platforms."""+ hermes_home = tmp_path / ".hermes"+ hermes_home.mkdir()+ config_path = hermes_home / "config.yaml"+ config_path.write_text(+ "gateway:\n"+ " platforms:\n"+ " relay:\n"+ " enabled: true\n"+ " extra:\n"+ " relay_url: https://connector.example/relay\n"+ " telegram:\n"+ " enabled: true\n"+ " bot_token: '123:abc'\n",+ encoding="utf-8",+ )+ monkeypatch.setenv("HERMES_HOME", str(hermes_home))+ monkeypatch.delenv("GATEWAY_RELAY_URL", raising=False)++ config = load_gateway_config()++ assert config.platforms[Platform.RELAY].enabled is True+ assert config.platforms[Platform.TELEGRAM].enabled is True++def test_thread_require_mention_yaml_does_not_overwrite_env(self, tmp_path, monkeypatch):"""Explicit env var should win over config.yaml (env > yaml precedence)."""hermes_home = tmp_path / ".hermes"