Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions plugins/platforms/discord/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import tempfile
import threading
import time
import traceback
from collections import defaultdict
from contextlib import suppress
from typing import Callable, Dict, List, Optional, Any, Tuple
Expand Down Expand Up @@ -2872,6 +2873,17 @@ async def send(
"""
if not self._client:
return SendResult(success=False, error="Not connected")
if not (content or "").strip():
logger.warning(
"[%s] Dropped empty message to chat=%s (caller bug). Call site:\n%s",
self.name,
chat_id,
"".join(traceback.format_stack(limit=12)[:-1]),
)
return SendResult(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This return bypasses the existing failure bookkeeping in send() (_record_discord_response is called by the outer exception path). Please record this failed result with the same reply_to, content, and final arguments before returning, so missed-message backfill retains the failure state for an empty final reply.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 24a3fcc after merging current main 1789e06. The empty-content path now records the failed SendResult through _record_discord_response with the same reply_to, content, and final values before returning. The regression exercises the real backfill database for a whitespace-only final reply and verifies it remains failed/not responded while no Discord I/O occurs.

Validation:

  • current-main RED: the old path called Discord and returned success
  • targeted GREEN: 1 passed
  • Discord send + missed-message backfill: 26 passed
  • all test_discord*.py: 203 passed, 11 environment failures also reproduced on the unmodified baseline (missing aiohttp / incomplete Discord mock); baseline was 202 passed plus this regression failure
  • Ruff, adapter compileall, and git diff --check: passed

The branch is now current with main, mergeable, and the final diff is limited to these two files (+55/-0).

success=False,
error="Refusing to send empty message",
)

try:
# Determine target channel: thread_id in metadata takes precedence.
Expand Down
20 changes: 20 additions & 0 deletions tests/gateway/test_discord_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ def _ensure_discord_mock():
from plugins.platforms.discord.adapter import DiscordAdapter # noqa: E402


@pytest.mark.asyncio
async def test_send_rejects_whitespace_without_calling_discord(caplog):
adapter = DiscordAdapter(PlatformConfig(enabled=True, token="***"))
channel = SimpleNamespace(send=AsyncMock())
get_channel = MagicMock(return_value=channel)
adapter._client = SimpleNamespace(
get_channel=get_channel,
fetch_channel=AsyncMock(),
)

with caplog.at_level("WARNING"):
result = await adapter.send("555", " \n\t ")

assert result.success is False
assert result.error == "Refusing to send empty message"
get_channel.assert_not_called()
channel.send.assert_not_awaited()
assert "Dropped empty message to chat=555" in caplog.text


@pytest.mark.asyncio
async def test_send_retries_without_reference_when_reply_target_is_system_message():
adapter = DiscordAdapter(PlatformConfig(enabled=True, token="***"))
Expand Down