elsa-workflows/elsa-core · error · InvalidOperationException

Workflow instance with ID

Error message

Workflow instance with ID '{workflowInstanceId}' does not exist.

What it means

MemoryWorkflowInstanceStore.UpdateUpdatedTimestampAsync requires an existing workflow instance. When no instance with the given ID exists in the in-memory store, it throws InvalidOperationException stating the instance does not exist, rather than silently succeeding.

Solutions

  1. Verify the workflow instance exists (e.g. via FindAsync) before calling UpdateUpdatedTimestampAsync.
  2. Ensure the same store implementation is used for reading and updating instance timestamps.
  3. Catch InvalidOperationException and treat the update as a no-op or log the missing instance ID.

Example fix

// before
await store.UpdateUpdatedTimestampAsync(instanceId, DateTimeOffset.UtcNow);
// after
var instance = await store.FindAsync(new() { Id = instanceId });
if (instance != null)
    await store.UpdateUpdatedTimestampAsync(instanceId, DateTimeOffset.UtcNow);
Defensive patterns

Strategy: try-catch

Validate before calling

var existing = await store.FindAsync(new() { Id = instanceId });
if (existing == null) return; // nothing to update

Try / catch

try { await store.UpdateUpdatedTimestampAsync(instanceId, timestamp); } catch (InvalidOperationException) { logger.LogWarning("Instance {Id} not found for timestamp update", instanceId); }

Prevention

When it happens

Trigger: Calling UpdateUpdatedTimestampAsync with a workflowInstanceId that was never added to the store, was deleted, or refers to an instance in a different store (e.g. instance persisted in the database while this call hits the memory store).

Common situations: Unit-test setups using the memory store against IDs from a real database; stale IDs after instance deletion; race conditions where the instance was removed concurrently.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at src/modules/Elsa.Workflows.Management/Stores/MemoryWorkflowInstanceStore.cs:166

    /// <inheritdoc />
    public ValueTask<long> DeleteAsync(WorkflowInstanceFilter filter, CancellationToken cancellationToken = default)
    {
        var query = Filter(_store.List().AsQueryable(), filter);
        var count = _store.DeleteMany(query, x => x.Id);
        return ValueTask.FromResult(count);
    }

    /// <inheritdoc />
    public async Task UpdateUpdatedTimestampAsync(string workflowInstanceId, DateTimeOffset value, CancellationToken cancellationToken = default)
    {
        var workflowInstance = await FindAsync(new()
        {
            Id = workflowInstanceId
        }, cancellationToken);
        
        if (workflowInstance == null)
            throw new InvalidOperationException($"Workflow instance with ID '{workflowInstanceId}' does not exist.");
        
        workflowInstance.UpdatedAt = value;
    }

    private static string GetId(WorkflowInstance workflowInstance) => workflowInstance.Id;

    [RequiresUnreferencedCode("Calls Elsa.Workflows.Management.Filters.WorkflowInstanceFilter.Apply(IQueryable<WorkflowInstance>)")]
    private static IQueryable<WorkflowInstance> Filter(IQueryable<WorkflowInstance> query, WorkflowInstanceFilter filter) => filter.Apply(query);
}

View on GitHub (pinned to fe9217bdfa)