From 018493a60bf9bc5778039e6dddbbb89a208c6423 Mon Sep 17 00:00:00 2001 From: 6vision Date: Mon, 15 Jun 2026 19:22:16 +0800 Subject: [PATCH] fix(wecom_bot): revert callback image cap to 512KB (2MB inline body rejected by WeCom) The 2MB cap (matching the long-connection upload path) does not work for the callback path: there the whole image is base64-embedded in an AES-encrypted body returned on every poll. A ~1.5MB image (base64 ~2.1MB, encrypted ~2.8MB) makes WeCom reject the finish packet and poll forever, which also surfaces as a truncated text bubble and WeCom's own timeout error. Cap well below that at 512KB so the finish packet is accepted. Co-authored-by: Cursor --- channel/wecom_bot/wecom_bot_channel.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/channel/wecom_bot/wecom_bot_channel.py b/channel/wecom_bot/wecom_bot_channel.py index 062f6aed..8d4601be 100644 --- a/channel/wecom_bot/wecom_bot_channel.py +++ b/channel/wecom_bot/wecom_bot_channel.py @@ -892,9 +892,12 @@ class WecomBotChannel(ChatChannel): if not local_path: return None - # Keep consistent with the long-connection upload path (2MB limit): - # only compress when the image exceeds the cap, otherwise send as-is. - callback_max_size = 2 * 1024 * 1024 + # Unlike the long-connection path (which uploads and sends only a tiny + # media_id), the callback reply embeds the whole image as base64 inside + # an AES-encrypted body that is returned on EVERY poll. Empirically a + # ~1.5MB image (base64 ~2.1MB, encrypted ~2.8MB) makes WeCom reject the + # finish packet and poll forever, so cap well below that. + callback_max_size = 512 * 1024 if os.path.getsize(local_path) > callback_max_size: compressed = self._compress_image(local_path, callback_max_size) if compressed: