From 877b84837042c4732087cd4a40350208dd2e5c18 Mon Sep 17 00:00:00 2001 From: 6vision Date: Thu, 28 May 2026 14:23:04 +0800 Subject: [PATCH] fix(wechat_kf): stop dropping rapid-fire messages in batch dedup _dedup_image_text_pair previously fell back to returning only the last message whenever the batch was not exactly an image+text pair, which silently dropped multiple texts/images sent in quick succession. Cursor freshness is already guaranteed by sync_msg, so no extra stale-history protection is needed. Now we return all messages by default and only collapse a batch when it is exactly a 2-message image+text pair within a 5s window (order-insensitive, normalized to [image, text]). --- channel/wechat_kf/wechat_kf_channel.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/channel/wechat_kf/wechat_kf_channel.py b/channel/wechat_kf/wechat_kf_channel.py index c2ffc67f..c725ccbd 100644 --- a/channel/wechat_kf/wechat_kf_channel.py +++ b/channel/wechat_kf/wechat_kf_channel.py @@ -479,22 +479,24 @@ class WechatKfChannel(ChatChannel): def _dedup_image_text_pair(messages: list) -> list: """ A WeChat user often sends an image immediately followed by a text - question (e.g. "what's in this picture?"). When that happens we - treat them as one combined turn: image first, then text. - Otherwise (single message or unrelated batch) we return only the - last message to avoid replying to stale history. + question (e.g. "what's in this picture?"). Only when the batch is + exactly that 2-message image+text pair within a 5s window do we + collapse it into a single [image, text] turn. Otherwise return + every message so rapid-fire texts/images are all processed — + cursor freshness is already guaranteed by sync_msg. """ if not messages: return [] - text_messages = [m for m in messages if m["msgtype"] == "text"] - image_messages = [m for m in messages if m["msgtype"] == "image"] - if text_messages and image_messages: - last_text_time = text_messages[-1]["send_time"] - first_image_time = image_messages[0]["send_time"] - if abs(last_text_time - first_image_time) <= 5: - return [image_messages[0], text_messages[-1]] - return [messages[-1]] + if len(messages) == 2: + a, b = messages + types = {a["msgtype"], b["msgtype"]} + if types == {"image", "text"} and abs(a["send_time"] - b["send_time"]) <= 5: + img = a if a["msgtype"] == "image" else b + txt = b if a["msgtype"] == "image" else a + return [img, txt] + + return messages # ----------------------------------------------------------------------