Update method not working as expected

I created a temporal workflow with a update method.
Workflow method has property initialization.
Update method uses the initialization.
When the api starts the workflow and calls the update method at the same time to the temporal, but there are no workers.
When workers are back, Update event gets processed and throws property uninitialised exception. (late init variable)
Ideally i expected that replay should run the start of the workflow first before running the update method (as it builds from history).
Am i missing anything?

Hi,

workflow will be replayed in the same order it was executed for the first time.

Can you share a reproduction?

Antonio


//Workflow method
override fun run(request: OtpWorkflowRequest) {
        otpWorkflowRequest = request
        initialisaitonDone = true
    }

//Update method
override fun verifyOtp(){
    otpWorkflowRequest.copy(destination = "dest")
}

//Client 
starts the workflow (async)
updates the workflow
1: there are no workers. 
2: then workers are provisioned. 
3: update method is executed before run method. 
4: raised uninitialised error

Workflow task processing failure. startedEventId=3, WorkflowId=workflowId+test-1, RunId=0998f6ff-0933-4593-aae1-b16a048eff31. If seen continuously the workflow might be stuck.

 Workflow task processing failure. startedEventId=3, WorkflowId=workflowId+test-1, RunId=a81e897d-9c92-4942-8b45-c614add414ba. If seen continuously the workflow might be stuck.

io.temporal.internal.statemachines.InternalWorkflowTaskException: Failure handling event 3 of type 'EVENT_TYPE_WORKFLOW_TASK_STARTED' during execution. {WorkflowTaskStartedEventId=3, CurrentStartedEventId=3}
	at io.temporal.internal.statemachines.WorkflowStateMachines.createEventProcessingException(WorkflowStateMachines.java:389)
	at io.temporal.internal.statemachines.WorkflowStateMachines.handleEventsBatch(WorkflowStateMachines.java:309)
	at io.temporal.internal.statemachines.WorkflowStateMachines.handleEvent(WorkflowStateMachines.java:272)

Caused by: java.lang.RuntimeException: WorkflowTask: failure executing SCHEDULED->WORKFLOW_TASK_STARTED, transition history is [CREATED->WORKFLOW_TASK_SCHEDULED]
	at io.temporal.internal.statemachines.StateMachine.executeTransition(StateMachine.java:163)
	at io.temporal.internal.statemachines.StateMachine.handleHistoryEvent(StateMachine.java:103)
	at io.temporal.internal.statemachines.EntityStateMachineBase.handleEvent(EntityStateMachineBase.java:84)
	at io.temporal.internal.statemachines.WorkflowStateMachines.handleSingleEvent(WorkflowStateMachines.java:439)
	at io.temporal.internal.statemachines.WorkflowStateMachines.handleEventsBatch(WorkflowStateMachines.java:307)
	... 13 common frames omitted
Caused by: kotlin.UninitializedPropertyAccessException: lateinit property otpWorkflowRequest has not been initialized
	at com.jago.jaguard.worker.workflow.common.OtpWorkflowImpl.verifyOtp(OtpWorkflowImpl.kt:178)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)

This is by design, as update and signal methods are called before unblocking the main workflow method. Without such a feature, signals or updates might be lost.

Use workflow constructor to initialize workflow before these methods are called:

Thankyou Maxim, I will try this!