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

CorrelationId not persisted correctly in BookmarkQueueItems, executing unrelated workflows #6409

Open
pkaaz opened this issue Feb 13, 2025 · 0 comments

Comments

@pkaaz
Copy link
Contributor

pkaaz commented Feb 13, 2025

Description

When you create an event with a correlationId for existing bookmarks it works as expected but if it goes to a queue, it is saved with a null value

Image
Image

This means that when a workflow instance is created it will activate instantly independent of the correlationId. In this case if I start a workflow with an unexpected correlationId, it is still executed. With the BookmarkQueue, giving a correlationId that does not exist puts it in the queue and then depending on the ttl executes it for workflows ignoring the correlationId

Steps to Reproduce

To help us identify the issue more quickly, please follow these guidelines:

  1. Detailed Steps:
    A simple scenario involves only an Event pretty much
    Image
    If I were to run these events with correlation id's:
    Image
    And now throw an event with a correlationId that is not expected
    Image
    Image

Note to achieve the result with 4 events it took 4 requests. For some reason the resume only picks up a single event to resume from the queue

var bookmark = await bookmarkStore.FindAsync(filter, cancellationToken);
  1. Code Snippets:
    In StimulusSender.ResumeExistingWorkflowsAsync the else block seems to be missing the CorrelationId assignment
else
{
    // If no bookmarks were matched, enqueue the request in case a matching bookmark is created in the near future.
    var workflowInstanceId = metadata?.WorkflowInstanceId;

    var bookmarkQueueItem = new NewBookmarkQueueItem
    {
        WorkflowInstanceId = workflowInstanceId,
        BookmarkId = metadata?.BookmarkId,
        StimulusHash = stimulusHash,
        Options = new()
        {
            Input = input,
            Properties = properties
        }
    };
    await bookmarkQueue.EnqueueAsync(bookmarkQueueItem, cancellationToken);
}
  1. Attachments:
    Not sure how useful a 1 event workflow is
    workflow-1.json

  2. Reproduction Rate:
    Pretty much 100% I think there are rare cases where the queue gets removed before executing but that's probably rare.

  3. Video/Screenshots:
    See Steps to reproduced and details above

  4. Additional Configuration:
    BookmarkQueues enabled? (I'm not sure it's something we can turn off) The database doesn't really matter, it's not passed and not saved in any.

Expected Behavior

The event sits in the Queue because no workflow matches with the correlationId

Actual Behavior

The event executes other workflows that don't have the required correlationId to match up

Screenshots

See above

Environment

  • Elsa Package Version: Whatever main branch is, probably 3.3
  • Operating System: Windows 10
  • Browser and Version: Doesn't matter

Log Output

I think I basically provided why in Code Snippets

Troubleshooting Attempts

Breakpoint on trigger endpoint and following down the path to see the issue.

Additional Context

Related Issues

My own comments

I think just passing the CorrelationId in the else block would fix the issue. I can probably make a PR for you if this is not intended, it seems like a simple CorellationId pass between NewBookmarkQueueItem and BookmarkQueueItem. The database already expects this.

On a somewhat unrelated note is there even an option to turn this off?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant