elsa-workflows / elsa-workflows/elsa-core
Error occurs when completing a rescheduled step in a workflow which was re-scheduled after completion.
- Dominant language
- C#
- Stars
- 7.9k
- Forks
- 1.5k
- Avg merge
- 15h 22m
- Merged PRs (30d)
- 114
Description
@sfmskywalker
### Description
Error occurs when completing a rescheduled step in a workflow that was moved backward.
**Issue Summary**: When I reschedule a completed step to move the workflow backward and then try to complete that step again, an error is thrown.
**Error Details**: Activity 2c39c6367b2855a0 is not reachable from the flowchart graph. Unable to schedule it's outbound activities.
### Steps to Reproduce
To help us identify the issue more quickly, please follow these guidelines:
1. **Detailed Steps**:
1. Create a workflow containing a Sub-Process
2. Ensure the Sub-Process contains: Event, Join, and If activities (json to create workflow and sub-process is given below)
3. Create a workflow instance using the following API call:
```bash
curl --location 'https://localhost:5001/elsa/api/workflow-definitions/5a23244b1687d561/dispatch' \
--header 'accept: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJodHRwOi8vZWxzYS5hcGkiLCJpc3MiOiJodHRwOi8vZWxzYS5hcGkiLCJleHAiOjE3NTkzMzQ1OTYsImlhdCI6MTc1OTI0ODE5NiwibmFtZSI6ImFkbWluIiwicGVybWlzc2lvbnMiOiIqIiwicm9sZSI6IkFkbWluaXN0cmF0b3IiLCJuYmYiOjE3NTkyNDgxOTZ9.HSo1JQRs1akGdCs67QFHk-6nGjiab0l4hHvtfkhJs6Y' \
--header 'Content-Type: application/json' \
--data '{}'
```
4. Complete steps in the sub-process using event triggers:
```bash
curl --location 'https://localhost:5001/elsa/api/events/SP1-Step1/trigger' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJodHRwOi8vZWxzYS5hcGkiLCJpc3MiOiJodHRwOi8vZWxzYS5hcGkiLCJleHAiOjE3NTkzMzQ1OTYsImlhdCI6MTc1OTI0ODE5NiwibmFtZSI6ImFkbWluIiwicGVybWlzc2lvbnMiOiIqIiwicm9sZSI6IkFkbWluaXN0cmF0b3IiLCJuYmYiOjE3NTkyNDgxOTZ9.HSo1JQRs1akGdCs67QFHk-6nGjiab0l4hHvtfkhJs6Y' \
--data '{
"workflowInstanceId": "27e3969b3b556eba",
"WorkflowExecutionMode": "Synchronous",
"input": {
}
}'
```
5. Move ahead in the workflow by completing subsequent steps
6. When wanting to incomplete a particular step, perform rescheduling using the alterations API:
```bash
curl --location 'https://localhost:5001/elsa/api/alterations/run' \
--header 'Authorization: Bearer eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJodHRwOi8vZWxzYS5hcGkiLCJpc3MiOiJodHRwOi8vZWxzYS5hcGkiLCJleHAiOjE3NTkzMzQ1OTYsImlhdCI6MTc1OTI0ODE5NiwibmFtZSI6ImFkbWluIiwicGVybWlzc2lvbnMiOiIqIiwicm9sZSI6IkFkbWluaXN0cmF0b3IiLCJuYmYiOjE3NTkyNDgxOTZ9.HSo1JQRs1akGdCs67QFHk-6nGjiab0l4hHvtfkhJs6Y' \
--header 'Content-Type: application/json' \
--data '{
"alterations": [
{
"type": "ScheduleActivity",
"activityId": "2c39c6367b2855a0"
}
],
"workflowInstanceIds": [
"27e3969b3b556eba"
]
}'
```
7. Attempt to complete the rescheduled step using the same event trigger API (shown in step 4)
8. Error occurs during step completion
2. **Code Snippets**:
**Main Workflow JSON** that reproduces this issue:
[main-workflow.json](https://github.com/user-attachments/files/22623768/main-workflow.json)
**Sub-Process SP-1 JSON** (demonstrates the Event activities within sub-process):
[SP-1.json](https://github.com/user-attachments/files/22623796/sp-1.json)
**Sub-Process SP-2 JSON** (demonstrates the Event activities within sub-process):
[SP-2.json](https://github.com/user-attachments/files/22623824/sp-2.json)
**Sub-Process SP-3 JSON** (demonstrates the Event activities within sub-process):
[SP-3.json](https://github.com/user-attachments/files/22623838/sp-3.json)
**Sub-Process SP-4 JSON** (demonstrates the Event activities within sub-process):
[SP-4.json](https://github.com/user-attachments/files/22623847/sp-4.json)
3. **Reproduction Rate**: Every time when attempting to complete a rescheduled step
4. **Screenshots**:
5. **Additional Configuration**:
- Workflow always contains Sub-Process
- Sub-Process always contains Event, Join, and If activities
- Issue specifically occurs with rescheduling/backward movement scenarios
### Expected Behavior
After rescheduling a completed step (to move workflow backward), I should be able to complete that step again without any errors. The workflow should continue normally after the step completion.
### Actual Behavior
When attempting to complete a rescheduled step, the following error is thrown:
**Error Message:**
```
Activity 2c39c6367b2855a0 is not reachable from the flowchart graph. Unable to schedule it's outbound activities.
```
**Full Stack Trace:**
```
at Elsa.Workflows.Activities.Flowchart.Activities.Flowchart.ScheduleOutboundActivitiesAsync(FlowGraph flowGraph, FlowScope flowScope, ActivityExecutionContext flowchartContext, IActivity activity, Outcomes outcomes, Boolean completedActivityExecutedByBackwardConnection) in C:\Users\vivek.patel\repos\elsa\elsa-core\src\modules\Elsa.Workflows.Core\Activities\Flowchart\Activities\Flowchart.cs:line 206
at Elsa.Workflows.Activities.Flowchart.Activities.Flowchart.OnChildCompletedAsync(ActivityCompletedContext context) in C:\Users\vivek.patel\repos\elsa\elsa-core\src\modules\Elsa.Workflows.Core\Activities\Flowchart\Activities\Flowchart.cs:line 177
at Elsa.Workflows.Behaviors.ScheduledChildCallbackBehavior.OnActivityCompletedAsync(ActivityCompleted signal, SignalContext context) in C:\Users\vivek.patel\repos\elsa\elsa-core\src\modules\Elsa.Workflows.Core\Behaviors\ScheduledChildCallbackBehavior.cs:line 37
at Elsa.Workflows.Behavior.Elsa.Workflows.ISignalHandler.ReceiveSignalAsync(Object signal, SignalContext context) in C:\Users\vivek.patel\repos\elsa\elsa-core\src\modules\Elsa.Workflows.Core\Abstractions\Behavior.cs:line 101
at Elsa.Workflows.Activity.Elsa.Workflows.ISignalHandler.ReceiveSignalAsync(Object signal, SignalContext context) in C:\Users\vivek.patel\repos\elsa\elsa-core\src\modules\Elsa.Workflows.Core\Abstractions\Activity.cs:line 207
at Elsa.Extensions.ActivityExecutionContextExtensions.SendSignalAsync(ActivityExecutionContext context, Object signal) in C:\Users\vivek.patel\repos\elsa\elsa-core\src\modules\Elsa.Workflows.Core\Extensions\ActivityExecutionContextExtensions.cs:line 237
at Elsa.Workflows.ActivityExecutionContext.CompleteActivityAsync(Object result) in C:\Users\vivek.patel\repos\elsa\elsa-core\src\modules\Elsa.Workflows.Core\Contexts\ActivityExecutionContext.Complete.cs:line 48
at Elsa.Workflows.Runtime.Activities.Event.CompleteInternalAsync(ActivityExecutionContext context) in C:\Users\vivek.patel\repos\elsa\elsa-core\src\modules\Elsa.Workflows.Runtime\Activities\Event.cs:line 84
at Elsa.Workflows.Middleware.Activities.DefaultActivityInvokerMiddleware.ExecuteActivityAsync(ActivityExecutionContext context) in C:\Users\vivek.patel\repos\elsa\elsa-core\src\modules\Elsa.Workflows.Core\Middleware\Activities\DefaultActivityInvokerMiddleware.cs:line 111
at Elsa.Workflows.Runtime.Middleware.Activities.BackgroundActivityInvokerMiddleware.ExecuteActivityAsync(ActivityExecutionContext context) in C:\Users\vivek.patel\repos\elsa\elsa-core\src\modules\Elsa.Workflows.Runtime\Middleware\Activities\BackgroundActivityInvokerMiddleware.cs:line 47
at Elsa.Workflows.Middleware.Activities.DefaultActivityInvokerMiddleware.InvokeAsync(ActivityExecutionContext context) in C:\Users\vivek.patel\repos\elsa\elsa-core\src\modules\Elsa.Workflows.Core\Middleware\Activities\DefaultActivityInvokerMiddleware.cs:line 67
at Elsa.Workflows.Runtime.Middleware.EvaluateLogPersistenceModesMiddleware.InvokeAsync(ActivityExecutionContext context) in C:\Users\vivek.patel\repos\elsa\elsa-core\src\modules\Elsa.Workflows.Runtime\LogPersistence\Middleware\EvaluateLogPersistenceModesMiddleware.cs:line 14
at Elsa.Workflows.Middleware.Activities.NotificationPublishingMiddleware.InvokeAsync(ActivityExecutionContext context) in C:\Users\vivek.patel\repos\elsa\elsa-core\src\modules\Elsa.Workflows.Core\Middleware\Activities\NotificationPublishingMiddleware.cs:line 28
at Elsa.Workflows.Middleware.Activities.ExecutionLogMiddleware.InvokeAsync(ActivityExecutionContext context) in C:\Users\vivek.patel\repos\elsa\elsa-core\src\modules\Elsa.Workflows.Core\Middleware\Activities\ExecutionLogMiddleware.cs:line 31
at Elsa.Workflows.Middleware.Activities.ExceptionHandlingMiddleware.InvokeAsync(ActivityExecutionContext context) in C:\Users\vivek.patel\repos\elsa\elsa-core\src\modules\Elsa.Workflows.Core\Middleware\Activities\ExceptionHandlingMiddleware.cs:line 30
```
**Root Cause Analysis:**
Upon debugging, I found that the flowchart graph is taking reference of the main workflow nodes, which only contains SP-1, SP-2, SP-3, and SP-4 sub-process activities. The individual steps within the sub-processes (like step-1, step-2) are not present in the main workflow's flowchart graph, causing the activity `2c39c6367b2855a0` (Event1 "SP1-Step1" from SP-1 sub-process) to be considered as a dangling node that is not reachable from the flowchart graph.
### Environment
- **Elsa Package Version**: 3.5.0.0
- **Elsa Branch**: develop/3.5.0 (both designer and core)
- **Operating System**: Windows
- **Workflow Structure**: Always contains Sub-Process with Event, Join, and If activities
### Additional Context
**Use Case**: Moving workflow backward by rescheduling completed steps and then attempting to complete them again.
**Frequency**: Occurs consistently when following the rescheduling pattern described above.
Contributor guide
Assessment
This issue has not been assessed yet.