Go SDK: non-deterministic error

We saw this error recently:

unknown command CommandType: Timer, ID: XXXX, possible causes are nondeterministic workflow definition code or incompatible change in the workflow definition

This is from a scheduled workflow. One activity was changed but the main workflow definition was untouched. We added an event publisher to the struct that implements the workflow. The event is published from an activity.

Can deployments of updated binaries cause this for scheduled workflows?

Example code:

type eventPublisher interface {
	PublishEvent(ctx context.Context)
}

type Workflow struct {
	eventPublisher eventPublisher // this was added
}

// this function wasn't touched at all
func (w *Workflow) DoSomething(ctx workflow.Context) error {
	if err := workflow.ExecuteActivity(ctx, w.DoSomeActivity).Get(ctx, nil); err != nil {
		return err
	}
	return nil
}

func (w *Workflow) DoSomeActivity(ctx context.Context) error {
	// do something

	// we added something like this:
	w.eventPublisher.PublishEvent(ctx)
	return nil
}

I don’t think your published code would cause a deterministic failure.

We recommend against using structures to define workflow function, use them only for activities.

Ok, thanks for the quick reply!

For anyone else looking for answers: it was fixed by deleting the schedule and recreating it through the new deployment.

As for:

We recommend against using structures to define workflow function, use them only for activities.

Good to know, maybe it should be explicitly mentioned here?

Yes, you can see this best practice in the examples, but I think it’s too easy to end up bundling it as a struct.