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.
This commit is contained in:
Teknium 2026-07-17 02:42:00 -07:00
parent 26eafd6a00
commit da955a643e
2 changed files with 9 additions and 16 deletions

View file

@ -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

View file

@ -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