Skip to content

fix(gateway): pass source.thread_id explicitly for Telegram forum routing#7404

Closed
keyuyuan wants to merge 1 commit into
NousResearch:mainfrom
keyuyuan:fix/telegram-thread-id-routing
Closed

fix(gateway): pass source.thread_id explicitly for Telegram forum routing#7404
keyuyuan wants to merge 1 commit into
NousResearch:mainfrom
keyuyuan:fix/telegram-thread-id-routing

Conversation

@keyuyuan

@keyuyuan keyuyuan commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix two adapter.send() calls that used getattr(event, 'metadata', None) instead of explicitly passing source.thread_id, causing responses to land in the wrong Telegram forum topic
  • Applies the same {"thread_id": source.thread_id} if source.thread_id else None pattern used consistently throughout the rest of the gateway

Details

In Telegram supergroups with Topics enabled, two code paths lost the thread context:

  1. Final response send (~line 7581) — when delivering a response before processing a queued follow-up message
  2. Auto-reset notification (~line 2469) — when notifying the user of an automatic session reset

Both used getattr(event, 'metadata', None) which doesn't carry the thread_id from the message source. The event object's metadata is not guaranteed to contain routing info, while source.thread_id is the authoritative value set during message ingestion.

Closes #7355

Test plan

  • Gateway test suite passes (1274 passed, 1 pre-existing failure unrelated to this change)
  • Manual: send a message in a Telegram forum topic, verify the response stays in the same topic
  • Manual: trigger an auto-reset in a forum topic, verify the notification stays in the same topic

Platform

macOS

…ting

Two adapter.send() calls used getattr(event, 'metadata', None) which
does not carry the thread_id from the original message source. In
Telegram forum groups this causes responses to land in the wrong topic
or General.

Replace with the standard pattern used throughout the gateway:
{"thread_id": source.thread_id} if source.thread_id else None

Fixes both the final-response send (line ~7581) and the auto-reset
notification send (line ~2469).

Closes NousResearch#7355
@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter labels Apr 29, 2026
teknium1 pushed a commit that referenced this pull request May 10, 2026
…(carve-out of #7404)

The auto-reset notice ("◐ Session automatically reset…") was being sent
with metadata=getattr(event, 'metadata', None), which can drop or
mis-route in Telegram forum topics: the event's metadata isn't
guaranteed to carry the originating thread_id, so the notice could leak
into General or another topic.

Use the existing self._thread_metadata_for_source(source) helper, which
already handles thread_id construction plus the Telegram DM topic
reply-fallback shape used everywhere else in the gateway.

Carve-out of #7404. The PR's other hunk (line 7578, queued first
response) is already redundant on main — gateway/run.py:15782 has used
_status_thread_metadata since the _thread_metadata_for_source plumbing
landed.

Closes #7355 (path B; paths A and C closed via prior salvage merges).
@teknium1

Copy link
Copy Markdown
Contributor

Merged via salvage PR #23440 (#23440). Your authorship was preserved on the auto-reset hunk. We dropped your second hunk (queued first-response) because it became redundant on main — gateway/run.py:15782 has used _status_thread_metadata since the _thread_metadata_for_source helper landed. The auto-reset hunk was routed through that same helper for consistency with the rest of the gateway. Together with PR #23437 (salvage of #13077), all three failure paths in #7355 are now closed. Thanks for the fix!

@teknium1 teknium1 closed this May 10, 2026
JZKK720 pushed a commit to JZKK720/hermes-agent that referenced this pull request May 11, 2026
…(carve-out of NousResearch#7404)

The auto-reset notice ("◐ Session automatically reset…") was being sent
with metadata=getattr(event, 'metadata', None), which can drop or
mis-route in Telegram forum topics: the event's metadata isn't
guaranteed to carry the originating thread_id, so the notice could leak
into General or another topic.

Use the existing self._thread_metadata_for_source(source) helper, which
already handles thread_id construction plus the Telegram DM topic
reply-fallback shape used everywhere else in the gateway.

Carve-out of NousResearch#7404. The PR's other hunk (line 7578, queued first
response) is already redundant on main — gateway/run.py:15782 has used
_status_thread_metadata since the _thread_metadata_for_source plumbing
landed.

Closes NousResearch#7355 (path B; paths A and C closed via prior salvage merges).
rmulligan pushed a commit to rmulligan/hermes-agent that referenced this pull request May 11, 2026
…(carve-out of NousResearch#7404)

The auto-reset notice ("◐ Session automatically reset…") was being sent
with metadata=getattr(event, 'metadata', None), which can drop or
mis-route in Telegram forum topics: the event's metadata isn't
guaranteed to carry the originating thread_id, so the notice could leak
into General or another topic.

Use the existing self._thread_metadata_for_source(source) helper, which
already handles thread_id construction plus the Telegram DM topic
reply-fallback shape used everywhere else in the gateway.

Carve-out of NousResearch#7404. The PR's other hunk (line 7578, queued first
response) is already redundant on main — gateway/run.py:15782 has used
_status_thread_metadata since the _thread_metadata_for_source plumbing
landed.

Closes NousResearch#7355 (path B; paths A and C closed via prior salvage merges).
JinyuID pushed a commit to JinyuID/hermes-agent that referenced this pull request May 11, 2026
…(carve-out of NousResearch#7404)

The auto-reset notice ("◐ Session automatically reset…") was being sent
with metadata=getattr(event, 'metadata', None), which can drop or
mis-route in Telegram forum topics: the event's metadata isn't
guaranteed to carry the originating thread_id, so the notice could leak
into General or another topic.

Use the existing self._thread_metadata_for_source(source) helper, which
already handles thread_id construction plus the Telegram DM topic
reply-fallback shape used everywhere else in the gateway.

Carve-out of NousResearch#7404. The PR's other hunk (line 7578, queued first
response) is already redundant on main — gateway/run.py:15782 has used
_status_thread_metadata since the _thread_metadata_for_source plumbing
landed.

Closes NousResearch#7355 (path B; paths A and C closed via prior salvage merges).
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
…(carve-out of NousResearch#7404)

The auto-reset notice ("◐ Session automatically reset…") was being sent
with metadata=getattr(event, 'metadata', None), which can drop or
mis-route in Telegram forum topics: the event's metadata isn't
guaranteed to carry the originating thread_id, so the notice could leak
into General or another topic.

Use the existing self._thread_metadata_for_source(source) helper, which
already handles thread_id construction plus the Telegram DM topic
reply-fallback shape used everywhere else in the gateway.

Carve-out of NousResearch#7404. The PR's other hunk (line 7578, queued first
response) is already redundant on main — gateway/run.py:15782 has used
_status_thread_metadata since the _thread_metadata_for_source plumbing
landed.

Closes NousResearch#7355 (path B; paths A and C closed via prior salvage merges).
jsboige pushed a commit to jsboige/hermes-agent that referenced this pull request May 14, 2026
…(carve-out of NousResearch#7404)

The auto-reset notice ("◐ Session automatically reset…") was being sent
with metadata=getattr(event, 'metadata', None), which can drop or
mis-route in Telegram forum topics: the event's metadata isn't
guaranteed to carry the originating thread_id, so the notice could leak
into General or another topic.

Use the existing self._thread_metadata_for_source(source) helper, which
already handles thread_id construction plus the Telegram DM topic
reply-fallback shape used everywhere else in the gateway.

Carve-out of NousResearch#7404. The PR's other hunk (line 7578, queued first
response) is already redundant on main — gateway/run.py:15782 has used
_status_thread_metadata since the _thread_metadata_for_source plumbing
landed.

Closes NousResearch#7355 (path B; paths A and C closed via prior salvage merges).
AlexFoxD pushed a commit to AlexFoxD/hermes-agent that referenced this pull request May 21, 2026
…(carve-out of NousResearch#7404)

The auto-reset notice ("◐ Session automatically reset…") was being sent
with metadata=getattr(event, 'metadata', None), which can drop or
mis-route in Telegram forum topics: the event's metadata isn't
guaranteed to carry the originating thread_id, so the notice could leak
into General or another topic.

Use the existing self._thread_metadata_for_source(source) helper, which
already handles thread_id construction plus the Telegram DM topic
reply-fallback shape used everywhere else in the gateway.

Carve-out of NousResearch#7404. The PR's other hunk (line 7578, queued first
response) is already redundant on main — gateway/run.py:15782 has used
_status_thread_metadata since the _thread_metadata_for_source plumbing
landed.

Closes NousResearch#7355 (path B; paths A and C closed via prior salvage merges).
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
…(carve-out of NousResearch#7404)

The auto-reset notice ("◐ Session automatically reset…") was being sent
with metadata=getattr(event, 'metadata', None), which can drop or
mis-route in Telegram forum topics: the event's metadata isn't
guaranteed to carry the originating thread_id, so the notice could leak
into General or another topic.

Use the existing self._thread_metadata_for_source(source) helper, which
already handles thread_id construction plus the Telegram DM topic
reply-fallback shape used everywhere else in the gateway.

Carve-out of NousResearch#7404. The PR's other hunk (line 7578, queued first
response) is already redundant on main — gateway/run.py:15782 has used
_status_thread_metadata since the _thread_metadata_for_source plumbing
landed.

Closes NousResearch#7355 (path B; paths A and C closed via prior salvage merges).
Seven74AI pushed a commit to Seven74AI/hermes-agent that referenced this pull request Jun 13, 2026
…(carve-out of NousResearch#7404)

The auto-reset notice ("◐ Session automatically reset…") was being sent
with metadata=getattr(event, 'metadata', None), which can drop or
mis-route in Telegram forum topics: the event's metadata isn't
guaranteed to carry the originating thread_id, so the notice could leak
into General or another topic.

Use the existing self._thread_metadata_for_source(source) helper, which
already handles thread_id construction plus the Telegram DM topic
reply-fallback shape used everywhere else in the gateway.

Carve-out of NousResearch#7404. The PR's other hunk (line 7578, queued first
response) is already redundant on main — gateway/run.py:15782 has used
_status_thread_metadata since the _thread_metadata_for_source plumbing
landed.

Closes NousResearch#7355 (path B; paths A and C closed via prior salvage merges).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P1 High — major feature broken, no workaround platform/telegram Telegram bot adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram: Final response chunks lose thread_id, breaking forum topic routing

3 participants