feat:执行状态单例状态bug修复server.py遗漏提交

This commit is contained in:
liailing1026
2026-02-04 11:29:46 +08:00
parent 328f8e7ec6
commit f736cd104a

View File

@@ -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: