Workflow Versioning didn’t prevent call to unregistered activity

Hi everyone,

I’m facing an issue related to workflow versioning in Temporal and need some clarification.I introduced a new activity inside a versioned block like this:

v := workflow.GetVersion(ctx, “MyChangeID”, workflow.DefaultVersion, 2)
if v >= 2 {
// Newly added activity
var result MyResult
err := workflow.ExecuteActivity(ctx, MyNewActivity, input).Get(ctx, &result)
if err != nil {
   return err
}
}

I forgot to register MyNewActivity in the worker.

However, I expected that already-running workflows (created before introducing version 2) would continue on the old codepath and not attempt to execute this new activity.

But instead, I got this error during replay of an existing workflow:
ActivityNotRegisteredError: activityType=MyNewActivity

Why would a running workflow attempt to execute a newly introduced activity within a versioned block?
Under what conditions does GetVersion not protect against this?

The GetVersion condition is evaluated when it is called. So if the workflow didn’t reach that code it will take the new code path even if workflow started before the change was introduced. This is actually a feature, not a bug as it allows fixing bugs in already running workflows.

If you don’t want this behavior call GetVersion at the beginning of the workflow execution with the same changeID.

Thanks, that makes sense.
Just two quick clarifications:

  1. So for long-running workflows, if the code inside the versioned block hasn’t executed yet (e.g., workflow was sleeping), it will always take the new version once it reaches that line — even if it started before the change, right?

  2. Is there any official doc , design notes or best-practice guide that explains this behavior in-depth? Especially around:

    • when to call GetVersion early in the workflow,

    • patterns for ensuring backward compatibility,

    • pitfalls when adding new activities or child workflows.

  1. Yes, this is by design.
  2. There is a Versioning Workflows course. I didn’t take it so I’m not sure if all of these questions are covered.

For many use cases Worker Versioning is the way to go.

Thank you so much, that really solved my doubt