# Replay for non-deterministic change

**URL:** https://community.temporal.io/t/replay-for-non-deterministic-change/8572
**Category:** Community Support
**Tags:** go-sdk
**Created:** [June 20, 2023, 7:44am UTC](https://community.temporal.io/t/replay-for-non-deterministic-change/8572 "2023-06-20T07:44:22Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Kevin\_Meng](https://avatars.discourse-cdn.com/v4/letter/k/eb9ed0/32.png) [@Kevin\_Meng](https://community.temporal.io/u/Kevin_Meng)
#### Post date: [June 20, 2023, 7:44am UTC](https://community.temporal.io/t/replay-for-non-deterministic-change/8572/1 "2023-06-20T07:44:22Z")

</div>

I was trying to write some example code to understand how replay could detect non-deterministic workflow code change. The workflow code is like

```auto
import (
	"context"
	"time"

	"go.temporal.io/sdk/activity"
	"go.temporal.io/sdk/workflow"
)

type ActivityOutput struct {
	Output string
}

func Workflow(ctx workflow.Context, name string) error {
	ao := workflow.ActivityOptions{
		StartToCloseTimeout: 10 * time.Second,
	}
	ctx = workflow.WithActivityOptions(ctx, ao)

	logger := workflow.GetLogger(ctx)
	logger.Info("Workflow started", "name", name)

	var result ActivityOutput
	err := workflow.ExecuteActivity(ctx, ActivityA).Get(ctx, &result)
	if err != nil {
		logger.Error("Activity failed.", "Error", err)
		return err
	}

	logger.Info("sleep for a while")
	_ = workflow.Sleep(ctx, time.Second*10)
	return nil
}

func ActivityA(ctx context.Context) (ActivityOutput, error) {
	logger := activity.GetLogger(ctx)
	logger.Info("enter ActivityA")
	return ActivityOutput{
		Output: "ActivityA",
	}, nil
}

func ActivityB(ctx context.Context) (ActivityOutput, error) {
	logger := activity.GetLogger(ctx)
	logger.Info("enter ActivityB")
	return ActivityOutput{
		Output: "ActivityB",
	}, nil
}

func ActivityC(ctx context.Context) (ActivityOutput, error) {
	logger := activity.GetLogger(ctx)
	logger.Info("enter ActivityC")
	return ActivityOutput{
		Output: "ActivityC",
	}, nil
}

```

After the workflow execution reached the sleep, I killed the worker, changed the code to execute `ActivityB` instead of ‘ActivityA’, then I started a new worker with the new workflow definition, hoping the new worker could pick up the previous workflow execution and replay event histories on this new workflow definition. My expectation was that it would cause a non-deterministic error since the replay expected `ActivityB` instead getting `ActivityA` from the event history. But actually the workflow execution run to complete successfully out of my expectation. I’m wondering why.

Here’s a screen shot of the workflow execution event history.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/temporal/original/2X/d/d17112249f4dd144e205bc3ff88cf95ff4490184.jpeg)

---

<div class="post-metadata">

### Author: ![antonio.perez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/antonio.perez/32/2417_2.png) [@antonio.perez](https://community.temporal.io/u/antonio.perez)
#### Post date: [June 21, 2023, 3:34pm UTC](https://community.temporal.io/t/replay-for-non-deterministic-change/8572/3 "2023-06-21T15:34:56Z")

</div>

Hello @Kevin_Meng

I guess there are some edge cases in which the SDK does not compare the activity name on replay.

Can you try the following?

```auto
- activityA
- sleep
- activityB

```

when the workflow reaches sleep, stop the worker and swap activityA and activityB, and start the worker again

```auto
- activityB
- sleep
- activityA

```

When the timer fires you should get a non-deterministic error.

Let me know how it goes.  
Antonio

---

<div class="post-metadata">

### Author: ![Kevin\_Meng](https://avatars.discourse-cdn.com/v4/letter/k/eb9ed0/32.png) [@Kevin\_Meng](https://community.temporal.io/u/Kevin_Meng)
#### Post date: [June 21, 2023, 10:41pm UTC](https://community.temporal.io/t/replay-for-non-deterministic-change/8572/4 "2023-06-21T22:41:23Z")

</div>

I have the same doubt about this is an edge case.

The previous workflow definition is like

```auto
- ActivityA
- Sleep

```

then I change `ActivityA` to `ActivityB` and add a new `ActivityC` after the sleep like this

```auto
- ActivityB
- Sleep
- ActivityC

```

If I kill the previous worker when sleeping and replay on the new workflow definition, it causes non-deterministic error which is expected.
