elsa-core
elsa-core copied to clipboard
Preserve Workflow Definition Snapshot in Workflow Instances to Ensure Execution Consistency
Enhancement Request
Enhancement Overview
When executing a workflow definition, the resulting workflow instance reflects live changes made to the workflow definition, even after execution. For example, if a workflow definition initially has 3 activities and a workflow instance is created from it, then later a 4th activity is added to the definition, the previously created instance (which should remain immutable) also reflects the 4th activity. This results in inconsistencies, as the workflow instance does not preserve the graph it originally executed.
Proposed Enhancement
Describe the enhancement you'd like Workflow instances should retain a snapshot of the workflow definition graph at the time of execution. Once a workflow instance is created and execution has begun (or completed), any subsequent modifications to the definition should not impact existing instances.
We also need to consider that when using ScheduleChildActivity, the workflow execution context should resolve and execute based on the persisted graph of the workflow instance, not the latest definition. This would guarantee that child workflows maintain logical consistency and behave as expected even if the parent definition has changed.
Solutions
Replicate column StringData from the workflow definition table to the workflow instance when executing the workflow The input, output, and variable also need to be replicated.
I originally wanted to do exactly this, but I’m glad we didn’t. Some users have many thousands of workflow instances, which already generates a lot of data as it is. Including workflow definitions as well would increase this data cost even further. Not to mention performance - right now we can cache workflow definitions, which we wouldn’t be able to do otherwise without blowing up memory consumption. And also, it wouldn’t help having to cache individual workflow definitions per workflow instance anyway.
So instead, we must treat a given published workflow definitions per version as immutable.
Even though we can’t technically prohibit anyone from breaking this rule, at least the core components should adhere to it.
If you did encounter a scenario where a published workflow definitions got mutated, then that is likely a bug. Including workflow definitions that case, can you please provide steps to reproduce? Thanks!