From 5aca54c08336a1f7074218921c5ab6d78cddebca Mon Sep 17 00:00:00 2001 From: 6vision Date: Sat, 30 May 2026 15:48:27 +0800 Subject: [PATCH] fix(wechatmp): flush cached segments while task still running Previously the passive reply only drained the cache after the agent task fully finished, so for long multi-turn tasks the user could not retrieve already-cached intermediate segments. Now return cached segments as soon as they are available, even while the task is still running; the next user message fetches the rest. Co-authored-by: Cursor --- channel/wechatmp/passive_reply.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/channel/wechatmp/passive_reply.py b/channel/wechatmp/passive_reply.py index 6206e0e7..85b3b402 100644 --- a/channel/wechatmp/passive_reply.py +++ b/channel/wechatmp/passive_reply.py @@ -103,14 +103,21 @@ class Query: task_running = True waiting_until = request_time + 4 while time.time() < waiting_until: - if from_user in channel.running: - time.sleep(0.1) - else: + if from_user not in channel.running: task_running = False break + # Task still running, but if it has already produced cached + # segments (e.g. multi-turn thinking output), return them now + # instead of forcing the user to wait for the whole task. The + # remaining segments are fetched by the user's next message. + if channel.cache_dict.get(from_user): + break + time.sleep(0.1) reply_text = "" - if task_running: + # Only fall back to retry / "thinking" hint when the task is still + # running AND there is nothing cached to send yet. + if task_running and not channel.cache_dict.get(from_user): if request_cnt < 3: # waiting for timeout (the POST request will be closed by Wechat official server) time.sleep(2)