improve workflow stop event handling

This commit is contained in:
yunlu.wen
2026-04-21 17:18:11 +08:00
parent 91008c0329
commit 87bbcc4e3b
2 changed files with 7 additions and 4 deletions

View File

@@ -410,7 +410,7 @@ class WorkflowBasedAppRunner:
elif isinstance(event, GraphRunFailedEvent):
self._publish_event(QueueWorkflowFailedEvent(error=event.error, exceptions_count=event.exceptions_count))
elif isinstance(event, GraphRunAbortedEvent):
self._publish_event(QueueWorkflowFailedEvent(error=event.reason or "Unknown error", exceptions_count=0))
self._publish_event(QueueWorkflowPartialSuccessEvent(outputs={}, exceptions_count=0))
elif isinstance(event, GraphRunPausedEvent):
runtime_state = workflow_entry.graph_engine.graph_runtime_state
paused_nodes = runtime_state.get_paused_nodes()

View File

@@ -37,10 +37,13 @@ class AppTaskService:
Returns:
None
"""
# Legacy mechanism: Set stop flag in Redis
AppQueueManager.set_stop_flag(task_id, invoke_from, user_id)
# New mechanism: Send stop command via GraphEngine for workflow-based apps
# This ensures proper workflow status recording in the persistence layer
if app_mode in (AppMode.ADVANCED_CHAT, AppMode.WORKFLOW):
# Let the event handler process the Graphon abort event instead of
# stopping the queue listener immediately. Otherwise, events may be
# lost and the workflow run can remain stuck in the running state.
GraphEngineManager(redis_client).send_stop_command(task_id)
else:
# Legacy mechanism: Set stop flag in Redis
AppQueueManager.set_stop_flag(task_id, invoke_from, user_id)