fix(gateway): normalise legacy bool reply_to_mode before Discord adapter (#29623)#29706
Open
Bartok9 wants to merge 1 commit into
Open
fix(gateway): normalise legacy bool reply_to_mode before Discord adapter (#29623)#29706Bartok9 wants to merge 1 commit into
Bartok9 wants to merge 1 commit into
Conversation
Contributor
Author
|
Closing to stay within contributor PR limit. Will resubmit with fresh rebase if the issue remains open in main. |
…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
7b926f6 to
ce077fc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the regression where Discord
reply_to_mode: falsein YAML config regresses tofirst(always-reply) behaviour at runtime.Root cause
YAML 1.1 (PyYAML default) parses bare
off/falseas Pythonbool False. That boolean reachesPlatformConfig.from_dict()as-is and is stored on the dataclass. The Discord adapter then does:Because
Falseis falsy,or 'first'fires and the user's explicitoffsetting is silently discarded — the bot replies to every message.Probe on current
origin/main(87d923900):Fix (defence-in-depth, two layers)
Layer 1 —
gateway/config.pyPlatformConfig.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.pyDiscordAdapter.__init__():Add an explicit
isinstance(bool)guard before theor 'first'fallback, so any stalePlatformConfigobject carrying a raw bool is also handled correctly.Tests
Adds 5 new cases to
TestConfigSerializationin the existingtests/gateway/test_discord_reply_mode.py:test_from_dict_bool_false_normalised_to_offfrom_dict({reply_to_mode: False})→"off"test_from_dict_bool_true_normalised_to_firstfrom_dict({reply_to_mode: True})→"first"test_adapter_bool_false_config_does_not_fall_back_to_firstPlatformConfig(reply_to_mode=False)adapter →"off"test_adapter_from_dict_bool_false_offfrom_dict→ adapter →"off"All 37 tests in the file pass.
How to test
Fixes #29623