doc/adr/0005-token-centric-flowchart-execution-model.md
Date: 2025-05-06
Accepted
Elsa Workflows’ original flowchart used execution-count heuristics to drive joins, which fails in loops, XOR splits and resumable activities:
Delay) clear join state on resume.We need a model that:
Adopt a token-centric execution model with explicit MergeMode and blocking:
Tokens
Token with:
FromActivityId, Outcome, ToActivityId,Consumed = false, Blocked = false.ActivityExecutionContext.Properties["Flowchart.Tokens"].MergeMode
MergeMode via GetMergeModeAsync(...). Supported values:
CancelInboundAncestorsAsync).Token.Block() for each.Scheduling Loop
On each child completion:
ToActivityId matches the completed activity.MergeMode and apply the rules above to decide whether to schedule it.State Cleanup
ToActivityId equals the completed activity.HasPendingWork() is false), clear the entire token list and complete the flowchart.OnTokenFlowActivityCanceledAsync), remove all tokens from or to that activity, then re-check for completion.sequenceDiagram
participant A as Activity A
participant F as Flowchart
participant B as Activity B
A-->>F: Completed(outcome="Done")
F->>F: Emit Token(A→B,Block=false,Consumed=false)
F->>F: Consume any inbound tokens for A
F->>F: Get B.MergeMode()
alt Race & first branch
F->>F: CancelInboundAncestors(B)
F-->>B: Schedule B
F->>F: Emit blocked Tokens for other inbound edges into B
else Race & later branch
F->>F: Consume blocked Token
else Converge until all arrived
Note over F: wait
end
F->>F: Purge consumed tokens for A
F-->>F: Complete if no pending work