Always unwind workflow recursion state before fault handling and unexpected execution failures#18990
Open
Always unwind workflow recursion state before fault handling and unexpected execution failures#18990
Conversation
Co-authored-by: sebastienros <1165805+sebastienros@users.noreply.github.com>
Co-authored-by: sebastienros <1165805+sebastienros@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix recursion counter leaks in ExecuteWorkflowAsync method
Always unwind workflow recursion state after unexpected execution failures
Mar 12, 2026
sebastienros
approved these changes
Mar 12, 2026
Member
|
@Smfakhoury Please check the changes |
gvkries
reviewed
Mar 19, 2026
Comment on lines
-473
to
-475
| DecrementRecursion(workflowContext.Workflow); | ||
| _logger.LogError(ex, "An unhandled error occurred while executing an activity. Workflow ID: '{WorkflowTypeId}'. Activity: '{ActivityId}', '{ActivityName}'. Putting the workflow in the faulted state.", workflowType.Id, activityContext.ActivityRecord.ActivityId, activityContext.ActivityRecord.Name); | ||
| workflowContext.Fault(ex, activityContext); | ||
|
|
||
| await _workflowFaultHandler.OnWorkflowFaultAsync(this, workflowContext, activityContext, ex); |
Member
There was a problem hiding this comment.
@copilot In case of an exception, the recursion counter is now decremented after OnWorkflowFaultAsync() is being called. Should that be fixed?
Contributor
Author
There was a problem hiding this comment.
Fixed in a0ec8df. The fault-path now clears the recursion state before calling OnWorkflowFaultAsync, and I added a regression test covering fault-handler reentry so the same workflow can be triggered again from the fault handler.
Co-authored-by: gvkries <7062785+gvkries@users.noreply.github.com>
Copilot
AI
changed the title
Always unwind workflow recursion state after unexpected execution failures
Always unwind workflow recursion state before fault handling and unexpected execution failures
Mar 19, 2026
gvkries
approved these changes
Mar 19, 2026
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.
WorkflowManager.ExecuteWorkflowAsynccould leave recursion counters elevated when an exception escaped outside the activity execution catch block. Once leaked, subsequentTriggerEventAsynccalls for the same workflow type were treated as recursive invocations and skipped with no signal.Execution cleanup
ExecuteWorkflowAsyncintry/finallyso recursion state is always decremented on exit, including unexpected failures while traversing transitions or resolving activities.OnWorkflowFaultAsync()so fault handlers observe cleared recursion state and can safely trigger workflows again.Regression coverage
WorkflowManagerTestscase that reproduces the failure with a transition targeting a non-existent activity.TriggerEventAsynccall is allowed to execute again instead of being silently suppressed by leaked recursion state.Behavioral effect
WorkflowManagerinstance for later triggers in the same scope.Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.