Skip to content

The agent that grows with you

fix(feishu): avoid threading regular replies

LeonSGP43f59c451f818d
diff --git a/plugins/platforms/feishu/adapter.py b/plugins/platforms/feishu/adapter.py
index aa6ec796def..05e8d541c79 100644
--- a/plugins/platforms/feishu/adapter.py
+++ b/plugins/platforms/feishu/adapter.py
@@ -2588,7 +2588,10 @@ class FeishuAdapter(BasePlatformAdapter):
if hint:
text = f"{hint}\n\n{text}" if text else hint
- thread_id = getattr(message, "thread_id", None) or getattr(message, "root_id", None) or None
+ # Only a native ``thread_id`` marks a topic. ``root_id`` is present on every quoted reply
+ # too, so using it as a fallback (#19711) turned ordinary quote replies into topic
+ # sessions and pushed the bot's answer into a fresh thread (#20548).
+ thread_id = getattr(message, "thread_id", None) or None
reply_to_message_id = (
getattr(message, "parent_id", None) or getattr(message, "upper_message_id", None)
or getattr(message, "root_id", None) or None
diff --git a/tests/gateway/test_feishu.py b/tests/gateway/test_feishu.py
index 490e9fff003..062e192c69b 100644
--- a/tests/gateway/test_feishu.py
+++ b/tests/gateway/test_feishu.py
@@ -2528,6 +2528,63 @@ class TestFeishuProcessInboundMessage(unittest.TestCase):
self.assertNotIn("[Mentioned:", event.text)
self.assertTrue(event.text.startswith("/model"))
+ def test_regular_reply_root_id_does_not_become_thread_id(self):
+ adapter = self._build_adapter()
+ adapter._fetch_message_text = AsyncMock(return_value="parent text")
+ message = SimpleNamespace(
+ content=json.dumps({"text": "regular reply"}),
+ message_type="text",
+ message_id="m6",
+ mentions=[],
+ chat_id="oc_chat",
+ parent_id=None,
+ upper_message_id=None,
+ root_id="om_root",
+ thread_id=None,
+ )
+
+ asyncio.run(
+ adapter._process_inbound_message(
+ data=message,
+ message=message,
+ sender_id=None,
+ chat_type="group",
+ message_id="m6",
+ )
+ )
+
+ adapter.build_source.assert_called_once()
+ self.assertIsNone(adapter.build_source.call_args.kwargs["thread_id"])
+ event = adapter._dispatch_inbound_event.call_args.args[0]
+ self.assertEqual(event.reply_to_message_id, "om_root")
+ self.assertEqual(event.reply_to_text, "parent text")
+
+ def test_explicit_thread_id_is_preserved(self):
+ adapter = self._build_adapter()
+ message = SimpleNamespace(
+ content=json.dumps({"text": "thread reply"}),
+ message_type="text",
+ message_id="m7",
+ mentions=[],
+ chat_id="oc_chat",
+ parent_id=None,
+ upper_message_id=None,
+ root_id="om_root",
+ thread_id="omt_thread",
+ )
+
+ asyncio.run(
+ adapter._process_inbound_message(
+ data=message,
+ message=message,
+ sender_id=None,
+ chat_type="group",
+ message_id="m7",
+ )
+ )
+
+ adapter.build_source.assert_called_once()
+ self.assertEqual(adapter.build_source.call_args.kwargs["thread_id"], "omt_thread")
class TestFeishuFetchMessageText(unittest.TestCase):
def _build_adapter(self):