Skip to content

The agent that grows with you

gateway: warn once when an explicit platforms.<x>.enabled: false overrides env credentials

Teknium7ff8aae8fb6f
diff --git a/gateway/config.py b/gateway/config.py
index 065701372ae..f3e9af5e596 100644
--- a/gateway/config.py
+++ b/gateway/config.py
@@ -1980,6 +1980,64 @@ def _validate_gateway_config(config: "GatewayConfig") -> None:
pconfig.enabled = False
+# Platforms for which the "explicitly disabled in config.yaml, but credentials
+# are present in the environment" WARNING has already been emitted in this
+# process. The gateway reloads its config on every turn (and other surfaces
+# call load_gateway_config() repeatedly), so the notice is one-time per
+# platform per process — loud once at startup, never a per-turn drumbeat.
+_EXPLICIT_DISABLE_WARNED: set = set()
+
+
+# Env var(s) whose presence drives each platform's env-enable branch, for the
+# explicit-disable WARNING below. Kept next to the branches that read them.
+_ENV_ENABLE_CREDENTIALS: dict = {
+ Platform.TELEGRAM: ("TELEGRAM_BOT_TOKEN",),
+ Platform.DISCORD: ("DISCORD_BOT_TOKEN",),
+ Platform.SLACK: ("SLACK_BOT_TOKEN",),
+ Platform.WHATSAPP_CLOUD: ("WHATSAPP_CLOUD_PHONE_NUMBER_ID", "WHATSAPP_CLOUD_ACCESS_TOKEN"),
+ Platform.SIGNAL: ("SIGNAL_HTTP_URL",),
+ Platform.MATTERMOST: ("MATTERMOST_TOKEN",),
+ Platform.MATRIX: ("MATRIX_ACCESS_TOKEN", "MATRIX_PASSWORD"),
+ Platform.HOMEASSISTANT: ("HASS_TOKEN",),
+ Platform.EMAIL: ("EMAIL_ADDRESS", "EMAIL_PASSWORD", "EMAIL_IMAP_HOST", "EMAIL_SMTP_HOST"),
+ Platform.SMS: ("TWILIO_ACCOUNT_SID",),
+ Platform.DINGTALK: ("DINGTALK_CLIENT_ID", "DINGTALK_CLIENT_SECRET"),
+ Platform.FEISHU: ("FEISHU_APP_ID", "FEISHU_APP_SECRET"),
+ Platform.WECOM: ("WECOM_BOT_ID", "WECOM_SECRET"),
+ Platform.WECOM_CALLBACK: ("WECOM_CALLBACK_CORP_ID", "WECOM_CALLBACK_CORP_SECRET"),
+ Platform.WEIXIN: ("WEIXIN_TOKEN", "WEIXIN_ACCOUNT_ID"),
+ Platform.BLUEBUBBLES: ("BLUEBUBBLES_SERVER_URL", "BLUEBUBBLES_PASSWORD"),
+ Platform.QQBOT: ("QQ_APP_ID", "QQ_CLIENT_SECRET"),
+ Platform.YUANBAO: ("YUANBAO_APP_ID", "YUANBAO_APP_SECRET"),
+ Platform.RELAY: ("GATEWAY_RELAY_URL",),
+}
+
+
+def _warn_explicit_disable_beats_env(platform: Platform) -> None:
+ """One-time WARNING: ``platforms.<x>.enabled: false`` wins over env creds.
+
+ Until #48820 the credential-presence branches force-enabled twelve
+ platforms regardless of an explicit ``enabled: false`` in config.yaml, so
+ users who relied on "creds in .env = platform on" would see it go dark
+ after the fix with no explanation. Name the platform, the config key that
+ is winning, and the env var(s) that used to override it.
+ """
+ if platform in _EXPLICIT_DISABLE_WARNED:
+ return
+ _EXPLICIT_DISABLE_WARNED.add(platform)
+ names = _ENV_ENABLE_CREDENTIALS.get(platform) or ()
+ present = [n for n in names if (os.environ.get(n) or "").strip()]
+ creds = ", ".join(present or names) or "its credentials"
+ logger.warning(
+ "Platform '%s' is explicitly disabled by platforms.%s.enabled: false in "
+ "config.yaml, so the credentials found in the environment (%s) will NOT "
+ "start its adapter. Environment credentials no longer override an "
+ "explicit disable. Remove the key or set platforms.%s.enabled: true to "
+ "turn it back on.",
+ platform.value, platform.value, creds, platform.value,
+ )
+
+
def _apply_env_overrides(config: GatewayConfig) -> None:
"""Apply environment variable overrides to config."""
getenv = _getenv_str
@@ -1998,8 +2056,13 @@ def _apply_env_overrides(config: GatewayConfig) -> None:
# flag is cleared once for all platforms in the final cleanup at the
# end of _apply_env_overrides.
enabled_was_explicit = bool(platform_config.extra.get("_enabled_explicit", False))
- if not platform_config.enabled and not enabled_was_explicit:
- platform_config.enabled = True
+ if not platform_config.enabled:
+ if enabled_was_explicit:
+ # Credentials are present (that is why we are here) but the
+ # user said no in config.yaml. Say so once (#48820).
+ _warn_explicit_disable_beats_env(platform)
+ else:
+ platform_config.enabled = True
return platform_config
# Telegram
@@ -2150,6 +2213,8 @@ def _apply_env_overrides(config: GatewayConfig) -> None:
# turn an env-token setup into a disabled platform. Only an
# explicit slack.enabled/platforms.slack.enabled false should.
slack_config.enabled = True
+ elif not slack_config.enabled:
+ _warn_explicit_disable_beats_env(Platform.SLACK)
# If yaml config exists, respect its enabled flag (don't override
# explicit enabled: false). Token is still stored so skills that
# send Slack messages can use it without activating the gateway adapter.
diff --git a/tests/gateway/test_env_override_explicit_disable_48820.py b/tests/gateway/test_env_override_explicit_disable_48820.py
index 1d3ce205bc7..1d8452c5a08 100644
--- a/tests/gateway/test_env_override_explicit_disable_48820.py
+++ b/tests/gateway/test_env_override_explicit_disable_48820.py
@@ -10,8 +10,11 @@ Discord / Slack routed through ``_enable_from_env`` and honored the
against a temp HERMES_HOME — real YAML I/O, no mocks of the code under test.
"""
+import logging
+
import pytest
+from gateway import config as gateway_config
from gateway.config import Platform, load_gateway_config
@@ -119,3 +122,78 @@ def test_env_credentials_still_populate_extra_when_yaml_disables(tmp_path, monke
assert cfg.extra.get("account_id") == "acct_12345"
# marker never leaks out of config load
assert "_enabled_explicit" not in cfg.extra
+
+
+def _fresh_warn_dedup(monkeypatch):
+ """The explicit-disable notice is one-time per process; start each test clean."""
+ monkeypatch.setattr(gateway_config, "_EXPLICIT_DISABLE_WARNED", set())
+
+
[email protected]("_fresh_warn_dedup")
[email protected]("platform", sorted(CRED_ENV))
+def test_explicit_disable_with_env_credentials_warns_once(platform, tmp_path, monkeypatch, caplog):
+ """Users who relied on 'creds in .env = platform on' must be told why it went
+ dark: one WARNING naming the platform, the winning config key, and the env
+ credential(s) — emitted once per process, not on every config reload."""
+ hermes_home = _isolate(monkeypatch, tmp_path, CRED_ENV[platform])
+ (hermes_home / "config.yaml").write_text(
+ f"platforms:\n {platform}:\n enabled: false\n", encoding="utf-8"
+ )
+
+ with caplog.at_level(logging.WARNING, logger="gateway.config"):
+ load_gateway_config()
+ load_gateway_config() # reload: must not repeat
+
+ hits = [
+ r for r in caplog.records
+ if r.levelno == logging.WARNING and f"platforms.{platform}.enabled: false" in r.getMessage()
+ ]
+ assert len(hits) == 1, [r.getMessage() for r in caplog.records]
+ msg = hits[0].getMessage()
+ assert f"Platform '{platform}'" in msg
+ for env_name in CRED_ENV[platform]:
+ assert env_name in msg
+ assert f"platforms.{platform}.enabled: true" in msg # the remedy
+
+
[email protected]("_fresh_warn_dedup")
+def test_no_warning_when_yaml_has_no_opinion_or_is_enabled(tmp_path, monkeypatch, caplog):
+ hermes_home = _isolate(monkeypatch, tmp_path, {**CRED_ENV["weixin"], **CRED_ENV["homeassistant"]})
+ (hermes_home / "config.yaml").write_text(
+ "platforms:\n homeassistant:\n enabled: true\n", encoding="utf-8"
+ )
+
+ with caplog.at_level(logging.WARNING, logger="gateway.config"):
+ config = load_gateway_config()
+
+ assert config.platforms[Platform.WEIXIN].enabled is True
+ assert config.platforms[Platform.HOMEASSISTANT].enabled is True
+ assert not [r for r in caplog.records if "explicitly disabled" in r.getMessage()]
+
+
[email protected]("_fresh_warn_dedup")
+def test_no_warning_when_disabled_and_no_env_credentials(tmp_path, monkeypatch, caplog):
+ """The notice is about credentials being IGNORED; a plain disable is silent."""
+ hermes_home = _isolate(monkeypatch, tmp_path, {})
+ (hermes_home / "config.yaml").write_text(
+ "platforms:\n weixin:\n enabled: false\n", encoding="utf-8"
+ )
+
+ with caplog.at_level(logging.WARNING, logger="gateway.config"):
+ config = load_gateway_config()
+
+ assert config.platforms[Platform.WEIXIN].enabled is False
+ assert not [r for r in caplog.records if "explicitly disabled" in r.getMessage()]
+
+
+def test_every_env_enable_branch_is_named_for_the_warning():
+ """Each platform routed through ``_enable_from_env`` needs a credential
+ entry so the WARNING can name what is being ignored."""
+ import inspect, re
+
+ src = inspect.getsource(gateway_config._apply_env_overrides)
+ routed = {Platform[name] for name in re.findall(r"_enable_from_env\(Platform\.([A-Z_]+)\)", src)}
+ routed.add(Platform.SLACK) # Slack has its own inline copy of the logic
+ missing = {p.value for p in routed} - {p.value for p in gateway_config._ENV_ENABLE_CREDENTIALS}
+ assert not missing, f"platforms without a credential entry for the explicit-disable warning: {missing}"
diff --git a/website/docs/user-guide/messaging/index.md b/website/docs/user-guide/messaging/index.md
index a0aaf6b5e42..f8984fed5a1 100644
--- a/website/docs/user-guide/messaging/index.md
+++ b/website/docs/user-guide/messaging/index.md
@@ -673,6 +673,36 @@ Once the gateway is running, use the `/platform` slash command from any connecte
See also the broader status summary command [`/platforms`](../../reference/slash-commands.md#info).
+### Disabling a platform whose credentials are still in `.env`
+
+`platforms.<name>.enabled: false` in `~/.hermes/config.yaml` is authoritative.
+Credentials for that platform left in the environment (`TELEGRAM_BOT_TOKEN`,
+`WEIXIN_TOKEN`, `HASS_TOKEN`, `EMAIL_*`, `TWILIO_ACCOUNT_SID`, ...) are still
+wired into the platform's config so send-only tooling keeps working, but they
+no longer start the adapter:
+
+```yaml title="~/.hermes/config.yaml"
+platforms:
+ weixin:
+ enabled: false # wins over WEIXIN_TOKEN in .env
+```
+
+Earlier releases let the mere presence of credentials re-enable twelve
+platforms (Weixin, WhatsApp Cloud, Home Assistant, Email, SMS, DingTalk, Feishu,
+WeCom, WeCom callback, BlueBubbles, QQ Bot, Yuanbao) regardless of that key. If
+you relied on that, the gateway now logs one WARNING per affected platform at
+startup so it does not just go dark:
+
+```
+Platform 'weixin' is explicitly disabled by platforms.weixin.enabled: false in config.yaml,
+so the credentials found in the environment (WEIXIN_TOKEN, WEIXIN_ACCOUNT_ID) will NOT start
+its adapter. Environment credentials no longer override an explicit disable. Remove the key
+or set platforms.weixin.enabled: true to turn it back on.
+```
+
+Omitting the `enabled` key entirely keeps the env-only behaviour: credentials
+present → adapter starts.
+
### Automatic circuit breaker
Each adapter is wrapped in a circuit breaker. Repeated retryable failures (network blips, rate-limit replies, 5xx upstream responses, websocket disconnects) cause the breaker to trip — the adapter is auto-paused, an operator notification is sent to the home channel of another live platform when one is configured, and a structured log line is emitted.