From da955a643e7a83e4179e18b2f822e7a23cd57a5e Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Fri, 17 Jul 2026 02:42:00 -0700 Subject: [PATCH] fix(discord): preserve recovery message identity Admit recovered events without consuming live dedup first, bypass split-message debounce, report actual dispatch admission, and require explicit reply correlation before suppressing a missed request. --- plugins/platforms/discord/adapter.py | 19 ++++++------------- .../test_discord_missed_message_backfill.py | 6 +++--- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/plugins/platforms/discord/adapter.py b/plugins/platforms/discord/adapter.py index d02c2bea508a..a7a07f2847fe 100644 --- a/plugins/platforms/discord/adapter.py +++ b/plugins/platforms/discord/adapter.py @@ -2210,7 +2210,7 @@ class DiscordAdapter(BasePlatformAdapter): if bot_id is None: return False - async def _scan_history(channel: Any, *, allow_unreferenced_bot_response: bool) -> bool: + async def _scan_history(channel: Any) -> bool: history = getattr(channel, "history", None) if not callable(history): return False @@ -2225,26 +2225,19 @@ class DiscordAdapter(BasePlatformAdapter): ref_id = str(getattr(reference, "message_id", "") or "") if ref_id == str(getattr(message, "id", "")): return True - if allow_unreferenced_bot_response and not ref_id: - return True except Exception: return False return False message_channel = getattr(message, "channel", None) - # In a thread, bot responses are usually ordinary unreferenced messages - # after the user's post. In a parent channel, however, an unreferenced - # bot post after a user message is not evidence that it answered this - # specific message; otherwise one successful reply can mask multiple - # missed parent-channel posts after a rate-limit/outage burst. - if await _scan_history( - message_channel, - allow_unreferenced_bot_response=bool(getattr(message_channel, "parent_id", None)), - ): + # Only an explicit reply reference proves which input a bot response + # completed. An arbitrary later bot post can otherwise mask multiple + # unanswered requests in the same parent channel or thread. + if await _scan_history(message_channel): return True thread = getattr(message, "thread", None) - if thread is not None and await _scan_history(thread, allow_unreferenced_bot_response=True): + if thread is not None and await _scan_history(thread): return True return False diff --git a/tests/gateway/test_discord_missed_message_backfill.py b/tests/gateway/test_discord_missed_message_backfill.py index bd4d2ff67b90..27a55bdfd14e 100644 --- a/tests/gateway/test_discord_missed_message_backfill.py +++ b/tests/gateway/test_discord_missed_message_backfill.py @@ -152,10 +152,10 @@ async def test_parent_channel_unreferenced_bot_message_does_not_suppress_backfil @pytest.mark.asyncio -async def test_thread_unreferenced_bot_message_suppresses_backfill(adapter): +async def test_thread_unreferenced_bot_message_does_not_mask_request(adapter): bot_post = SimpleNamespace( id=2, - content="Done — captured it.", + content="Done — captured a different request.", author=SimpleNamespace(id=999, bot=True), reference=None, created_at=datetime.now(timezone.utc), @@ -163,7 +163,7 @@ async def test_thread_unreferenced_bot_message_suppresses_backfill(adapter): thread = FakeChannel(channel_id=456, parent_id=123, history_messages=[bot_post]) message = make_message(message_id=1, channel=thread) - assert await adapter._should_backfill_discord_message(message) is False + assert await adapter._should_backfill_discord_message(message) is True @pytest.mark.asyncio