elsa-workflows / elsa-workflows/elsa-core

[BUG] Variables aren't restored from persistence for Blocking Activities - RunTask

Open
#5,242 4 comments 0 reactions 0 assignees View on GitHub
bug triaged
Dominant language
C#
Stars
7.9k
Forks
1.5k
Avg merge
15h 22m
Merged PRs (30d)
114

Description

## Description

It seems like the execution context is not restored after a blocking activity is triggered. I've checked the snapshot of a workflow instance and it seems like dynamic variables are not assigned correctly.

## Steps to Reproduce

1. Start a worfklow that contains `ParallelForEach` and `RunTask` activity in it.
2. Once we try to submit a task result via `/elsa/api/tasks/{{taskId}}/complete` we receive a Null Reference Exception (NRE) because the context is not restored and variable is no longer assigned.

```csharp
public class QuorumVotingWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder builder)
{
builder.Version = 1;

var board = builder.WithVariable();

var currentVoteResult = builder.WithVariable();

var votes = builder.WithVariable>();

var approved = builder.WithVariable();

builder.Root = new Sequence
{
Activities =
{
new HttpEndpoint
{
Path = new("/parallel-quorum-vote"),
CanStartWorkflow = true,
SupportedMethods = new([HttpMethods.Post]),
ParsedContent = new(board)
},
new WriteHttpResponse
{
ContentType = new(MediaTypeNames.Application.Json),
Content = new(board.Get),
},
new ParallelForEach()
{
// doesn't work - Null Reference Excetion is thrown after resolution of any of `RunTask`
Items = new(context => board.Get(context).Members),
Body = new Sequence
{
Activities =
{
new RunTask("PromptVote")
{
Result = new Output(currentVoteResult),
Payload = new(context => new Dictionary
{
["User"] = context.GetVariable("CurrentValue"),
})
},
new SetVariable>(
votes,
WorkflowExtensions.SetVotes(currentVoteResult, votes)
)
}
},
},
new QuorumVote()
{
Votes = new(context => votes.Get(context).Values),
Result = new(approved),
},
new If(approved.Get)
{
Then = new WriteLine(context => $"Approved!"),
Else = new WriteLine(context => $"Rejected!")
}
},
};
}
}
```

I've documented the result of the investigation as part of this project: https://github.com/NikiforovAll/elsa-workflows-voting

3. **Attachments**:

https://github.com/NikiforovAll/elsa-workflows-voting

4. **Reproduction Rate**: Every time

5. **Video/Screenshots**:
6. **Additional Configuration**:

## Expected Behavior

I expect workflow to continue working after a blocking activity is resolved

## Actual Behavior
The context is missing

## Screenshots

## Environment
## Log Output
## Troubleshooting Attempts

I've tried various workflows implementations that will suffice my requirement. But the principle remains the same - context is not restored after blocking activities.

## Additional Context
## Related Issues

https://github.com/elsa-workflows/elsa-core/issues/4762

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.