elsa-workflows / elsa-workflows/elsa-core

BulkDispatchWorkflows: Parent workflow completes before all child bookmarks are consumed, resulting in lost child completions

Open
#7,405 1 comment 0 reactions 0 assignees View on GitHub
triaged
Dominant language
C#
Stars
7.9k
Forks
1.5k
Avg merge
15h 22m
Merged PRs (30d)
114

Description

## Description

When using a master flowchart with a BulkDispatchWorkflows activity (with WaitForCompletion enabled) to dispatch multiple child workflows, only the first child completion is processed correctly. The parent workflow completes prematurely after the first child's result, and subsequent child completions cannot be processed (bookmark warnings). This leads to lost execution context and the remaining results are never handled by the master workflow.

### Key symptoms:
- Only the first child's results are visible/captured in the parent/master workflow; the rest are not.
- Multiple bookmarkqueueitem rows are created for child completions, but only the first is actually consumed.
- Logs show: `No bookmarks found in the store for filter ...` and `Attempt to resume workflow ... that is not in the Running state. The actual state is Finished` warnings for child completions after the first one.
- The CompletedInstancesCountKey property is not preserved between bookmark resumptions, causing incomplete tracking.

## Steps to Reproduce
1. Create a flowchart that uses BulkDispatchWorkflows (via designer or code) with WaitForCompletion enabled.
2. Use a data array of size 2+ (e.g., 2 items) so multiple child executions occur.
3. In the child workflow, output some unique result (e.g., a key and a status).
4. In the master workflow, on the ChildComplete path, try to record (WriteLine or other) those results.
5. Observe only one result processed and the parent workflow completed. The other child completions leave bookmarks that are never picked up.
6. Check database: bookmarkqueueitem entries are left unprocessed for extra children.
7. Observe logs show the master completed too early to resume remaining bookmarks.

## Expected Behavior
- All child completions should be processed by the master before it completes.
- Bookmark queue items for child completions should all be consumed.
- All child results should be available in the master workflow (e.g., when using WriteLine for WorkflowOutput, see both results).

## Actual Behavior
- Only the first child completion is processed, leading to premature completion of the parent workflow.
- Unprocessed bookmarks left for the remainder. Further attempts to resume master logging warnings about unavailable bookmarks or wrong state.

## Environment
- Elsa Package Version: [e.g., latest 3.x release as of April 2026]
- OS: Windows
- Workflow design: Flowchart in designer using BulkDispatchWorkflows, with WaitForCompletion checked.

## Troubleshooting Attempts
- Verified data in bookmarkqueueitem and bookmarks tables (SQL Server) -- multiple items present but not handled.
- Confirmed that child completions arrive (they do), but master completes too early.
- Used WriteLine to print WorkflowOutput/WorkflowStatus -- always same result for every child (because only first child is processed).

## Additional Context
- See [BulkDispatchWorkflows code, lines tracking child completion](https://github.com/elsa-workflows/elsa-core/blob/main/src/modules/Elsa.Workflows.Runtime/Activities/BulkDispatchWorkflows.cs)
- Possibly related to how context properties (CompletedInstancesCount, DispatchedInstancesCount) are persisted across bookmark resumptions.

## Related Issues
(none found)

Contributor guide

Open the contributing guide

Research direction

Start with src/modules/Elsa.Workflows.Runtime/Activities/BulkDispatchWorkflows.cs, focusing on the child-completion tracking and the CompletedInstancesCount and DispatchedInstancesCount properties across bookmark resumptions. Reproduce the issue with a flowchart, WaitForCompletion enabled, and two child items, then inspect the bookmarkqueueitem and bookmarks records and runtime warnings. Done means every child result is processed and queued bookmarks are consumed before the parent finishes.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.