fix(task): stop canceled runs and clear stale task events
This commit is contained in:
parent
b9df354808
commit
0296418cff
@ -577,6 +577,16 @@ async def handle_task_with_sender(terminal: WebTerminal, workspace: UserWorkspac
|
||||
|
||||
iteration = 0
|
||||
while max_iterations is None or iteration < max_iterations:
|
||||
# 检查停止标志
|
||||
stop_entry = get_stop_flag(client_sid, username)
|
||||
if stop_entry and stop_entry.get('stop'):
|
||||
debug_log(f"[Task] 检测到停止标志,退出循环")
|
||||
sender('task_stopped', {
|
||||
'message': '任务已停止',
|
||||
'reason': 'user_requested'
|
||||
})
|
||||
break
|
||||
|
||||
current_iteration = iteration + 1
|
||||
iteration += 1
|
||||
total_iterations += 1
|
||||
|
||||
@ -177,6 +177,9 @@ class TaskManager:
|
||||
with self._lock:
|
||||
rec.status = "cancel_requested"
|
||||
rec.updated_at = time.time()
|
||||
# 清空事件队列,防止新任务读取到旧事件
|
||||
rec.events.clear()
|
||||
debug_log(f"[Task] 任务 {task_id} 已取消,事件队列已清空")
|
||||
return True
|
||||
|
||||
# ---- internal helpers ----
|
||||
|
||||
Loading…
Reference in New Issue
Block a user