Skip to content

fix(gateway): normalise legacy bool reply_to_mode before Discord adapter (#29623)#29706

Open
Bartok9 wants to merge 1 commit into
NousResearch:mainfrom
Bartok9:fix/29623-discord-reply-to-mode-bool-compat
Open

fix(gateway): normalise legacy bool reply_to_mode before Discord adapter (#29623)#29706
Bartok9 wants to merge 1 commit into
NousResearch:mainfrom
Bartok9:fix/29623-discord-reply-to-mode-bool-compat

Conversation

@Bartok9

@Bartok9 Bartok9 commented May 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the regression where Discord reply_to_mode: false in YAML config regresses to first (always-reply) behaviour at runtime.

Root cause

YAML 1.1 (PyYAML default) parses bare off / false as Python bool False. That boolean reaches PlatformConfig.from_dict() as-is and is stored on the dataclass. The Discord adapter then does:

self._reply_to_mode = getattr(config, 'reply_to_mode', 'first') or 'first'

Because False is falsy, or 'first' fires and the user's explicit off setting is silently discarded — the bot replies to every message.

Probe on current origin/main (87d923900):

from gateway.config import PlatformConfig
print(PlatformConfig.from_dict({'enabled': True, 'reply_to_mode': False}).reply_to_mode)
# False   <-- raw bool, not normalised

Fix (defence-in-depth, two layers)

Layer 1 — gateway/config.py PlatformConfig.from_dict():
Normalise boolean values before storing:

  • False"off" (user meant "no reply-reference")
  • True"first" (user meant "default on")

String values ("off", "first", "all") pass through unchanged.

Layer 2 — gateway/platforms/discord.py DiscordAdapter.__init__():
Add an explicit isinstance(bool) guard before the or 'first' fallback, so any stale PlatformConfig object carrying a raw bool is also handled correctly.

Tests

Adds 5 new cases to TestConfigSerialization in the existing tests/gateway/test_discord_reply_mode.py:

Test Assertion
test_from_dict_bool_false_normalised_to_off from_dict({reply_to_mode: False})"off"
test_from_dict_bool_true_normalised_to_first from_dict({reply_to_mode: True})"first"
test_adapter_bool_false_config_does_not_fall_back_to_first PlatformConfig(reply_to_mode=False) adapter → "off"
test_adapter_from_dict_bool_false_off full pipeline: from_dict → adapter → "off"

All 37 tests in the file pass.

How to test

python3 -m pytest tests/gateway/test_discord_reply_mode.py -v
# 37 passed

# Quick sanity probe:
python3 -c "
from gateway.config import PlatformConfig
from gateway.platforms.discord import DiscordAdapter
cfg = PlatformConfig.from_dict({'enabled': True, 'reply_to_mode': False})
print('config.reply_to_mode:', cfg.reply_to_mode)   # off
a = DiscordAdapter(cfg)
print('adapter._reply_to_mode:', a._reply_to_mode)  # off
"

Fixes #29623

@daimon-nous daimon-nous Bot added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/discord Discord bot adapter area/config Config system, migrations, profiles labels May 21, 2026
@Bartok9

Bartok9 commented May 27, 2026

Copy link
Copy Markdown
Contributor Author

Closing to stay within contributor PR limit. Will resubmit with fresh rebase if the issue remains open in main.

@Bartok9 Bartok9 closed this May 27, 2026
@Bartok9 Bartok9 reopened this May 27, 2026
…scord adapter (NousResearch#29623)

YAML 1.1 parses bare 'off'/'on' as boolean False/True, so configs like:

    discord:
      reply_to_mode: false

arrive in PlatformConfig.from_dict() as the Python bool False.
The Discord adapter then does:

    self._reply_to_mode = getattr(config, 'reply_to_mode', 'first') or 'first'

Because False is falsy, this silently falls back to 'first', so the bot
replies to every message even when the user explicitly set reply_to_mode
to off.

Fix in two layers (defence-in-depth):

1. PlatformConfig.from_dict(): normalise bool before storing
     False -> "off", True -> "first"
2. DiscordAdapter.__init__(): guard isinstance(bool) before the
   'or first' fallback so a stale PlatformConfig object with a raw
   bool field also maps correctly.

Adds five new tests to TestConfigSerialization covering the
bool->string normalisation pipeline end-to-end.

Fixes NousResearch#29623
@Bartok9 Bartok9 force-pushed the fix/29623-discord-reply-to-mode-bool-compat branch from 7b926f6 to ce077fc Compare May 27, 2026 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/discord Discord bot adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Discord reply_to_mode: false regresses to first on current runtime

1 participant