fix(feishu): ensure replies stay inside topic threads in group chats#16018
Closed
highland0971 wants to merge 1 commit into
Closed
fix(feishu): ensure replies stay inside topic threads in group chats#16018highland0971 wants to merge 1 commit into
highland0971 wants to merge 1 commit into
Conversation
Collaborator
4 tasks
9c7e6c2 to
3e7d473
Compare
When a user sends a message inside a Feishu group topic thread, the bot's reply was spawning a new topic instead of staying in the existing thread. This happened because: 1. Inbound: thread_id wasn't being extracted from root_id when the message came from a non-root message inside a topic. 2. Outbound: _send_raw_message had no fallback logic to convert omt_ topic IDs into valid reply targets. 3. Gateway runner: metadata didn't carry reply_to_message_id for Feishu topics, so intermediate/progress messages couldn't use im.v1.message.reply with reply_in_thread=True. Changes: - feishu.py _normalize_inbound_message: fallback thread_id from root_id; add TOPIC_DEBUG logging - feishu.py _send_raw_message: detect omt_ prefix, use reply_to_message_id from metadata; pass root_id when creating messages to place them inside topics - feishu.py _build_create_message_body: accept optional root_id - gateway/run.py: carry reply_to_message_id in metadata for all Feishu topic paths (initial, progress, status, stream consumer) Closes: user-reported bug where bot replies always created new topic threads instead of staying within the existing one.
3e7d473 to
8ec116c
Compare
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 sends a message inside a Feishu group topic thread, the bot's reply spawns a new topic instead of staying inside the existing thread. This affects all message types: final responses, tool progress messages, and streaming partial responses.
Root Cause
Three gaps in the Feishu adapter's topic threading logic:
Inbound normalization (
feishu.py): When a message is a reply within a topic (non-root message),message.thread_idis empty — onlymessage.root_idcontains the topic ID. The code only readthread_id, missing the fallback toroot_id.Outbound send (
_send_raw_message): Feishu uses two ID prefixes:om_→ message ID (valid asreply_toforim.v1.message.reply)omt_→ topic/thread ID (not valid asreply_to— triggers API error 99992354)When
reply_towas empty and onlythread_id(anomt_ID) was available, the code fell through toim.v1.message.createwhich doesn't place messages inside topics.Gateway runner (
run.py): Metadata carriedthread_idbut notreply_to_message_id(the original user message ID), so downstream consumers (stream, progress, status callbacks) couldn't useim.v1.message.replyto stay inside topics.Fix (3 changes)
gateway/platforms/feishu.py_normalize_inbound_message: Addroot_id → thread_idfallback_send_raw_message:om_thread_id (message ID) → use asreply_todirectlyomt_thread_id (topic ID) → usereply_to_message_idfrom metadata as the reply targetroot_idtoim.v1.message.createso new messages land inside the topic_build_create_message_body: Accept optionalroot_idparameterTOPIC_DEBUG/SEND_DEBUGlogging for future troubleshootinggateway/run.pysource.thread_idstarts withomt_, addreply_to_message_id= originalevent_message_idto metadatareply_to_message_idfor Feishu topicsTesting
Verified in production (Feishu group chat with topics enabled). Four scenarios tested: