diff --git a/plugins/platforms/discord/adapter.py b/plugins/platforms/discord/adapter.py index 0ffe1abac7a..563ab5fa931 100644 --- a/plugins/platforms/discord/adapter.py +++ b/plugins/platforms/discord/adapter.py @@ -4818,7 +4818,7 @@ class DiscordAdapter(BasePlatformAdapter): and not in_bot_thread ) _backfill_enabled = self._discord_history_backfill() - if _needed_mention and _backfill_enabled: + if _backfill_enabled and (_needed_mention or is_thread): _backfill_text = await self._fetch_channel_context( message.channel, before=message, ) diff --git a/scripts/release.py b/scripts/release.py index 4bf04f3e8f8..55d59b42470 100755 --- a/scripts/release.py +++ b/scripts/release.py @@ -52,6 +52,7 @@ AUTHOR_MAP = { "270604154+superearn-fisher@users.noreply.github.com": "superearn-fisher", "3540493+kpadilha@users.noreply.github.com": "kpadilha", "40378218+chaconne67@users.noreply.github.com": "chaconne67", + "Pluviobyte@users.noreply.github.com": "Pluviobyte", "sanghyuk_seo@nexcubecorp.com": "sanghyuk-seo-nexcube", "subrtt@gmail.com": "Brixyy", "wangpuv@hotmail.com": "wangpuv", diff --git a/tests/gateway/test_discord_free_response.py b/tests/gateway/test_discord_free_response.py index 554288812b7..1e4497c83cc 100644 --- a/tests/gateway/test_discord_free_response.py +++ b/tests/gateway/test_discord_free_response.py @@ -851,6 +851,27 @@ async def test_discord_per_user_channel_backfills_too(adapter, monkeypatch): assert event.channel_context == "[Recent channel messages]\n[Alice] context" +@pytest.mark.asyncio +async def test_discord_participated_thread_backfills_without_mention(adapter, monkeypatch): + """Known threads still need recent thread context when mention gating is bypassed.""" + monkeypatch.setenv("DISCORD_REQUIRE_MENTION", "true") + monkeypatch.delenv("DISCORD_FREE_RESPONSE_CHANNELS", raising=False) + monkeypatch.delenv("DISCORD_THREAD_REQUIRE_MENTION", raising=False) + adapter.config.extra["history_backfill"] = True + adapter._fetch_channel_context = AsyncMock(return_value="[Recent channel messages]\n[Alice] thread context") + + thread = FakeThread(channel_id=456, name="follow-up") + adapter._threads.mark("456") + + message = make_message(channel=thread, content="follow-up without mention") + await adapter._handle_message(message) + + adapter._fetch_channel_context.assert_awaited_once() + event = adapter.handle_message.await_args.args[0] + assert event.text == "follow-up without mention" + assert event.channel_context == "[Recent channel messages]\n[Alice] thread context" + + @pytest.mark.asyncio async def test_discord_dm_does_not_backfill(adapter, monkeypatch): """DMs skip backfill — every DM triggers the bot, so there's no mention gap."""