AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(backend/copilot-bot): skip messages in locked Discord threads (#13295)
Bently337023749ea8
diff --git a/autogpt_platform/backend/backend/copilot/bot/adapters/discord/adapter.py b/autogpt_platform/backend/backend/copilot/bot/adapters/discord/adapter.pyindex 3485860b42..1e759ab038 100644--- a/autogpt_platform/backend/backend/copilot/bot/adapters/discord/adapter.py+++ b/autogpt_platform/backend/backend/copilot/bot/adapters/discord/adapter.py@@ -238,6 +238,13 @@ class DiscordAdapter(PlatformAdapter):if self._on_message_callback is None:return+ # A locked thread rejects bot sends — processing the message would+ # just burn a turn and error on every reply. Skip until it's+ # unlocked. (`locked` is set on archive-locked threads too.)+ channel = message.channel+ if isinstance(channel, discord.Thread) and channel.locked:+ return+channel_type = self._channel_type(message)bot_mentioned = self._is_mentioned(message)diff --git a/autogpt_platform/backend/backend/copilot/bot/adapters/discord/adapter_test.py b/autogpt_platform/backend/backend/copilot/bot/adapters/discord/adapter_test.pyindex ca4163748a..1cf2427221 100644--- a/autogpt_platform/backend/backend/copilot/bot/adapters/discord/adapter_test.py+++ b/autogpt_platform/backend/backend/copilot/bot/adapters/discord/adapter_test.py@@ -583,3 +583,48 @@ class TestOnThreadRemove:):# Must not raise — cleanup is never critical-path.await handlers["on_thread_remove"](_thread(555))+++# ── on_message: locked threads ──────────────────────────────────────────+++class TestLockedThread:+ @pytest.mark.asyncio+ async def test_locked_thread_message_is_skipped(self):+ # A locked thread rejects bot sends, so processing the message would+ # just burn a turn and error on every reply. Bail before the handler.+ adapter, _ = _bare_adapter(bot_id=1000)+ callback = AsyncMock()+ adapter.on_message(callback)+ handlers = _register_events_with_mocked_decorator(adapter)++ thread = _thread(555)+ thread.locked = True+ msg = MagicMock()+ msg.author = MagicMock(id=2000, bot=False)+ msg.channel = thread++ await handlers["on_message"](msg)++ callback.assert_not_awaited()++ @pytest.mark.asyncio+ async def test_unlocked_thread_message_is_processed(self):+ adapter, _ = _bare_adapter(bot_id=1000)+ callback = AsyncMock()+ adapter.on_message(callback)+ handlers = _register_events_with_mocked_decorator(adapter)++ thread = _thread(555)+ thread.locked = False+ msg = MagicMock()+ msg.id = 999+ msg.author = MagicMock(id=2000, bot=False, display_name="Bently")+ msg.guild = MagicMock(id=111)+ msg.channel = thread+ msg.content = "hi"+ msg.mentions = []++ await handlers["on_message"](msg)++ callback.assert_awaited_once()