[PR #28328] refactor: consume events after pause/abort and improve API clarity #32014

Closed
opened 2026-02-21 20:50:35 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/28328

State: closed
Merged: Yes


Summary

This PR refactors the workflow dispatcher and execution coordinator to improve event handling reliability and API clarity.

Related Issue: #28327

Changes

Dispatcher (api/core/workflow/graph_engine/orchestration/dispatcher.py)

  • Simplified dispatcher loop to ensure all remaining events are consumed after execution stops (pause/abort/completion)
  • Removed unused event_collector parameter
  • Replaced _should_check_commands method with _process_commands for clearer intent
  • Added explicit event consumption loop after main dispatcher loop exits

Execution Coordinator (api/core/workflow/graph_engine/orchestration/execution_coordinator.py)

  • Renamed check_commands() to process_commands() for better clarity
  • Converted is_execution_complete() method to execution_complete property
  • Converted is_paused method to paused property
  • Added aborted property to check abort/error states

Tests

  • Moved dispatcher tests to proper location (orchestration/test_dispatcher.py)
  • Updated all tests to reflect new API
  • Added test for consuming remaining events after pause

Benefits

  • Improved reliability: Events are now guaranteed to be processed even after pause/abort
  • Cleaner API: Properties instead of getter methods follow Python best practices
  • Better clarity: Method names more accurately reflect their purpose
**Original Pull Request:** https://github.com/langgenius/dify/pull/28328 **State:** closed **Merged:** Yes --- ## Summary This PR refactors the workflow dispatcher and execution coordinator to improve event handling reliability and API clarity. **Related Issue:** #28327 ## Changes ### Dispatcher (`api/core/workflow/graph_engine/orchestration/dispatcher.py`) - Simplified dispatcher loop to ensure all remaining events are consumed after execution stops (pause/abort/completion) - Removed unused `event_collector` parameter - Replaced `_should_check_commands` method with `_process_commands` for clearer intent - Added explicit event consumption loop after main dispatcher loop exits ### Execution Coordinator (`api/core/workflow/graph_engine/orchestration/execution_coordinator.py`) - Renamed `check_commands()` to `process_commands()` for better clarity - Converted `is_execution_complete()` method to `execution_complete` property - Converted `is_paused` method to `paused` property - Added `aborted` property to check abort/error states ### Tests - Moved dispatcher tests to proper location (`orchestration/test_dispatcher.py`) - Updated all tests to reflect new API - Added test for consuming remaining events after pause ## Benefits - **Improved reliability**: Events are now guaranteed to be processed even after pause/abort - **Cleaner API**: Properties instead of getter methods follow Python best practices - **Better clarity**: Method names more accurately reflect their purpose
yindo added the pull-request label 2026-02-21 20:50:35 -05:00
yindo closed this issue 2026-02-21 20:50:35 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#32014