Skip to content

fix(gateway): respect explicit platform enabled:false in YAML config - #35562

Closed
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/telegram-env-override-explicit-disable
Closed

fix(gateway): respect explicit platform enabled:false in YAML config#35562
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/telegram-env-override-explicit-disable

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes a bug where platforms.telegram.enabled: false (and platforms.discord.enabled: false) in profile config.yaml is ignored when TELEGRAM_BOT_TOKEN / DISCORD_BOT_TOKEN is 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

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • gateway/config.py: Fixed two code paths in _apply_env_overrides() that unconditionally set enabled=True when env tokens are present:
    • Hardcoded Telegram/Discord token blocks: now only auto-enable when no YAML config exists (env-only setup)
    • Plugin auto-enablement loop: now skips entirely when existing_cfg is present (YAML config exists), preventing is_connected probes from overriding explicit enabled: false
  • tests/gateway/test_config.py: Added 5 regression tests in TestEnvOverrideRespectsExplicitDisable covering Telegram and Discord: explicit disable respected, auto-enable for env-only, and preserve existing enabled state

How to Test

  1. Create a profile config with platforms.telegram.enabled: false
  2. Have TELEGRAM_BOT_TOKEN in .env (shared across profiles)
  3. Start gateway: hermes -p <profile> gateway run
  4. Verify: gateway does NOT connect to Telegram (before fix, it would connect)
  5. Run tests: pytest tests/gateway/test_config.py -k "TestEnvOverrideRespectsExplicitDisable" -v

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Code Intelligence

  • Analyzed: gateway/config.py:_apply_env_overrides (callers: load_gateway_config, 1 call site)
  • Blast radius: LOW — changes only affect the env-override → platform-enable decision; no schema/API changes
  • Related patterns: WhatsApp (lines 1316-1325) and Slack (lines 1337-1347) already implement the correct "respect explicit disable" pattern. This fix aligns Telegram and Discord with that established behavior.

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
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter platform/discord Discord bot adapter P2 Medium — degraded but workaround exists labels May 30, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Competing fix PRs for the same _apply_env_overrides() bug family:

This PR covers both hardcoded (Telegram/Discord) and plugin platform code paths in a single fix. Addresses #35555.

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 but enabled is left untouched.
  • Plugin platform probe fix: The plugin auto-discovery path changed from if existing_cfg is None or not existing_cfg.enabled to if 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 wrote enabled: 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_disabled
    • test_telegram_env_token_auto_enables_when_no_yaml_config
    • test_telegram_env_token_preserves_yaml_enabled_true
    • test_discord_env_token_does_not_override_yaml_disabled
    • test_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 tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_cfg is 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)

@teknium1

Copy link
Copy Markdown
Contributor

Closing — issue #35555 is resolved on current main, so this PR is no longer needed. Thanks for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/discord Discord bot adapter platform/telegram Telegram bot adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Profile config ignored when TELEGRAM_BOT_TOKEN is in environment

4 participants