fix(discord): keep free-response channels inline - #25311
Closed
simpolism wants to merge 1 commit into
Closed
Conversation
Free-response channels are intended as lightweight chat surfaces — the bot
responds to every message without requiring an @mention. But the auto-thread
gate only checked DISCORD_NO_THREAD_CHANNELS, not DISCORD_FREE_RESPONSE_CHANNELS,
so every message in a free-response channel still spawned a brand-new thread.
That turns a chat channel into a thread-spawning machine: 1 thread per message.
The user-facing docs at website/docs/user-guide/messaging/discord.md already
describe the intended behavior ("Free-response channels also skip auto-threading
— the bot replies inline rather than spinning off a new thread per message"),
so this is a code-vs-docs gap, not a design change.
Fix: OR is_free_channel into skip_thread alongside the existing no_thread_channels
check. One-line production change.
Regression test added at tests/gateway/test_discord_free_response.py:
test_discord_free_response_channel_skips_auto_thread asserts that a message
in a free-response channel never calls _auto_create_thread. Reverting the
one-line fix causes the test to fail with 'Expected mock to not have been
awaited. Awaited 1 times.' — i.e. the test demonstrates the bug concretely.
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?
Fix a code-vs-docs gap in Discord auto-threading. Free-response channels are documented as "skip auto-threading — reply inline," but the production code only checks
DISCORD_NO_THREAD_CHANNELSwhen deciding whether to skip thread creation, notDISCORD_FREE_RESPONSE_CHANNELS. So every message in a free-response channel currently spawns its own thread, turning a documented "lightweight chat" channel into a thread-spawning machine.One-line production change: OR
is_free_channelinto the existingskip_threadcalculation.The existing docstring for
discord.free_response_channelsatwebsite/docs/user-guide/messaging/discord.md:347already promises this behavior:so no docs change is needed — this PR makes the code match the docs.
Related Issue
Fixes #25310
Type of Change
Changes Made
gateway/platforms/discord.py: in_handle_message's auto-thread block,skip_thread = bool(channel_ids & no_thread_channels)becomesbool(channel_ids & no_thread_channels) or is_free_channel. Theis_free_channelvariable is already computed earlier in the function (used by the mention gate) — this propagates it to the auto-thread gate as well.tests/gateway/test_discord_free_response.py: new regression testtest_discord_free_response_channel_skips_auto_threadthat mocks_auto_create_threadand asserts it is not awaited when a message arrives in a free-response channel withauto_thread=true(the default).How to Test
To verify the bug exists without the fix:
main.pytest tests/gateway/test_discord_free_response.py::test_discord_free_response_channel_skips_auto_thread.AssertionError: Expected mock to not have been awaited. Awaited 1 times.(i.e. the production bug is real — auto-thread is fired).To verify the fix:
tests/gateway/test_discord_free_response.pysuite — 22 tests pass (was 21).Manual verification: configure a Discord bot with
discord.free_response_channels: [<channel-id>]anddiscord.auto_thread: true. Send any message in that channel. Before this PR: bot spawns a thread. After this PR: bot replies inline.Checklist
Code
Documentation & Housekeeping