Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Outputs from activities which are run asynchronously not captured in ActivityExecutionRecord #6227

Open
bobhauser opened this issue Dec 19, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@bobhauser
Copy link
Contributor

Description

There is an option on activities to have them run asynchronously (when Kind == ActivityKind.Task). When these activities are executed asynchronously their outputs are not properly reported in the associated ActivityExecutionRecord - only outputs that are actively mapped to a variable appear, unmapped outputs are always reported as null.

Additionally, only mapped outputs are reported in the activity output register, but incorrectly - all mapped outputs are reported to the activity output register with the output name of "output". This implies that you would not ever be able to map the outputs from an activity which was run asynchronously to a subsequent activity.

Steps to Reproduce

  1. Create a test activity similar to this
[Activity("Elsa.Test", Kind = ActivityKind.Task)]
internal class SampleActivity : CodeActivity
{

    public SampleActivity()
    {
        RunAsynchronously = true;
    }

    public Input<int>? Number1 { get; set; } = default;
    public Input<int>? Number2 { get; set; } = default;
    public Output<int>? Sum { get; set; } = default;
    public Output<int>? Product { get; set; } = default;

    protected override void Execute(ActivityExecutionContext context)
    {
        int number1 = context.Get(Number1);
        int number2 = context.Get(Number2);

        context.Set(Sum, number1 + number2);
        context.Set(Product, number1 * number2);
    }
}
  1. Run a workflow that uses this activity
TestWorkflow workflow = new(workflowBuilder =>
	{
		workflowBuilder.DefinitionId = "sampleWorkflow";
		workflowBuilder.Id = "sampleWorkflow";

		var variable1 = new Variable<int>();
		workflowBuilder.Root = new Sequence
		{
			Variables =
			{
				variable1
			},
			Activities =
			{
				new SampleActivity()
				{
					Id = "SampleActivity1",
					RunAsynchronously = runAsynchronously,
					Number1 = new(4),
					Number2 = new(8),
					Sum = new(variable1),
					Product = null, 
				}
			}
		};
	}
);
  1. Notice that the associated ActivityExecutionRecord only contains the mapped Sum output value, and that the unmapped Product output is indicated to be null.
    image
  2. Also notice that activity output register only shows the value for the mapped value. And that the name of the output is incorrectly set as "output", not "Sum"
    image

Expected Behavior

My expectation is that all outputs, mapped or not, are properly reported in the ActivityExecutionRecord regardless of whether they are run synchronously or asynchronously.

As well, I would expect that all outputs are properly recorded in the activity output register.

Actual Behavior

Only mapped outputs are reported properly in the ActivityExecutionRecord when the activity is run asynchronously (they are all reported properly currently when run synchronously).

Also, when run asynchornously, only mapped outputs appear in the activity output register, but with an output name of "output". As well, I would expect that all outputs are properly recorded in the activity output register (again, they are all reported properly currently when run synchronously).

Environment

  • Elsa Package Version: 3.3 RC4
@sfmskywalker
Copy link
Member

Hi @bobhauser

Thanks for the detailed analysis. You're right, the output should be recorded regardless of whether they're bound to a variable or not.

I'll take a look at your PR - many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants