hermes - 💡(How to fix) Fix feat(discord): add delete_message for cleanup_progress support

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

async def delete_message(self, chat_id: str, message_id: str) -> bool: """Delete a previously sent Discord message.

Used by the stream consumer's cleanup path to remove tool-progress
bubbles after the final response lands. Discord's API supports
deletion of bot-posted messages in any channel the bot can see.
Failures (NotFound, Forbidden) are non-fatal — the caller logs at
debug level and the progress bubbles remain as breadcrumbs.
"""
if not self._client:
    return False
try:
    channel = self._client.get_channel(int(chat_id))
    if not channel:
        channel = await self._client.fetch_channel(int(chat_id))
    if not channel:
        return False

    message = await channel.fetch_message(int(message_id))
    await message.delete()
    return True
except (discord.NotFound, discord.Forbidden) as e:
    logger.debug(
        "[%s] Cannot delete message %s: %s",
        self.name, message_id, e,
    )
    return False
except Exception as e:
    logger.warning(
        "[%s] Failed to delete message %s: %s",
        self.name, message_id, e,
    )
    return False

Root Cause

The gateway supports display.platforms.<name>.cleanup_progress: true — when enabled, tool-progress indicator messages (e.g. 🔍 web_search: "query", 💻 terminal: "cd ...") are deleted after the final response lands, keeping the chat clean. This works on Telegram but silently disables itself on Discord because DiscordAdapter doesn't override delete_message.

Fix Action

Fix / Workaround

  • Telegram: gateway/platforms/telegram.py (line 1450) — identical pattern
  • Base adapter: gateway/platforms/base.py (line 1497) — default no-op returning False
  • Cleanup dispatcher: gateway/run.py (lines 14995-15025) — calls delete_message after final response

Code Example

async def delete_message(self, chat_id: str, message_id: str) -> bool:
    """Delete a previously sent Discord message.

    Used by the stream consumer's cleanup path to remove tool-progress
    bubbles after the final response lands. Discord's API supports
    deletion of bot-posted messages in any channel the bot can see.
    Failures (NotFound, Forbidden) are non-fatal — the caller logs at
    debug level and the progress bubbles remain as breadcrumbs.
    """
    if not self._client:
        return False
    try:
        channel = self._client.get_channel(int(chat_id))
        if not channel:
            channel = await self._client.fetch_channel(int(chat_id))
        if not channel:
            return False

        message = await channel.fetch_message(int(message_id))
        await message.delete()
        return True
    except (discord.NotFound, discord.Forbidden) as e:
        logger.debug(
            "[%s] Cannot delete message %s: %s",
            self.name, message_id, e,
        )
        return False
    except Exception as e:
        logger.warning(
            "[%s] Failed to delete message %s: %s",
            self.name, message_id, e,
        )
        return False

---

display:
  platforms:
    discord:
      cleanup_progress: true
RAW_BUFFERClick to expand / collapse

Feature: Add delete_message to Discord adapter for progress cleanup

Problem

The gateway supports display.platforms.<name>.cleanup_progress: true — when enabled, tool-progress indicator messages (e.g. 🔍 web_search: "query", 💻 terminal: "cd ...") are deleted after the final response lands, keeping the chat clean. This works on Telegram but silently disables itself on Discord because DiscordAdapter doesn't override delete_message.

Impact

Users who want to see live tool progress (rather than disabling it entirely) currently have two bad choices on Discord:

  1. Leave tool_progress: all — progress messages permanently clutter the channel
  2. Set tool_progress: off — lose all visibility into what the agent is doing mid-response

With cleanup_progress working on Discord, users could have both: live progress indicators during execution that auto-vanish when the answer arrives.

Proposed Implementation

Add a delete_message method to DiscordAdapter in gateway/platforms/discord.py:

async def delete_message(self, chat_id: str, message_id: str) -> bool:
    """Delete a previously sent Discord message.

    Used by the stream consumer's cleanup path to remove tool-progress
    bubbles after the final response lands. Discord's API supports
    deletion of bot-posted messages in any channel the bot can see.
    Failures (NotFound, Forbidden) are non-fatal — the caller logs at
    debug level and the progress bubbles remain as breadcrumbs.
    """
    if not self._client:
        return False
    try:
        channel = self._client.get_channel(int(chat_id))
        if not channel:
            channel = await self._client.fetch_channel(int(chat_id))
        if not channel:
            return False

        message = await channel.fetch_message(int(message_id))
        await message.delete()
        return True
    except (discord.NotFound, discord.Forbidden) as e:
        logger.debug(
            "[%s] Cannot delete message %s: %s",
            self.name, message_id, e,
        )
        return False
    except Exception as e:
        logger.warning(
            "[%s] Failed to delete message %s: %s",
            self.name, message_id, e,
        )
        return False

Why This Is Safe

  • discord.Forbidden — bot lacks permission to delete in that channel → silent no-op
  • discord.NotFound — message already deleted or channel gone → silent no-op
  • Best-effort only — failures are logged at debug/warning level, never raised
  • Time window — cleanup fires within seconds of the final response; well within Discord's message-deletion window for bot messages
  • Matches Telegram pattern — identical structure to telegram.py's delete_message at line 1450

Usage

After this change, users enable it via config.yaml:

display:
  platforms:
    discord:
      cleanup_progress: true

Optional: also set tool_progress: new to deduplicate repeated identical tool calls for even cleaner output.

Why edit_message Won't Work Here

Discord's adapter doesn't implement edit_message either, and edit_message has different semantics — it replaces the content of an existing message. The progress system currently sends separate progress messages per-tool-update, then wants to delete the entire progress bubble after the final response, not edit it. edit_message is a future improvement for the toolline-accumulation pattern; delete_message is the orthogonal capability needed here.

Prior Art

  • Telegram: gateway/platforms/telegram.py (line 1450) — identical pattern
  • Base adapter: gateway/platforms/base.py (line 1497) — default no-op returning False
  • Cleanup dispatcher: gateway/run.py (lines 14995-15025) — calls delete_message after final response

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - 💡(How to fix) Fix feat(discord): add delete_message for cleanup_progress support