Skip to content

The agent that grows with you

fix: explicit empty backfill channel list disables the Discord scan (review follow-up)

teknium11d6fbd0d1f4d
diff --git a/plugins/platforms/discord/adapter.py b/plugins/platforms/discord/adapter.py
index 0355161850a..e0b91aafe81 100644
--- a/plugins/platforms/discord/adapter.py
+++ b/plugins/platforms/discord/adapter.py
@@ -2161,8 +2161,11 @@ class DiscordAdapter(DiscordMediaMixin, BasePlatformAdapter):
free-response channels by default; ``channels: "*"`` scans every text channel."""
configured = self.config.extra.get("missed_message_backfill")
if isinstance(configured, dict) and "channels" in configured:
- channels = self._gate_csv_set(configured.get("channels"))
- if channels:
+ raw = configured.get("channels")
+ channels = self._gate_csv_set(raw)
+ # An explicit list (YAML list or JSON-list string, even empty) is authoritative — the
+ # operator disabled the scan; only the default "" string falls through to the env/default.
+ if channels or isinstance(_decode_json_list_literal(raw), list):
return channels
raw = self._gate_env("DISCORD_MISSED_MESSAGE_BACKFILL_CHANNELS")
if not raw.strip():
diff --git a/tests/gateway/test_discord_missed_message_backfill.py b/tests/gateway/test_discord_missed_message_backfill.py
index 1d7d422f6bb..ac162d2c09f 100644
--- a/tests/gateway/test_discord_missed_message_backfill.py
+++ b/tests/gateway/test_discord_missed_message_backfill.py
@@ -348,6 +348,19 @@ def test_missed_message_backfill_config_stays_per_adapter():
assert second._missed_message_backfill_max_dispatches() == 3
+def test_explicit_empty_backfill_channel_list_disables_the_scan(monkeypatch):
+ """``channels: []`` is the operator saying "scan nothing" — it must not fall through to the
+ allowed ∪ free-response default (which would scan channels they disabled). The default
+ ``channels: ""`` still falls through."""
+ monkeypatch.setenv("DISCORD_ALLOWED_CHANNELS", "555")
+ explicit = DiscordAdapter(PlatformConfig(
+ enabled=True, token="one", extra={"missed_message_backfill": {"enabled": True, "channels": []}}))
+ assert explicit._missed_message_backfill_channels() == set()
+ default = DiscordAdapter(PlatformConfig(
+ enabled=True, token="two", extra={"missed_message_backfill": {"enabled": True, "channels": ""}}))
+ assert "555" in default._missed_message_backfill_channels()
+
+
def test_recovery_ledger_prunes_expired_rows(adapter):
old = (datetime.now(timezone.utc) - dt.timedelta(days=31)).isoformat()