Skip to content

The agent that grows with you

fix(gateway): honor explicit webhook disable in _apply_env_overrides

webtecnicadd666d241830
diff --git a/gateway/config.py b/gateway/config.py
index f3e9af5e596..c9108614dcf 100644
--- a/gateway/config.py
+++ b/gateway/config.py
@@ -2406,7 +2406,21 @@ def _apply_env_overrides(config: GatewayConfig) -> None:
if webhook_enabled:
if Platform.WEBHOOK not in config.platforms:
config.platforms[Platform.WEBHOOK] = PlatformConfig()
- config.platforms[Platform.WEBHOOK].enabled = True
+ # Honor an explicit ``enabled: false`` in config.yaml (flagged by
+ # ``_enabled_explicit``). In multiplex mode a secondary profile's
+ # config.yaml pins ``platforms.webhook.enabled: false`` so it shares
+ # the default profile's listener instead of binding its own port. That
+ # profile may still carry ``WEBHOOK_ENABLED`` in its own .env (or the
+ # process env, single-profile); without this guard the env var would
+ # force-enable the listener and trip the MultiplexConfigError check.
+ # Pop (don't read) the marker — the webhook branch is terminal (no
+ # later registry pass re-enables it), matching the api_server branch
+ # above.
+ webhook_explicit = config.platforms[Platform.WEBHOOK].extra.pop(
+ "_enabled_explicit", False
+ )
+ if not webhook_explicit or config.platforms[Platform.WEBHOOK].enabled:
+ config.platforms[Platform.WEBHOOK].enabled = True
if webhook_port:
try:
config.platforms[Platform.WEBHOOK].extra["port"] = int(webhook_port)
diff --git a/tests/gateway/test_config.py b/tests/gateway/test_config.py
index 2e4285f68ff..b06b163bdb7 100644
--- a/tests/gateway/test_config.py
+++ b/tests/gateway/test_config.py
@@ -1409,3 +1409,49 @@ class TestApiServerEnvOverride:
assert config.platforms[Platform.API_SERVER].enabled is False
# The key is still wired through for the shared listener.
assert config.platforms[Platform.API_SERVER].extra.get("key") == api_server_key
+
+
+class TestWebhookEnvOverride:
+ def test_env_key_does_not_reenable_explicitly_disabled_webhook(self):
+ """An explicit ``platforms.webhook.enabled: false`` must survive
+ _apply_env_overrides() even when WEBHOOK_ENABLED is truthy in the env.
+
+ Regression (#85637): _apply_env_overrides() force-set
+ webhook.enabled = True whenever WEBHOOK_ENABLED was truthy. In
+ multiplex mode a secondary profile pins ``webhook.enabled: false`` so
+ it shares the default profile's listener instead of binding its own
+ port, but it still inherits the process-level WEBHOOK_ENABLED
+ (or carries one in its own .env). The unconditional re-enable
+ flipped it back on and tripped the MultiplexConfigError check.
+
+ The fix honors the explicit disable, flagged by ``_enabled_explicit``
+ in the platform's extra (set when the config.yaml pins enabled).
+ """
+ config = GatewayConfig(
+ platforms={
+ Platform.WEBHOOK: PlatformConfig(
+ enabled=False,
+ extra={"_enabled_explicit": True},
+ ),
+ },
+ )
+
+ with patch.dict(
+ os.environ,
+ {
+ "WEBHOOK_ENABLED": "true",
+ "WEBHOOK_PORT": "9999",
+ "WEBHOOK_SECRET": "shared-secret",
+ },
+ clear=True,
+ ):
+ _apply_env_overrides(config)
+
+ # Explicit disable wins over the env-var presence.
+ assert config.platforms[Platform.WEBHOOK].enabled is False
+ # Port/secret are still wired through for the shared listener.
+ assert config.platforms[Platform.WEBHOOK].extra.get("port") == 9999
+ assert (
+ config.platforms[Platform.WEBHOOK].extra.get("secret")
+ == "shared-secret"
+ )