elsa-workflows / elsa-core

A .NET workflows library
https://v3.elsaworkflows.io/
MIT License
5.88k stars 1.06k forks source link

Fix WorkflowActivity to Use Cached Workflow Definitions for Consistent Behavior #5223

Closed sfmskywalker closed 1 month ago

sfmskywalker commented 1 month ago

This PR addresses an issue where WorkflowActivity was directly loading workflow definitions from the store instead of using the cached workflow service. This approach led to the creation of new Activity instances that did not align with the stored workflow graph in the execution context, causing instability and discrepancies during concurrent processing.

Root Cause: The problem was identified as WorkflowActivity bypassing the caching mechanisms designed to handle workflow definitions consistently. This incorrect handling was especially problematic under parallel executions, resulting in mismatched activities within the workflow execution context.

Solution: To rectify this, the PR modifies WorkflowActivity to ensure it utilizes the higher-level cached workflow service. This service maintains already materialized workflows, which will help in keeping consistency across executions and improve performance when workflows are used as activities.

Additional Changes:

  1. Deprecation of direct accesses to the workflow definition store by WorkflowActivity.
  2. Introduction of dependency between the HTTP Lookup cache and the 2nd level cache of the Workflow Definition Service to synchronize workflow object sourcing.
  3. Adjustment of trigger extraction logic from activities to prevent unnecessary trigger record creation.
  4. Update existing triggers to point to the latest published workflow definition versions to ensure they are up-to-date.

Fixes #5222