Need help with temporal versioning production issue

Hi Team,

Background

Our workflow’s are running in production env and they are long running jobs and we then we have introduced new activity (calling it inside on of the signal) in our workflow definition without taking care of versioning into account. Now post deployment once we have invoked the signal to old running workflow it’s falling with A non-deterministic error has caused the Workflow Task to fail. This usually means the workflow code has a non-backward compatible change without a proper versioning branch check activityType with an expected value 'name: “CompleteWorkItem”
’ and an actual value 'name: “GetReportWorkflow”
error

We understand the problem it’s occurring while temporal replaying the state of old workflow it’s not able to get the new activity which we add in new release

Solution

We looked at the versioning documentation and have couple of document how we can mitigate the issue

int version = Workflow.getVersion("newActivity", Workflow.DEFAULT_VERSION, 1 //. how to get the correct value of this parameter ? );
        if (version == 1) {
            // call new activity 
          invoke activity 
        } 
    // else old flow 

Wanted to understand how to find the correct maxSupported version for our workflow and can we have any unique value for 1 st parameter of .getVersion method need some clarification on how to use the above method to tackle the versioning issue , please help me out

Thanks,
Yogender Singh Tanwar

The workflow can store any number of versions, and they default to -1 if they were not set on previous runs (which is what Workflow.DEFAULT_VERSION is equal to). So the general pattern is to name your version check for the change you are making, and set the maximum supported version to 1. If you have to iterate again, you can set it to 2, in the case where you have to support three concurrent versions.

I hope that helps.