feat(discord): add thread_require_mention for multi-bot threads#25313
Closed
simpolism wants to merge 1 commit into
Closed
feat(discord): add thread_require_mention for multi-bot threads#25313simpolism wants to merge 1 commit into
simpolism wants to merge 1 commit into
Conversation
By default, once Hermes participates in a Discord thread (auto-created on @mention or replied in once) it auto-responds to every subsequent message in that thread without requiring further @mentions. That's the right default for one-on-one conversations and isolated channel threads. But it's a confirmed footgun in multi-bot threads. When a user invokes one bot per turn — addressing Codex first, then Hermes — every other bot in the thread also fires on every message, burning credits and spamming the channel. Author has hit this personally in active multi-bot research-team threads. Add a new `discord.thread_require_mention` config key (env: `DISCORD_THREAD_REQUIRE_MENTION`), default `false` to preserve existing behavior. When `true`, the in-thread mention shortcut is disabled and threads are gated the same way channels are. Explicit @mentions still pass through as expected. Mirrors the existing helper shape (config.extra > env > default) and the existing yaml→env bridge pattern used by `require_mention`. Changes: - gateway/platforms/discord.py: new `_discord_thread_require_mention()` helper; in_bot_thread shortcut now AND's with `not _discord_thread_require_mention()` - gateway/config.py: bridge `discord.thread_require_mention` from config.yaml to `DISCORD_THREAD_REQUIRE_MENTION` env var (mirrors the existing `require_mention` bridge two lines above) - hermes_cli/config.py: add `thread_require_mention: False` default to DEFAULT_CONFIG['discord'] - tests/gateway/test_discord_free_response.py: 4 new tests covering default behaviour (in-thread shortcut still works), enabled behaviour (mention required in threads), enabled+mentioned (mention still passes through), and yaml-via-config.extra path. Also clears DISCORD_* env vars in the `adapter` fixture so process-env state from the contributor's shell doesn't leak into per-test behaviour. - tests/gateway/test_config.py: 2 new tests covering the yaml→env bridge (both the apply-from-yaml and env-precedence-over-yaml paths) - website/docs/user-guide/messaging/discord.md: document the new env var + config key with multi-bot rationale; cross-link from `auto_thread` section Tested on Ubuntu 24.04.
1 task
Contributor
13 tasks
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.
What does this PR do?
Adds opt-in
discord.thread_require_mentionconfig (env:DISCORD_THREAD_REQUIRE_MENTION), defaultfalseso existing behavior is unchanged. When set totrue, threads are gated the same way channels are — the bot no longer auto-responds to non-mentioned messages in a thread just because it has previously participated. Explicit@mentionis the only trigger when enabled.This fixes an active footgun in multi-bot threads. By default, once Hermes joins a thread, it auto-responds to every message in that thread without needing further
@mention— fine for one-on-one conversations, but in shared multi-bot threads (e.g. a research Discord with several agents), every other bot also fires on every message you send to any one bot, burning credits and spamming the channel. Author has hit this personally; not hypothetical.The change is deliberately conservative — add the knob, keep the default — so existing 1:1 Discord deployments behave exactly as they do today.
Related Issue
Fixes #25312
Type of Change
Changes Made
gateway/platforms/discord.py: new_discord_thread_require_mention()helper (config.extra → env → defaultfalse), mirroring the existing_discord_require_mention()shape. Thein_bot_threadshortcut in_handle_messagenow ANDs withnot _discord_thread_require_mention()so the shortcut is suppressed when the new knob is enabled.gateway/config.py: yaml→env bridge fordiscord.thread_require_mention, mirroring the existingrequire_mentionbridge two lines above. Without this,config.yamlsettings wouldn't reach the helper at runtime — same pattern, same precedence (env wins over yaml).hermes_cli/config.py: addthread_require_mention: FalsetoDEFAULT_CONFIG['discord'].tests/gateway/test_discord_free_response.py:adapterfixture — clearsDISCORD_*env vars at fixture entry. Found in development: existing tests in this file are environment-fragile (a contributor withDISCORD_THREAD_REQUIRE_MENTION=trueset in their shell seestest_discord_bot_thread_skips_mention_requirementfail). Adding the existing test's needed env vars to the fixture's cleanup list makes the whole file robust to shell environment state.tests/gateway/test_config.py: 2 new tests for the yaml→env bridge — one covering apply-from-yaml, one covering env-precedence-over-yaml (matching how the existingrequire_mentionbridge works).website/docs/user-guide/messaging/discord.md:DISCORD_THREAD_REQUIRE_MENTIONrow in the env-var tablethread_require_mentionentry in the YAML example#### discord.thread_require_mentionprose section with the multi-bot rationale and a code exampleauto_threadsection pointing at the new knobHow to Test
Unit tests (6 new, all impacted files green):
(70 passed locally.)
Manual — multi-bot thread reproduction:
discord.require_mention: true.@mentionBot A. Bot A responds in the thread.@mentionBot B in the same thread. Both bots respond — A because it's "already in the thread," B because it was mentioned. ← the footgun.discord.thread_require_mention: trueon both bots (or viaDISCORD_THREAD_REQUIRE_MENTION=true). Restart gateway.@mentionBot B again. Only Bot B responds.Or for a quick env-only check on one bot:
Checklist
Code
Documentation & Housekeeping
website/docs/user-guide/messaging/discord.mdupdated in three places (env-var table, YAML example, new prose section + cross-link)discord:settings block (settings live in env vars), so following the existing pattern: documented in website docs, not example yaml. Happy to add an example block if preferred.