fix(discord): filter obfuscated channels on the explicit-id backfill path too

Review finding on #90154: only the wildcard ("*") branch of
_iter_missed_message_backfill_candidates skipped obfuscated channels. A
channel the bot previously talked in that later lost VIEW_CHANNEL still
entered the explicit-id branch and produced a failing history read on
every startup. Apply the predicate once, after both branches build the
candidate list, and import it at module level like the other helpers.

(During the rebase the predicate was also tightened, resolved in the original
commit: is_discord_channel_obfuscated catches AttributeError (the precise
expected failure) instead of a bare Exception so a genuine attribute bug
is not hidden behind the name fallback, and its docstring states the
deliberate bias of the sentinel-name fallback (a visible channel literally
named ___hidden___ is also skipped on discord.py builds without the flag).)
This commit is contained in:
teknium1
2026-09-14 18:38:53 -07:00
committed by Teknium
parent 1f34742552
commit 624777617c

View File

@@ -258,7 +258,7 @@ except ImportError:
from gateway.config import Platform, PlatformConfig
from gateway.platforms.helpers import (
MessageDeduplicator, ThreadParticipationTracker, convert_table_to_bullets,
MessageDeduplicator, ThreadParticipationTracker, convert_table_to_bullets, is_discord_channel_obfuscated,
)
from gateway.platforms.helpers import cancel_task
from utils import atomic_json_write, env_float
@@ -2280,18 +2280,8 @@ class DiscordAdapter(DiscordMediaMixin, BasePlatformAdapter):
seen: set[str] = set()
candidate_channels = []
if "*" in channel_ids:
from gateway.platforms.helpers import is_discord_channel_obfuscated
for guild in getattr(self._client, "guilds", []) or []:
# Skip obfuscated placeholders (bot lacks VIEW_CHANNEL;
# Discord dispatches them with name "___hidden___" +
# CHANNEL_OBFUSCATED flag as of the Aug 2026 privacy
# change). History reads on them always fail.
candidate_channels.extend(
ch
for ch in (getattr(guild, "text_channels", []) or [])
if not is_discord_channel_obfuscated(ch)
)
candidate_channels.extend(getattr(guild, "text_channels", []) or [])
else:
for channel_id in sorted(channel_ids):
channel = None
@@ -2306,6 +2296,10 @@ class DiscordAdapter(DiscordMediaMixin, BasePlatformAdapter):
logger.debug("[%s] Cannot fetch backfill channel %s: %s", self.name, channel_id, exc)
continue
candidate_channels.append(channel)
# Obfuscated placeholders (bot lost VIEW_CHANNEL) fail every history read — drop them
# from both the wildcard and the explicit-id branch (#90154).
candidate_channels = [ch for ch in candidate_channels if not is_discord_channel_obfuscated(ch)]
iterators = [
self._iter_channel_and_thread_messages(
channel, limit=limit, after=after, seen_channels=seen,