elsa-workflows / elsa-workflows/elsa-core

CorrelationStrategy blocks all workflow instances when CorrelationId is null

Open
#7,241 0 comments 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 a workflow uses **Activation Strategy = Correlation**, Elsa blocks new workflow instances from starting even when they should be allowed to run. This happens specifically when the `CorrelationId` is `null`, which occurs when executing workflows from the Elsa Studio UI.

## Environment
- **Elsa Version:** 3.x (current)
- **Execution Context:** Elsa Studio UI

## Root Cause

The issue is in the `CorrelationStrategy` class implementation:

**File:** `src/modules/Elsa.Workflows.Runtime/ActivationValidators/CorrelationStrategy.cs`

```csharp
public async ValueTask GetAllowActivationAsync(WorkflowInstantiationStrategyContext context)
{
var filter = new WorkflowInstanceFilter
{
CorrelationId = context.CorrelationId, // ← This is null when executed from UI
WorkflowStatus = WorkflowStatus.Running
};

var count = await workflowInstanceStore.CountAsync(filter);
return count == 0;
}
```

When `context.CorrelationId` is `null`, the filter matches **ALL running workflow instances** (of any correlation), not just instances with the same correlation ID. This causes Elsa to block new instances if **any** instance of any workflow is currently running.

## Steps to Reproduce

1. Create a workflow in Elsa Studio
2. Set **Activation Strategy** to **"Correlation"**
3. Publish the workflow
4. Run the workflow from Elsa Studio UI (using the Run button)
5. Try to run it a second time while the first instance is still running or some other instance is running

**Expected Behavior:**
Since no `CorrelationId` is provided (or it's unique), a new instance should be allowed to start.

**Actual Behavior:**
The workflow is blocked with error: "The workflow cannot be started"

## Impact

- **Workflows cannot be tested from Elsa Studio UI** when using Correlation strategy
- Any API call without explicit `CorrelationId` parameter will be blocked if any workflow instance is running
- This defeats the purpose of the Correlation strategy, which should only block instances with the **same** correlation ID

Contributor guide

Open the contributing guide

Research direction

Start by reading src/modules/Elsa.Workflows.Runtime/ActivationValidators/CorrelationStrategy.cs, especially GetAllowActivationAsync, and trace how WorkflowInstanceFilter handles a null CorrelationId. Reproduce the Elsa Studio workflow steps from the issue, then verify that a null or unique correlation ID does not block activation because of unrelated running instances.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.