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
- Find the source of duplicate definition IDs (the IDs are listed in the message) and deduplicate the input batch.
- Regenerate a unique definition ID for one of the duplicated workflow definitions (e.g. copy the JSON with a new ID).
- 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
- Deduplicate definitions by ID before bulk population
- Ensure each workflow file/assembly is scanned only once
- Regenerate definition IDs when copying workflow JSON
- Group scanned sources by definition ID during discovery
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
- A workflow definition already exists for definition
- Cannot retract an unpublished workflow definition.
- Invalid variable test values.
- The document declares the same element id more than once…
- Workflow definition with ID
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)