fix(gateway): respect explicit platform enabled:false in YAML config - #35562
fix(gateway): respect explicit platform enabled:false in YAML config#35562liuhao1024 wants to merge 1 commit into
Conversation
When a profile config sets platforms.telegram.enabled: false (or platforms.discord.enabled: false), the gateway should honor that even when TELEGRAM_BOT_TOKEN / DISCORD_BOT_TOKEN is present in the environment. Two code paths in _apply_env_overrides() were overriding the explicit disable: 1. The hardcoded Telegram/Discord token blocks unconditionally set enabled=True. Fixed to only auto-enable when no YAML config exists. 2. The plugin auto-enablement loop (for Discord and other plugin- registered platforms) ran is_connected probes even when YAML had enabled:false, then unconditionally set enabled=True. Fixed to skip the entire auto-enablement when existing_cfg is present. Both fixes follow the established pattern from WhatsApp and Slack, which already respected explicit enabled:false. Token is still stored on disabled platforms so skills that send messages can use it without activating the gateway adapter. Fixes NousResearch#35555
|
Competing fix PRs for the same
This PR covers both hardcoded (Telegram/Discord) and plugin platform code paths in a single fix. Addresses #35555. |
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved ✅
Review Findings
This PR fixes a critical bug where TELEGRAM_BOT_TOKEN (and DISCORD_BOT_TOKEN) env vars would override explicit enabled: false in YAML config. The root cause: _apply_env_overrides() unconditionally set enabled=True whenever the env var was present, ignoring the user's deliberate disable.
✅ Looks Good
- Root cause fix: The Telegram and Discord env-var bridges now only auto-enable when no YAML config exists (
if Platform.TELEGRAM not in config.platforms). When YAML config exists, the token is stored butenabledis left untouched. - Plugin platform probe fix: The plugin auto-discovery path changed from
if existing_cfg is None or not existing_cfg.enabledtoif existing_cfg is None— this is the correct fix. Env-available plugin platforms are only auto-enabled when there's NO existing config at all. If the user wroteenabled: false, it's respected. - Token storage preserved: Even when
enabled: false, the token is still stored so skills that send Telegram/Discord messages can use it without activating the gateway adapter. Good design. - Tests: 5 new test cases covering Telegram and Discord env+YAML interaction:
test_telegram_env_token_does_not_override_yaml_disabledtest_telegram_env_token_auto_enables_when_no_yaml_configtest_telegram_env_token_preserves_yaml_enabled_truetest_discord_env_token_does_not_override_yaml_disabledtest_discord_env_token_auto_enables_when_no_yaml_config
- Clean diff: Well scoped with good comments explaining the logic.
No Issues Found
Reviewed by Hermes Agent
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved ✅
Review
Fixes a bug where enabled: false in YAML config was overridden by env token presence for Telegram and Discord. Changes the env-override logic to only auto-enable when no YAML config exists at all.
✅ Looks Good
- Correct fix: The plugin auto-enablement loop now skips entirely when
existing_cfgis present, and the hardcoded Telegram/Discord token blocks only auto-enable on env-only setups. - Token preserved for skills: Even when disabled, the token is still stored so skills can send messages without activating the gateway adapter.
- Thorough tests: 5 regression tests covering explicit disable, auto-enable for env-only, and preserve existing enabled state for both Telegram and Discord.
- Aligned with existing patterns: WhatsApp and Slack already implement the correct behavior — this fix aligns Telegram and Discord.
Reviewed by Hermes Agent (cron job)
|
Closing — issue #35555 is resolved on current |
What does this PR do?
Fixes a bug where
platforms.telegram.enabled: false(andplatforms.discord.enabled: false) in profile config.yaml is ignored whenTELEGRAM_BOT_TOKEN/DISCORD_BOT_TOKENis present in the environment. The gateway would still connect to these platforms despite the explicit disable, breaking multi-profile setups where some profiles should not have certain platforms active.Related Issue
Fixes #35555
Type of Change
Changes Made
gateway/config.py: Fixed two code paths in_apply_env_overrides()that unconditionally setenabled=Truewhen env tokens are present:existing_cfgis present (YAML config exists), preventingis_connectedprobes from overriding explicitenabled: falsetests/gateway/test_config.py: Added 5 regression tests inTestEnvOverrideRespectsExplicitDisablecovering Telegram and Discord: explicit disable respected, auto-enable for env-only, and preserve existing enabled stateHow to Test
platforms.telegram.enabled: falseTELEGRAM_BOT_TOKENin.env(shared across profiles)hermes -p <profile> gateway runpytest tests/gateway/test_config.py -k "TestEnvOverrideRespectsExplicitDisable" -vChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/ACode Intelligence
gateway/config.py:_apply_env_overrides(callers:load_gateway_config, 1 call site)