Skip to content

fix(wechat): check abort flag in streaming loop to honor /stop command#544

Open
Kailigithub wants to merge 1 commit into
lsdefine:mainfrom
Kailigithub:fix/wechat-stop-abort-check
Open

fix(wechat): check abort flag in streaming loop to honor /stop command#544
Kailigithub wants to merge 1 commit into
lsdefine:mainfrom
Kailigithub:fix/wechat-stop-abort-check

Conversation

@Kailigithub
Copy link
Copy Markdown
Contributor

Problem

Closes #396

In WeChat clawbot mode, when a user sends /stop during task execution, the _task_aborted flag is set but _handle() never checks it inside its streaming loop. The loop blocks on dq.get(timeout=300) and continues processing accumulated intermediate results, sending them to the user before finally showing [任务已完成].

Root Cause

The while True loop in _handle() (line 373) only breaks on 'done' in item or queue.Empty timeout. It never checks _task_aborted[uid], so the abort flag is only evaluated after the loop exits — by which time all accumulated results have already been sent.

Fix

Added an abort check at the top of each loop iteration:

if _task_aborted.get(uid): break

Also changed dq.get(timeout=300) to use a try/except for queue.Empty so the abort check runs every 300s instead of blocking indefinitely. This ensures the /stop command takes effect within one queue poll cycle.

Verification

  • python3 -m py_compile frontends/wechatapp.py — no syntax errors
  • ruff check frontends/wechatapp.py — no new issues introduced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: WeChat clawbot 中使用 /stop 命令无法真正停止任务,仍继续发送结果

1 participant