fix(wecom): proactive fallback must not spam one message per delta

The 59c44e9 fallback replied every coalesced delta (~0.8s) as a separate
proactive message once the callback req_id went stale - a wall of
repeating snapshots. Now: intermediate deltas are dropped after a single
'long reply, result will follow' notice; only the final text goes out.
This commit is contained in:
openbot committed 2026-10-24 10:12:19 +08:00
1 parent 59c44e94ca
commit 353db7ba10
2 files changed
+25 -10

No files matched your search

+9 -3
View File
@@ -178,8 +178,14 @@ def test_wecom_stream_falls_back_when_callback_req_stale():
ch, ws = _make_wecom()
ch._ws = ws
ch._req_ids["c1"] = ("req-old", __import__("time").time() - 600) # beyond TTL
ch.push_event("c1", "final", {"text": "late answer"})
respond = [m for m in ws.sent if m["cmd"] == "aibot_respond_msg"]
# intermediate deltas: only ONE proactive notice, no full-snapshot spam
for _ in range(5):
ch.push_event("c1", "delta", {"text": "more words "})
send = [m for m in ws.sent if m["cmd"] == "aibot_send_msg"]
assert len(send) == 1 and "处理完成后" in json.dumps(send[0], ensure_ascii=False)
respond = [m for m in ws.sent if m["cmd"] == "aibot_respond_msg"]
assert respond == [] # stale req_id must NOT be reused
assert send and "late answer" in json.dumps(send[-1])
# final: exactly one proactive message with the full text
ch.push_event("c1", "final", {"text": "late answer"})
send = [m for m in ws.sent if m["cmd"] == "aibot_send_msg"]
assert len(send) == 2 and "late answer" in json.dumps(send[-1], ensure_ascii=False)