How do I restart an opened workflow?

Currently I have a workflow that has been opened and it is still in progress.

Due to some business logic, I want to restart the workflow from the beginning using the same workflowId.

If I try to call WorkflowClient.start(…), I get the following error:
Caused by: io.grpc.StatusRuntimeException: ALREADY_EXISTS: Workflow execution is already running

Is there a way to restart a workflow? How do I do that with the Java SDK?

There are multiple ways to restart a workflow. You can either terminate the previous run and start it again.
Another option is to reset the workflow to its first workflow task.

Thanks for the reply, Maxim. Is there a way to restart it programmatically? Also terminate it programmatically?

All operations UI and CLI expose are going through gRPC APIs of the service. All of these APIs are available for user code as well.

For terminations you can use untyped workflow stub:

    WorkflowStub client =
        workflowClient.newUntypedWorkflowStub(workflowId, Optional.of(runId), Optional.empty());
    client.terminate("No reason");

Awesome. You mentioned there’s a reset workflow option through the CLI but I can’t seem to find that in the sdk-java. Could you point me to it? Thanks.

        WorkflowServiceStubs service =
            WorkflowServiceStubs.newInstance(
                WorkflowServiceStubsOptions.newBuilder().setTarget(serviceAddress).build());
        service.blockingStub().resetWorkflowExecution(request);

Hi @maxim,
I also need to restart a workflow by using Go SDK but I was not able to find the suggested method “untyped workflow stub” in the related SDK. Could you point me to the right code section?
Thanks in advance

It is not yet exposed in Go SDK. We are looking into it.

Any progress on this for the Go SDK?

We didn’t get to this yet. A contribution PR is welcome.

I will add ResetWorkflowExecution API to the Go SDK client.

1 Like

Here is the PR to track: Add ResetWorkflowExecution method to the client by alexshtin · Pull Request #400 · temporalio/sdk-go · GitHub.

1 Like

Hi Maxim. How do i create request object which is passed to resetWorkflowExecution method.
Is there any jar i need to download for Java to create object of ResetWorfklowExecutionRequest. Please help

WorkflowServiceStubs service =
        WorkflowServiceStubs.newInstance(
            WorkflowServiceStubsOptions.newBuilder().setTarget(serviceAddress).build());
    ResetWorkflowExecutionRequest request =
        ResetWorkflowExecutionRequest.newBuilder()
            ...
            .build();
    service.blockingStub(). resetWorkflowExecution(request);

Hi Maxim. When i am trying to reset workflow i am getting exception.

io.grpc.StatusRuntimeException: DEADLINE_EXCEEDED: deadline exceeded after 9.922057800s.

Do you know why this exception occurs?

Do you see any exceptions in the service logs?

Hi Maxim. I was able to resolve the error. But my workflow which is in failure status is not getting restarted from the failure point. Can you please let me know what value i need to pass in setWorkflowTaskFinishEventId method.

ResetWorkflowExecutionRequest request = ResetWorkflowExecutionRequest.newBuilder().setNamespace(“test-nm”)
.setReason(“Testing”).setWorkflowExecution(ex).setWorkflowTaskFinishEventId(2).build();
service.blockingStub().resetWorkflowExecution(request);

It should be eventId of a WorkflowTaskCompleted event.

Thanks Maxim. I was able to finally reset the workflow. But the new workflow keeps on running.
Status is running and in the history the last step displaying is WorkflowTaskScheduled.

Do i need to create any worker for it?

Yes, workflow cannot make progress without the worker.