From f736cd104abaafbf246fff2a13dd867489af994f Mon Sep 17 00:00:00 2001 From: liailing1026 <1815388873@qq.com> Date: Wed, 4 Feb 2026 11:29:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=89=A7=E8=A1=8C=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E5=8D=95=E4=BE=8B=E7=8A=B6=E6=80=81bug=E4=BF=AE=E5=A4=8Dserver?= =?UTF-8?q?.py=E9=81=97=E6=BC=8F=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/server.py | 69 +++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/backend/server.py b/backend/server.py index 01610e5..9f71804 100644 --- a/backend/server.py +++ b/backend/server.py @@ -311,11 +311,19 @@ def Handle_executePlanOptimized(): num_StepToRun: 要运行的步骤数 RehearsalLog: 已执行的历史记录 existingKeyObjects: 已存在的KeyObjects(用于重新执行时传递中间结果) + execution_id: 执行ID(用于多用户隔离) 前端使用 EventSource 接收 """ incoming_data = request.get_json() + # 生成或获取 execution_id + plan = incoming_data.get("plan", {}) + execution_id = incoming_data.get("execution_id") + if not execution_id: + import time + execution_id = f"{plan.get('General Goal', '').replace(' ', '_')}_{int(time.time() * 1000)}" + def generate(): try: for chunk in executePlan_streaming( @@ -324,6 +332,7 @@ def Handle_executePlanOptimized(): RehearsalLog=incoming_data.get("RehearsalLog", []), AgentProfile_Dict=AgentProfile_Dict, existingKeyObjects=incoming_data.get("existingKeyObjects"), + execution_id=execution_id, ): yield chunk except Exception as e: @@ -524,6 +533,7 @@ def handle_execute_plan_optimized_ws(data): num_StepToRun=num_StepToRun, RehearsalLog=RehearsalLog, AgentProfile_Dict=AgentProfile_Dict, + execution_id=execution_id ): emit('progress', { 'id': request_id, @@ -1583,7 +1593,7 @@ def handle_pause_execution(data): "id": "request-id", "action": "pause_execution", "data": { - "goal": "任务描述" + "execution_id": "执行ID" } } """ @@ -1593,36 +1603,32 @@ def handle_pause_execution(data): try: from AgentCoord.RehearsalEngine_V2.execution_state import execution_state_manager - goal = incoming_data.get('goal', '') + execution_id = incoming_data.get('execution_id', '') - # 检查当前执行的任务是否匹配 - current_goal = execution_state_manager.get_goal() - if current_goal and current_goal != goal: - print(f"⚠️ 任务目标不匹配: 当前={current_goal}, 请求={goal}") + if not execution_id: emit('response', { 'id': request_id, 'status': 'error', - 'error': '任务目标不匹配' + 'error': '缺少 execution_id' }) return # 调用执行状态管理器暂停 - success = execution_state_manager.pause_execution() + success = execution_state_manager.pause_execution(execution_id) if success: - print(f"⏸️ [DEBUG] 暂停成功! 当前状态: {execution_state_manager.get_status().value}") - print(f"⏸️ [DEBUG] should_pause: {execution_state_manager._should_pause}") + print(f"⏸️ [DEBUG] 暂停成功! execution_id={execution_id}") emit('response', { 'id': request_id, 'status': 'success', 'data': {"message": "已暂停执行,可随时继续"} }) else: - print(f"⚠️ [DEBUG] 暂停失败,当前状态: {execution_state_manager.get_status().value}") + print(f"⚠️ [DEBUG] 暂停失败,execution_id={execution_id}") emit('response', { 'id': request_id, 'status': 'error', - 'error': f'无法暂停,当前状态: {execution_state_manager.get_status().value}' + 'error': f'无法暂停' }) except Exception as e: @@ -1644,7 +1650,7 @@ def handle_resume_execution(data): "id": "request-id", "action": "resume_execution", "data": { - "goal": "任务描述" + "execution_id": "执行ID" } } """ @@ -1654,35 +1660,32 @@ def handle_resume_execution(data): try: from AgentCoord.RehearsalEngine_V2.execution_state import execution_state_manager - goal = incoming_data.get('goal', '') + execution_id = incoming_data.get('execution_id', '') - # 检查当前执行的任务是否匹配 - current_goal = execution_state_manager.get_goal() - if current_goal and current_goal != goal: - print(f"⚠️ 任务目标不匹配: 当前={current_goal}, 请求={goal}") + if not execution_id: emit('response', { 'id': request_id, 'status': 'error', - 'error': '任务目标不匹配' + 'error': '缺少 execution_id' }) return # 调用执行状态管理器恢复 - success = execution_state_manager.resume_execution() + success = execution_state_manager.resume_execution(execution_id) if success: - print(f"▶️ 已恢复执行: goal={goal}") + print(f"▶️ 已恢复执行: execution_id={execution_id}") emit('response', { 'id': request_id, 'status': 'success', 'data': {"message": "已恢复执行"} }) else: - print(f"⚠️ 恢复失败,当前状态: {execution_state_manager.get_status()}") + print(f"⚠️ 恢复失败,execution_id={execution_id}") emit('response', { 'id': request_id, 'status': 'error', - 'error': f'无法恢复,当前状态: {execution_state_manager.get_status().value}' + 'error': f'无法恢复' }) except Exception as e: @@ -1704,7 +1707,7 @@ def handle_stop_execution(data): "id": "request-id", "action": "stop_execution", "data": { - "goal": "任务描述" + "execution_id": "执行ID" } } """ @@ -1714,36 +1717,32 @@ def handle_stop_execution(data): try: from AgentCoord.RehearsalEngine_V2.execution_state import execution_state_manager - goal = incoming_data.get('goal', '') + execution_id = incoming_data.get('execution_id', '') - # 检查当前执行的任务是否匹配 - current_goal = execution_state_manager.get_goal() - if current_goal and current_goal != goal: - print(f"⚠️ 任务目标不匹配: 当前={current_goal}, 请求={goal}") + if not execution_id: emit('response', { 'id': request_id, 'status': 'error', - 'error': '任务目标不匹配' + 'error': '缺少 execution_id' }) return # 调用执行状态管理器停止 - success = execution_state_manager.stop_execution() + success = execution_state_manager.stop_execution(execution_id) if success: - print(f"🛑 [DEBUG] 停止成功! 当前状态: {execution_state_manager.get_status().value}") - print(f"🛑 [DEBUG] should_stop: {execution_state_manager._should_stop}") + print(f"🛑 [DEBUG] 停止成功! execution_id={execution_id}") emit('response', { 'id': request_id, 'status': 'success', 'data': {"message": "已停止执行"} }) else: - print(f"⚠️ [DEBUG] 停止失败,当前状态: {execution_state_manager.get_status().value}") + print(f"⚠️ [DEBUG] 停止失败,execution_id={execution_id}") emit('response', { 'id': request_id, 'status': 'error', - 'error': f'无法停止,当前状态: {execution_state_manager.get_status().value}' + 'error': f'无法停止' }) except Exception as e: