elsa-workflows/elsa-core · error · Exception

Unable to update WorkflowDefinition with ids

Error message

Unable to update WorkflowDefinition with ids {string.Join(',', duplicates)} multiple times.

What it means

DefaultWorkflowDefinitionStorePopulator's AddOrUpdateCoreAsync detects duplicate workflow definition IDs within a single batch of definitions to upsert. Duplicates would be saved multiple times in one SaveManyAsync call, corrupting the 'latest' flag logic, so it throws with the list of duplicated IDs.

Solutions

  1. Find the source of duplicate definition IDs (the IDs are listed in the message) and deduplicate the input batch.
  2. Regenerate a unique definition ID for one of the duplicated workflow definitions (e.g. copy the JSON with a new ID).
  3. Fix assembly/file scanning so each workflow source is loaded only once per populator run.

Example fix

// before
// two files contain the same definitionId: "my-workflow"
// after
// edit the copied file and set a fresh definitionId, or remove the duplicate file
Defensive patterns

Strategy: validation

Validate before calling

var dupes = definitions.GroupBy(d => d.Id).Where(g => g.Count() > 1).Select(g => g.Key).ToList();
if (dupes.Any()) throw new InvalidOperationException($"Duplicate definition ids in batch: {string.Join(',', dupes)}");

Try / catch

try { await populator.PopulateAsync(definitions); } catch (Exception ex) when (ex.Message.StartsWith("Unable to update WorkflowDefinition")) { logger.LogError(ex, "Duplicate definition ids during registration"); }

Prevention

When it happens

Trigger: A bulk registration/population pass (e.g. scanning multiple assemblies or re-reading the same workflow file twice) that produces two or more WorkflowDefinitions sharing the same ID in one batch.

Common situations: Duplicate workflow files with the same definition ID in different locations; assembly scans loading the same assembly twice; copied workflow JSON where the definition ID was not regenerated.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13). Data as JSON: /api/errors/9752a68cfc65a734. Report an issue: GitHub.

Appendix: source

Thrown at src/modules/Elsa.Workflows.Runtime/Services/DefaultWorkflowDefinitionStorePopulator.cs:251

        workflowDefinition.MaterializerContext = materializerContextJson;
        workflowDefinition.MaterializerName = materializedWorkflow.MaterializerName;

        if (existingDefinitionVersion is null && workflowDefinitionsToSave.Any(w => w.Id == workflowDefinition.Id))
        {
            _logger.LogInformation("Workflow with ID {WorkflowId} already exists", workflowDefinition.Id);
            return workflowDefinition;
        }

        workflowDefinitionsToSave.Add(workflowDefinition);

        var duplicates = workflowDefinitionsToSave.GroupBy(wd => wd.Id)
            .Where(g => g.Count() > 1)
            .Select(g => g.Key)
            .ToList();

        if (duplicates.Any())
        {
            throw new Exception($"Unable to update WorkflowDefinition with ids {string.Join(',', duplicates)} multiple times.");
        }

        await _workflowDefinitionStore.SaveManyAsync(workflowDefinitionsToSave, cancellationToken);
        return workflowDefinition;

        async Task UpdateIsLatest()
        {
            // Always try to update the IsLatest property based on the VersionNumber

            // Reset current latest definitions.
            var filter = new WorkflowDefinitionFilter
            {
                DefinitionId = definitionId,
                VersionOptions = VersionOptions.Latest
            };
            var latestWorkflowDefinitions = (await _workflowDefinitionStore.FindManyAsync(filter, cancellationToken)).ToList();

            // If the latest definitions contains definitions with the same ID then we need to replace them with the latest workflow definitions.

View on GitHub (pinned to fe9217bdfa)