fix(gateway): stream consumer first message drops thread context#13077
Closed
hrygo wants to merge 2 commits into
Closed
fix(gateway): stream consumer first message drops thread context#13077hrygo wants to merge 2 commits into
hrygo wants to merge 2 commits into
Conversation
This was referenced Apr 20, 2026
Closed
e84403b to
2d7860a
Compare
This was referenced Apr 24, 2026
…tream-consumer-thread-routing Cherry-picked commits: - 5500c7d8 fix(gateway): stream consumer first message drops thread context - e84403b9 test(gateway): add regression tests for stream consumer thread routing Fixes: Streaming first message drops thread/topic context in Feishu group topics, Slack threads, Telegram forum topics. Also fixes Feishu fallback path (reply→create) to use thread_id instead of chat_id.
2d7860a to
7554711
Compare
…path When the first streamed message exceeds the platform length limit and gets split into chunks, _send_new_chunk was called with self._message_id (which is None on first send), dropping thread routing entirely. Fallback to self._initial_reply_to_id so overflow chunks land in the correct topic/thread. Also fix a fragile test assertion that could be silently skipped.
teknium1
pushed a commit
that referenced
this pull request
May 10, 2026
Cherry-picked from PR #13077 commits: - 5500c7d8 fix(gateway): stream consumer first message drops thread context - e84403b9 test(gateway): add regression tests for stream consumer thread routing Fixes: Streaming first message drops thread/topic context in Feishu group topics, Slack threads, Telegram forum topics. Adds initial_reply_to_id ctor arg to GatewayStreamConsumer, threaded through _send_or_edit and _send_new_chunk. Also fixes Feishu _send_raw_message fallback path (reply -> create) to use receive_id_type='thread_id' so the new message lands in the correct topic instead of the main channel. Authored by hrygo via PR #13077 (re-attributed from the bot-authored salvage commit on the original branch).
Contributor
|
Merged via salvage PR #23437 (#23437). Your two commits were cherry-picked onto current main with your authorship preserved (re-attributed from the bot-authored commit on your branch to hrygo). We added a test compat fix so the new Feishu fallback test runs in environments without the lark SDK installed, plus an AUTHOR_MAP entry. Conflict against PR #23420 (just-landed #10748 fix) was resolved by merging both fixes in the same chunk loop. Thanks for the fix — this also closes paths #6969 and #9916 as a side effect. |
This was referenced May 10, 2026
Merged
JZKK720
pushed a commit
to JZKK720/hermes-agent
that referenced
this pull request
May 11, 2026
Cherry-picked from PR NousResearch#13077 commits: - 5500c7d8 fix(gateway): stream consumer first message drops thread context - e84403b9 test(gateway): add regression tests for stream consumer thread routing Fixes: Streaming first message drops thread/topic context in Feishu group topics, Slack threads, Telegram forum topics. Adds initial_reply_to_id ctor arg to GatewayStreamConsumer, threaded through _send_or_edit and _send_new_chunk. Also fixes Feishu _send_raw_message fallback path (reply -> create) to use receive_id_type='thread_id' so the new message lands in the correct topic instead of the main channel. Authored by hrygo via PR NousResearch#13077 (re-attributed from the bot-authored salvage commit on the original branch).
rmulligan
pushed a commit
to rmulligan/hermes-agent
that referenced
this pull request
May 11, 2026
Cherry-picked from PR NousResearch#13077 commits: - 5500c7d8 fix(gateway): stream consumer first message drops thread context - e84403b9 test(gateway): add regression tests for stream consumer thread routing Fixes: Streaming first message drops thread/topic context in Feishu group topics, Slack threads, Telegram forum topics. Adds initial_reply_to_id ctor arg to GatewayStreamConsumer, threaded through _send_or_edit and _send_new_chunk. Also fixes Feishu _send_raw_message fallback path (reply -> create) to use receive_id_type='thread_id' so the new message lands in the correct topic instead of the main channel. Authored by hrygo via PR NousResearch#13077 (re-attributed from the bot-authored salvage commit on the original branch).
JinyuID
pushed a commit
to JinyuID/hermes-agent
that referenced
this pull request
May 11, 2026
Cherry-picked from PR NousResearch#13077 commits: - 5500c7d8 fix(gateway): stream consumer first message drops thread context - e84403b9 test(gateway): add regression tests for stream consumer thread routing Fixes: Streaming first message drops thread/topic context in Feishu group topics, Slack threads, Telegram forum topics. Adds initial_reply_to_id ctor arg to GatewayStreamConsumer, threaded through _send_or_edit and _send_new_chunk. Also fixes Feishu _send_raw_message fallback path (reply -> create) to use receive_id_type='thread_id' so the new message lands in the correct topic instead of the main channel. Authored by hrygo via PR NousResearch#13077 (re-attributed from the bot-authored salvage commit on the original branch).
02356abc
pushed a commit
to 02356abc/hermes-agent
that referenced
this pull request
May 14, 2026
Cherry-picked from PR NousResearch#13077 commits: - 5500c7d8 fix(gateway): stream consumer first message drops thread context - e84403b9 test(gateway): add regression tests for stream consumer thread routing Fixes: Streaming first message drops thread/topic context in Feishu group topics, Slack threads, Telegram forum topics. Adds initial_reply_to_id ctor arg to GatewayStreamConsumer, threaded through _send_or_edit and _send_new_chunk. Also fixes Feishu _send_raw_message fallback path (reply -> create) to use receive_id_type='thread_id' so the new message lands in the correct topic instead of the main channel. Authored by hrygo via PR NousResearch#13077 (re-attributed from the bot-authored salvage commit on the original branch).
jsboige
pushed a commit
to jsboige/hermes-agent
that referenced
this pull request
May 14, 2026
Cherry-picked from PR NousResearch#13077 commits: - 5500c7d8 fix(gateway): stream consumer first message drops thread context - e84403b9 test(gateway): add regression tests for stream consumer thread routing Fixes: Streaming first message drops thread/topic context in Feishu group topics, Slack threads, Telegram forum topics. Adds initial_reply_to_id ctor arg to GatewayStreamConsumer, threaded through _send_or_edit and _send_new_chunk. Also fixes Feishu _send_raw_message fallback path (reply -> create) to use receive_id_type='thread_id' so the new message lands in the correct topic instead of the main channel. Authored by hrygo via PR NousResearch#13077 (re-attributed from the bot-authored salvage commit on the original branch).
AlexFoxD
pushed a commit
to AlexFoxD/hermes-agent
that referenced
this pull request
May 21, 2026
Cherry-picked from PR NousResearch#13077 commits: - 5500c7d8 fix(gateway): stream consumer first message drops thread context - e84403b9 test(gateway): add regression tests for stream consumer thread routing Fixes: Streaming first message drops thread/topic context in Feishu group topics, Slack threads, Telegram forum topics. Adds initial_reply_to_id ctor arg to GatewayStreamConsumer, threaded through _send_or_edit and _send_new_chunk. Also fixes Feishu _send_raw_message fallback path (reply -> create) to use receive_id_type='thread_id' so the new message lands in the correct topic instead of the main channel. Authored by hrygo via PR NousResearch#13077 (re-attributed from the bot-authored salvage commit on the original branch).
gweeteve
pushed a commit
to gweeteve/hermes-agent
that referenced
this pull request
Jun 2, 2026
Cherry-picked from PR NousResearch#13077 commits: - 5500c7d8 fix(gateway): stream consumer first message drops thread context - e84403b9 test(gateway): add regression tests for stream consumer thread routing Fixes: Streaming first message drops thread/topic context in Feishu group topics, Slack threads, Telegram forum topics. Adds initial_reply_to_id ctor arg to GatewayStreamConsumer, threaded through _send_or_edit and _send_new_chunk. Also fixes Feishu _send_raw_message fallback path (reply -> create) to use receive_id_type='thread_id' so the new message lands in the correct topic instead of the main channel. Authored by hrygo via PR NousResearch#13077 (re-attributed from the bot-authored salvage commit on the original branch).
Seven74AI
pushed a commit
to Seven74AI/hermes-agent
that referenced
this pull request
Jun 13, 2026
Cherry-picked from PR NousResearch#13077 commits: - 5500c7d8 fix(gateway): stream consumer first message drops thread context - e84403b9 test(gateway): add regression tests for stream consumer thread routing Fixes: Streaming first message drops thread/topic context in Feishu group topics, Slack threads, Telegram forum topics. Adds initial_reply_to_id ctor arg to GatewayStreamConsumer, threaded through _send_or_edit and _send_new_chunk. Also fixes Feishu _send_raw_message fallback path (reply -> create) to use receive_id_type='thread_id' so the new message lands in the correct topic instead of the main channel. Authored by hrygo via PR NousResearch#13077 (re-attributed from the bot-authored salvage commit on the original branch).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a user @mentions the bot inside a group topic thread (Feishu group topic / Slack thread / Telegram forum), the first streamed message chunk is sent via
message.createwithreceive_id=chat_id(the main group) instead of being threaded into the topic. The response — including any visible thinking/reasoning — appears in the main group chat rather than the topic thread.This is a cross-platform architecture defect in
GatewayStreamConsumerthat has been reported multiple times across different platforms:Root Cause
Two bugs:
Bug 1:
GatewayStreamConsumersends first chunk withoutreply_togateway/stream_consumer.py—_send_or_edit()first-message path:self._message_idisNoneon the first send, and no fallbackreply_tois provided. The adapter receivesreply_to=None→ falls tomessage.createwithreceive_id=chat_id→ message lands in main chat.Meanwhile, the non-streaming path in
base.pyhas always correctly passedreply_to=event.message_id. This is why short answers work fine — only streaming (long answers / tool-heavy responses) triggers the bug.Bug 2:
FeishuAdapter._send_raw_messagefallback loses thread contextWhen
message.replyfails (e.g. message withdrawn, error codes in_FEISHU_REPLY_FALLBACK_CODES) and falls back tomessage.create, the fallback usesreceive_id=chat_ideven thoughmetadata.thread_idis available — as independently identified in #9916.Fix (3 files)
gateway/stream_consumer.py__init__accepts optionalinitial_reply_to_id;_send_or_editpasses it asreply_toon first sendgateway/platforms/feishu.py_send_raw_messagefallback checksmetadata.thread_id, usesreceive_id_type="thread_id"instead of"chat_id"gateway/run.pyGatewayStreamConsumercreation sites (proxy path L8000 + local path L8575) passinitial_reply_to_id=event_message_idAffected Platforms
Any platform using topic/thread routing:
Reproduction
Backward Compatibility
initial_reply_to_iddefaults toNone— no impact on existing code or platforms without thread routing.Closes
Closes #6969
Closes #9916
Closes #7355