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)