hermes - ✅(Solved) Fix [Bug]: Telegram gateway processes its own bot-authored messages as inbound DM/topic turns [2 pull requests, 1 comments, 2 participants]

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…
GitHub stats
NousResearch/hermes-agent#11905Fetched 2026-04-18 05:58:21
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×2commented ×1referenced ×1

Error Message

Relevant Logs / Traceback

Root Cause

On current upstream main, gateway/platforms/telegram.py::_should_process_message() has an early DM fast-path:

if not self._is_group_chat(message):
    return True

There is no earlier check that rejects messages authored by self._bot.

So if Telegram delivers a bot-authored private message update back through the adapter, Hermes accepts it as processable input.

I verified this against current upstream origin/main (b449a0e0) with a minimal reproduction using a bot-authored private Message object; _should_process_message(...) still returns True.

PR fix notes

PR #11949: [codex] fix Telegram self-message ingestion in DMs

Description (problem / solution / changelog)

Summary

  • ignore Telegram messages authored by the bot itself before any DM/group gating runs
  • add a regression test covering bot-authored private-topic messages

Root Cause

Telegram's _should_process_message() returned True for all private-chat messages before checking whether the update came from Hermes itself. That allowed bot-authored watcher/system text to re-enter the adapter as fresh inbound user input.

Testing

  • python -m pytest tests/gateway/test_telegram_group_gating.py -q
  • python -m pytest tests/gateway/test_text_batching.py -q -k telegram
  • python -m pytest tests/gateway/test_telegram_*.py -q

Fixes #11905

Changed files

  • gateway/platforms/telegram.py (modified, +8/-0)
  • scripts/release.py (modified, +1/-0)
  • tests/gateway/test_telegram_group_gating.py (modified, +15/-0)

PR #11950: fix(telegram): ignore bot-authored messages to prevent self-ingestion

Description (problem / solution / changelog)

Summary

Fixes #11905 - Telegram gateway was processing its own bot-authored messages as inbound user turns, causing unintended behavior including system notifications re-entering the conversation.

Root Cause

The method in the Telegram adapter did not check if messages were authored by the bot itself. For DMs, it returned unconditionally without filtering bot messages.

Fix

Added a check at the start of to detect and ignore messages where is . This prevents:

  • System/status messages (e.g., "[SYSTEM: Background process ...]") from being processed as user input
  • Bot's own responses from being re-ingested
  • Cross-topic noise from synthetic messages

Test Plan

  • Added test case covering:
    • Regular user messages (should be processed)
    • Bot-authored DM messages (should be ignored)
    • Bot-authored group messages (should be ignored)
  • All existing tests pass

Changes

  • : Added bot check in
  • : Added regression test

Closes #11905

Changed files

  • gateway/platforms/telegram.py (modified, +6/-1)
  • tests/gateway/test_telegram_group_gating.py (modified, +44/-0)

Code Example

2026-04-17 17:02:43,871 INFO gateway.run: inbound message: platform=telegram user=Jack chat=[redacted] msg='OK, so can you make a plan and then do all these fixes?'
2026-04-17 17:02:53,539 INFO gateway.platforms.telegram: [Telegram] Flushing text batch agent:main:telegram:dm:[redacted]:21657 (1 chars)

2026-04-17 18:22:27,980 INFO [20260408_105622_7cd83d] gateway.run: Pre-reset memory flush completed for session 20260408_105622_7cd83d

2026-04-17 18:58:49,311 INFO gateway.run: Watch pattern notification — injecting for telegram
2026-04-17 18:58:50,177 INFO gateway.run: inbound message: platform=telegram user=Jack chat=[redacted] msg='[SYSTEM: Background process proc_fc27dd253825 matched watch pattern "...'

---

20260408_105622_7cd83d|Open Claw Upgrade Blocker #2|session_reset|...|...|gpt-5-codex
20260417_182207_ffea6235|Initial Assistance Prompt||...||gpt-5.4

---

if not self._is_group_chat(message):
    return True

---

message_user = getattr(message, "from_user", None)
if message_user and self._bot and getattr(message_user, "id", None) == getattr(self._bot, "id", None):
    return False
RAW_BUFFERClick to expand / collapse

Bug Description

In Telegram DM topics, Hermes can ingest messages authored by its own bot as fresh inbound user turns.

In practice this means synthetic/system/status text, including [SYSTEM: Background process ...] watcher notifications, can re-enter the Telegram conversation as if it came from the user. That can trigger unintended replies, create cross-topic noise, and make a topic appear stuck or "haunted" even after /reset.

Steps to Reproduce

  1. Run Hermes gateway with Telegram enabled and DM topics in use.
  2. Cause Hermes to emit any Telegram-visible bot-authored message in that DM/topic context.
    • One real path I observed was a watch-pattern background-process notification of the form: [SYSTEM: Background process ... matched watch pattern ...]
  3. Observe the gateway logs.
  4. Hermes records that bot-authored Telegram text as a new inbound message and processes it like a normal user turn.

Expected Behavior

Telegram messages authored by the Hermes bot itself should be ignored by inbound message handling.

In particular:

  • bot-authored private-chat messages should not pass Telegram inbound gating
  • synthetic/system/status messages should not become new user turns
  • /reset should not be undermined by bot-authored follow-on ingestion

Actual Behavior

Bot-authored Telegram/system text is accepted by the Telegram adapter's inbound gate for private chats, then flushed/handled like ordinary user input.

This can survive a /reset, because the reset clears session state but does not fix the underlying self-ingestion path.

Affected Component

  • Gateway (Telegram/Discord/Slack/WhatsApp)

Messaging Platform

  • Telegram

Operating System

Ubuntu 25.10

Python Version

3.11.14

Hermes Version

Hermes Agent v0.9.0 (2026.4.13)

Relevant Logs / Traceback

2026-04-17 17:02:43,871 INFO gateway.run: inbound message: platform=telegram user=Jack chat=[redacted] msg='OK, so can you make a plan and then do all these fixes?'
2026-04-17 17:02:53,539 INFO gateway.platforms.telegram: [Telegram] Flushing text batch agent:main:telegram:dm:[redacted]:21657 (1 chars)

2026-04-17 18:22:27,980 INFO [20260408_105622_7cd83d] gateway.run: Pre-reset memory flush completed for session 20260408_105622_7cd83d

2026-04-17 18:58:49,311 INFO gateway.run: Watch pattern notification — injecting for telegram
2026-04-17 18:58:50,177 INFO gateway.run: inbound message: platform=telegram user=Jack chat=[redacted] msg='[SYSTEM: Background process proc_fc27dd253825 matched watch pattern "...'

Additional session evidence from the local state DB:

20260408_105622_7cd83d|Open Claw Upgrade Blocker #2|session_reset|...|...|gpt-5-codex
20260417_182207_ffea6235|Initial Assistance Prompt||...||gpt-5.4

That shows /reset did create a fresh topic session, but the Telegram self-ingestion path still existed afterward.

Root Cause Analysis

On current upstream main, gateway/platforms/telegram.py::_should_process_message() has an early DM fast-path:

if not self._is_group_chat(message):
    return True

There is no earlier check that rejects messages authored by self._bot.

So if Telegram delivers a bot-authored private message update back through the adapter, Hermes accepts it as processable input.

I verified this against current upstream origin/main (b449a0e0) with a minimal reproduction using a bot-authored private Message object; _should_process_message(...) still returns True.

Proposed Fix

Add an early self-message guard in gateway/platforms/telegram.py before the DM fast-path, roughly:

message_user = getattr(message, "from_user", None)
if message_user and self._bot and getattr(message_user, "id", None) == getattr(self._bot, "id", None):
    return False

Also add a regression test that verifies bot-authored Telegram private messages are ignored, including DM-topic scenarios.

Are you willing to submit a PR for this?

  • I'd like to fix this myself and submit a PR

extent analysis

TL;DR

To fix the issue, add a self-message guard in gateway/platforms/telegram.py to ignore bot-authored private messages.

Guidance

  • Identify the gateway/platforms/telegram.py file and locate the _should_process_message() function to apply the proposed fix.
  • Add an early check to reject messages authored by self._bot before the DM fast-path.
  • Verify the fix by testing bot-authored private messages in DM-topic scenarios.
  • Consider adding a regression test to ensure the fix is not broken in future updates.

Example

The proposed fix can be implemented as follows:

message_user = getattr(message, "from_user", None)
if message_user and self._bot and getattr(message_user, "id", None) == getattr(self._bot, "id", None):
    return False

This code checks if the message is authored by the bot and returns False if so, effectively ignoring the message.

Notes

The provided fix assumes that the message object has a from_user attribute and that the self._bot object has an id attribute. If this is not the case, the fix may need to be adjusted accordingly.

Recommendation

Apply the proposed workaround by adding the self-message guard in gateway/platforms/telegram.py to ignore bot-authored private messages, as this is a targeted fix for the identified issue.

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 - ✅(Solved) Fix [Bug]: Telegram gateway processes its own bot-authored messages as inbound DM/topic turns [2 pull requests, 1 comments, 2 participants]