Python: Emit ExecutorFailedEvent before WorkflowFailedEvent when executor throws exception#2537
Merged
moonbox3 merged 3 commits intomicrosoft:mainfrom Dec 2, 2025
Merged
Conversation
Member
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue where ExecutorFailedEvent was not being emitted before WorkflowFailedEvent when an executor throws an exception. The fix ensures that pending events queued via context.add_event() are drained and yielded before WorkflowFailedEvent in the exception handler.
- Added event draining logic in the exception handler of
_run_workflow_with_tracing()to ensureExecutorFailedEventis emitted beforeWorkflowFailedEvent - Added comprehensive test coverage for both start executor failures and non-start executor failures in a chain
- Added test assertions to verify the correct event ordering
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| python/packages/core/agent_framework/_workflows/_workflow.py | Added logic to drain pending events from context before yielding WorkflowFailedEvent in the exception handler |
| python/packages/core/tests/workflow/test_workflow_states.py | Added test coverage for event ordering, including a new PassthroughExecutor class and test_executor_failed_event_from_second_executor_in_chain() test case |
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
eavanvalkenburg
approved these changes
Dec 1, 2025
a1exwang
approved these changes
Dec 1, 2025
dmytrostruk
approved these changes
Dec 2, 2025
arisng
pushed a commit
to arisng/agent-framework
that referenced
this pull request
Feb 2, 2026
…utor throws exception (microsoft#2537) * Emit ExecutorFailedEvent before WorkflowFailedEvent when executor throws exception * Cleanup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
When an executor throws an exception, the
ExecutorFailedEventis queued viacontext.add_event()but never yielded to the stream. This happens because when the start executor fails, it runs beforerun_until_convergence(), so the exception bypasses the runner's event draining logic entirely.The fix is to drain any pending events from the context before yielding
WorkflowFailedEventin the exception handler of_run_workflow_with_tracing().Description
Contribution Checklist