From 68ddd6b338b47209b41c7d3b613dff0536d9124e Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Thu, 28 May 2026 03:42:34 -0700 Subject: [PATCH] refactor(discord): inline backfill gate and document intent Drop the _needed_mention local variable now that it has only one use, inline its expression as _has_mention_gap, and add a comment explaining the three backfill cases (mention-gated channel, thread, DM skip). Behaviorally identical to the prior commit; cleanup only. Co-authored-by: liuhao1024 --- plugins/platforms/discord/adapter.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/plugins/platforms/discord/adapter.py b/plugins/platforms/discord/adapter.py index 563ab5fa931..8b697275bdd 100644 --- a/plugins/platforms/discord/adapter.py +++ b/plugins/platforms/discord/adapter.py @@ -4811,14 +4811,17 @@ class DiscordAdapter(BasePlatformAdapter): # to keep the partition rule clean. _channel_context = None _is_dm = isinstance(message.channel, discord.DMChannel) - if not _is_dm: - _needed_mention = ( - require_mention - and not is_free_channel - and not in_bot_thread - ) - _backfill_enabled = self._discord_history_backfill() - if _backfill_enabled and (_needed_mention or is_thread): + if not _is_dm and self._discord_history_backfill(): + # Run backfill when there's a real gap to fill: + # - mention-gated channels with no free-response override + # (messages between bot turns aren't in the transcript) + # - any thread (in_bot_thread bypasses the mention check, but + # processing-window gaps and post-restart context still need + # recovery) + # DMs skip entirely because every DM message triggers the bot, + # so the session transcript already has everything. + _has_mention_gap = require_mention and not is_free_channel and not in_bot_thread + if _has_mention_gap or is_thread: _backfill_text = await self._fetch_channel_context( message.channel, before=message, )