From 2990ae840414dbe5ba5dc90ce823b02719e82da7 Mon Sep 17 00:00:00 2001 From: easonysliu Date: Fri, 13 Mar 2026 18:24:36 +0800 Subject: [PATCH] fix: cancel_task returning 404 after successful cancel, and KeyError on forum app - cancel_task(): track whether we actually cancelled the task before checking task.status, since the status was already changed to 'cancelled' by that point - search endpoint: skip apps not in api_ports to avoid KeyError when forum process is running --- ReportEngine/flask_interface.py | 4 ++++ app.py | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ReportEngine/flask_interface.py b/ReportEngine/flask_interface.py index b0f608db2..6e81e2671 100644 --- a/ReportEngine/flask_interface.py +++ b/ReportEngine/flask_interface.py @@ -999,6 +999,7 @@ def cancel_task(task_id: str): try: with task_lock: + cancelled = False if current_task and current_task.task_id == task_id: if current_task.status == "running": current_task.update_status("cancelled", 0, "用户取消任务") @@ -1006,6 +1007,7 @@ def cancel_task(task_id: str): 'message': '任务被用户主动终止', 'task': current_task.to_dict(), }) + cancelled = True current_task = None task = tasks_registry.get(task_id) if task and task.status == 'running': @@ -1014,7 +1016,9 @@ def cancel_task(task_id: str): 'message': '任务被用户主动终止', 'task': task.to_dict(), }) + cancelled = True + if cancelled or (task and task.status == 'cancelled'): return jsonify({ 'success': True, 'message': '任务已取消' diff --git a/app.py b/app.py index 8ad9422f5..c292fcf3c 100644 --- a/app.py +++ b/app.py @@ -1171,8 +1171,10 @@ def search(): # 向运行中的应用发送搜索请求 results = {} api_ports = {'insight': 8501, 'media': 8502, 'query': 8503} - + for app_name in running_apps: + if app_name not in api_ports: + continue try: api_port = api_ports[app_name] # 调用Streamlit应用的API端点