From 2d3f5c1554b29df73b12110f8ecf657fe90762a2 Mon Sep 17 00:00:00 2001 From: Ben Barclay Date: Fri, 21 Aug 2026 12:26:41 +1000 Subject: [PATCH] feat(gateway): GATEWAY_RELAY_ALLOW_DIRECT_PLATFORMS opt-out for relay-exclusive mode Deployments that intentionally mix connector-fronted and direct ingress can set GATEWAY_RELAY_ALLOW_DIRECT_PLATFORMS=true to keep directly- connected messaging adapters enabled beside the relay. Unset, the GATEWAY_RELAY_URL env stamp keeps its exclusive behavior. Like the trigger, the opt-out is a deploy-stamp env var, not config.yaml. --- gateway/config.py | 10 +++++++++- tests/gateway/test_config.py | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/gateway/config.py b/gateway/config.py index 590bb5ebe8..172eaf4ff2 100644 --- a/gateway/config.py +++ b/gateway/config.py @@ -2772,7 +2772,15 @@ def _apply_env_overrides(config: GatewayConfig) -> None: # 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: + # + # Opt-out: GATEWAY_RELAY_ALLOW_DIRECT_PLATFORMS=true keeps direct + # adapters running beside the relay for deployments that intentionally + # mix both ingress paths. Like the trigger, it is a deploy-stamp env var, + # not a config.yaml setting. + allow_direct = os.getenv( + "GATEWAY_RELAY_ALLOW_DIRECT_PLATFORMS", "" + ).strip().lower() in ("1", "true", "yes", "on") + if relay_url_env and not allow_direct: 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: diff --git a/tests/gateway/test_config.py b/tests/gateway/test_config.py index 8e110714df..5fd626051b 100644 --- a/tests/gateway/test_config.py +++ b/tests/gateway/test_config.py @@ -746,6 +746,31 @@ class TestLoadGatewayConfig: assert config.platforms[Platform.TELEGRAM].enabled is True + def test_relay_env_url_opt_out_keeps_direct_platforms(self, tmp_path, monkeypatch): + """GATEWAY_RELAY_ALLOW_DIRECT_PLATFORMS=true opts a deployment out of + the relay-exclusive sweep: direct adapters stay enabled beside the + relay even with the GATEWAY_RELAY_URL env stamp present.""" + 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", + encoding="utf-8", + ) + monkeypatch.setenv("HERMES_HOME", str(hermes_home)) + monkeypatch.setenv("GATEWAY_RELAY_URL", "https://connector.example/relay") + monkeypatch.setenv("GATEWAY_RELAY_ALLOW_DIRECT_PLATFORMS", "true") + + 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"