Skip to content

Commit 4a3a271

Browse files
Copilotsfmskywalker
andcommitted
Fix: Skip flowchart-specific processing for non-direct child activities
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>
1 parent 67ba760 commit 4a3a271

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

src/modules/Elsa.Workflows.Core/Activities/Flowchart/Activities/Flowchart.Counters.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ private async ValueTask ProcessChildCompletedAsync(ActivityExecutionContext flow
138138
return;
139139
}
140140

141+
// Check if the completed activity is a direct child of this flowchart.
142+
// If not, skip flowchart-specific processing as the activity is managed by an intermediate container (e.g., sub-process).
143+
var isDirectChild = completedActivityContext.ParentActivityExecutionContext == flowchartContext;
144+
145+
if (!isDirectChild)
146+
{
147+
// The activity is not a direct child, so we don't process its outbound connections.
148+
// Instead, just check if the flowchart should complete.
149+
await CompleteIfNoPendingWorkAsync(flowchartContext);
150+
return;
151+
}
152+
141153
// Schedule the outbound activities
142154
var flowGraph = GetFlowGraph(flowchartContext);
143155
var flowScope = GetFlowScope(flowchartContext);

src/modules/Elsa.Workflows.Core/Activities/Flowchart/Activities/Flowchart.Tokens.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ private async ValueTask OnChildCompletedTokenBasedLogicAsync(ActivityCompletedCo
1313
{
1414
var flowContext = ctx.TargetContext;
1515
var completedActivity = ctx.ChildContext.Activity;
16+
var completedActivityContext = ctx.ChildContext;
1617
var flowGraph = flowContext.GetFlowGraph();
1718
var tokens = GetTokenList(flowContext);
1819

@@ -24,6 +25,22 @@ private async ValueTask OnChildCompletedTokenBasedLogicAsync(ActivityCompletedCo
2425
return;
2526
}
2627

28+
// Check if the completed activity is a direct child of this flowchart.
29+
// If not, skip flowchart-specific processing as the activity is managed by an intermediate container (e.g., sub-process).
30+
var isDirectChild = completedActivityContext.ParentActivityExecutionContext == flowContext;
31+
32+
if (!isDirectChild)
33+
{
34+
// The activity is not a direct child, so we don't process its tokens.
35+
// Instead, just check if the flowchart should complete.
36+
if (!flowContext.HasPendingWork())
37+
{
38+
tokens.Clear();
39+
await flowContext.CompleteActivityAsync();
40+
}
41+
return;
42+
}
43+
2744
// Emit tokens for active outcomes.
2845
var outcomes = (ctx.Result as Outcomes ?? Outcomes.Default).Names;
2946
var outboundConnections = flowGraph.GetOutboundConnections(completedActivity);

0 commit comments

Comments
 (0)