Skip to content

Commit c665f58

Browse files
docs: Add workflow reset documentation (#4029)
* Add workflow reset documentation for .NET SDK * Apply suggestion from @lennessyy * Sync documentation updates * Sync documentation updates * Sync documentation updates * Sync documentation updates * docs: small copyedit --------- Co-authored-by: promptless[bot] <179508745+promptless[bot]@users.noreply.github.com> Co-authored-by: Lenny Chen <[email protected]> Co-authored-by: Lenny Chen <[email protected]>
1 parent c444cd5 commit c665f58

File tree

14 files changed

+630
-103
lines changed

14 files changed

+630
-103
lines changed

docs/develop/dotnet/cancellation.mdx

Lines changed: 86 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
id: cancellation
33
title: Interrupt a Workflow - .NET SDK
44
sidebar_label: Interrupt a Workflow
5-
description: Interrupt Workflow Execution in .NET using the Temporal SDK. Cancel for graceful stops; terminate for forceful stops. Handle Cancellation in Workflow and Activities efficiently.
5+
description:
6+
Interrupt Workflow Execution in .NET using the Temporal SDK. Cancel for graceful stops; terminate for forceful stops.
7+
Handle Cancellation in Workflow and Activities efficiently.
68
toc_max_heading_level: 4
79
keywords:
810
- interrupt workflow execution
@@ -39,16 +41,15 @@ You can interrupt a Workflow Execution in one of the following ways:
3941
- [Cancel](#cancellation): Canceling a Workflow provides a graceful way to stop Workflow Execution.
4042
- [Terminate](#termination): Terminating a Workflow forcefully stops Workflow Execution.
4143

42-
Terminating a Workflow forcefully stops Workflow Execution.
43-
This action resembles killing a process.
44+
Terminating a Workflow forcefully stops Workflow Execution. This action resembles killing a process.
4445

4546
- The system records a `WorkflowExecutionTerminated` event in the Workflow History.
4647
- The termination forcefully and immediately stops the Workflow Execution.
4748
- The Workflow code gets no chance to handle termination.
4849
- A Workflow Task doesn't get scheduled.
4950

50-
In most cases, canceling is preferable because it allows the Workflow to finish gracefully.
51-
Terminate only if the Workflow is stuck and cannot be canceled normally.
51+
In most cases, canceling is preferable because it allows the Workflow to finish gracefully. Terminate only if the
52+
Workflow is stuck and cannot be canceled normally.
5253

5354
## Cancellation {#cancellation}
5455

@@ -63,11 +64,12 @@ To give a Workflow and its Activities the ability to be cancelled, do the follow
6364

6465
**How to handle a Cancellation in a Workflow in .NET.**
6566

66-
Workflow Definitions can be written to respond to cancellation requests.
67-
It is common for an Activity to be run on Cancellation to perform cleanup.
67+
Workflow Definitions can be written to respond to cancellation requests. It is common for an Activity to be run on
68+
Cancellation to perform cleanup.
6869

69-
Cancellation Requests on Workflows cancel the `Workflow.CancellationToken`.
70-
This is the token that is implicitly used for all calls within the workflow as well (e.g. Timers, Activities, etc) and therefore cancellation is propagated to them to be handled and bubble out.
70+
Cancellation Requests on Workflows cancel the `Workflow.CancellationToken`. This is the token that is implicitly used
71+
for all calls within the workflow as well (e.g. Timers, Activities, etc) and therefore cancellation is propagated to
72+
them to be handled and bubble out.
7173

7274
```csharp
7375
[WorkflowRun]
@@ -111,9 +113,10 @@ public async Task RunAsync()
111113

112114
**How to handle a Cancellation in an Activity using the Temporal .NET SDK**
113115

114-
Ensure that the Activity is [Heartbeating](/develop/dotnet/failure-detection#activity-heartbeats) to receive the Cancellation request and stop execution.
115-
Also make sure that the [Heartbeat Timeout](/develop/dotnet/failure-detection#heartbeat-timeout) is set on the Activity Options when calling from the Workflow.
116-
An Activity Cancellation Request cancels the `CancellationToken` on the `ActivityExecutionContext`.
116+
Ensure that the Activity is [Heartbeating](/develop/dotnet/failure-detection#activity-heartbeats) to receive the
117+
Cancellation request and stop execution. Also make sure that the
118+
[Heartbeat Timeout](/develop/dotnet/failure-detection#heartbeat-timeout) is set on the Activity Options when calling
119+
from the Workflow. An Activity Cancellation Request cancels the `CancellationToken` on the `ActivityExecutionContext`.
117120

118121
```csharp
119122
[Activity]
@@ -150,8 +153,8 @@ await handle.CancelAsync();
150153

151154
**How to request Cancellation of an Activity in .NET using the Temporal .NET SDK**
152155

153-
By default, Activities are automatically cancelled when the Workflow is cancelled since the workflow cancellation token is used by activities by default.
154-
To issue a cancellation explicitly, a new cancellation token can be created.
156+
By default, Activities are automatically cancelled when the Workflow is cancelled since the workflow cancellation token
157+
is used by activities by default. To issue a cancellation explicitly, a new cancellation token can be created.
155158

156159
```csharp
157160
[WorkflowRun]
@@ -187,7 +190,9 @@ public async Task RunAsync()
187190

188191
**How to Terminate a Workflow Execution in .NET using the Temporal .NET SDK**
189192

190-
To Terminate a Workflow Execution in .NET, use the [TerminateAsync()](https://dotnet.temporal.io/api/Temporalio.Client.WorkflowHandle.html#Temporalio_Client_WorkflowHandle_TerminateAsync_System_String_Temporalio_Client_WorkflowTerminateOptions_) method on the Workflow handle.
193+
To Terminate a Workflow Execution in .NET, use the
194+
[TerminateAsync()](https://dotnet.temporal.io/api/Temporalio.Client.WorkflowHandle.html#Temporalio_Client_WorkflowHandle_TerminateAsync_System_String_Temporalio_Client_WorkflowTerminateOptions_)
195+
method on the Workflow handle.
191196

192197
```csharp
193198
// Get a workflow handle by its workflow ID. This could be made specific to a run by passing run ID.
@@ -198,4 +203,69 @@ var handle = myClient.GetWorkflowHandle("my-workflow-id");
198203
await handle.TerminateAsync();
199204
```
200205

201-
Workflow Executions can also be Terminated directly from the WebUI. In this case, a custom note can be logged from the UI when that happens.
206+
Workflow Executions can also be Terminated directly from the WebUI. In this case, a custom note can be logged from the
207+
UI when that happens.
208+
209+
## Reset a Workflow Execution {#reset}
210+
211+
Resetting a Workflow Execution terminates the current Workflow Execution and starts a new Workflow Execution from a
212+
point you specify in its Event History. Use reset when a Workflow is blocked due to a non-deterministic error or other
213+
issues that prevent it from completing.
214+
215+
When you reset a Workflow, the Event History up to the reset point is copied to the new Workflow Execution, and the
216+
Workflow resumes from that point with the current code. Reset only works if you've fixed the underlying issue, such as
217+
removing non-deterministic code. Any progress made after the reset point will be discarded. Provide a reason when
218+
resetting, as it will be recorded in the Event History.
219+
220+
<Tabs>
221+
222+
<TabItem value="web-ui" label="Web UI">
223+
224+
1. Navigate to the Workflow Execution details page,
225+
2. Click the **Reset** button in the top right dropdown menu,
226+
3. Select the Event ID to reset to,
227+
4. Provide a reason for the reset,
228+
5. Confirm the reset.
229+
230+
The Web UI shows available reset points and creates a link to the new Workflow Execution after the reset completes.
231+
232+
</TabItem>
233+
234+
<TabItem value="cli" label="Temporal CLI">
235+
236+
Use the `temporal workflow reset` command to reset a Workflow Execution:
237+
238+
```bash
239+
temporal workflow reset \
240+
--workflow-id <workflow-id> \
241+
--event-id <event-id> \
242+
--reason "Reason for reset"
243+
```
244+
245+
For example:
246+
247+
```bash
248+
temporal workflow reset \
249+
--workflow-id my-background-check \
250+
--event-id 4 \
251+
--reason "Fixed non-deterministic code"
252+
```
253+
254+
By default, the command resets the latest Workflow Execution in the `default` Namespace. Use `--run-id` to reset a
255+
specific run. Use `--namespace` to specify a different Namespace:
256+
257+
```bash
258+
temporal workflow reset \
259+
--workflow-id my-background-check \
260+
--event-id 4 \
261+
--reason "Fixed non-deterministic code" \
262+
--namespace my-namespace \
263+
--tls-cert-path /path/to/cert.pem \
264+
--tls-key-path /path/to/key.pem
265+
```
266+
267+
Monitor the new Workflow Execution after resetting to ensure it completes successfully.
268+
269+
</TabItem>
270+
271+
</Tabs>

docs/develop/dotnet/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ Interrupt a Workflow Execution with a Cancel or Terminate action.
138138
through Workflow cancellation.
139139
- [Terminate a Workflow](/develop/dotnet/cancellation#termination): Interrupt a Workflow Execution and its Activities
140140
through Workflow termination.
141+
- [Reset a Workflow](/develop/dotnet/cancellation#reset): Resume a Workflow Execution from an earlier point in its Event History.
141142

142143
## [Asynchronous Activity completion](/develop/dotnet/asynchronous-activity)
143144

docs/develop/go/cancellation.mdx

Lines changed: 84 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
id: cancellation
33
title: Interrupt a Workflow - Go SDK
44
sidebar_label: Interrupt a Workflow Execution
5-
description: Handle Cancellations in Temporal Workflows and Activities, set Activity Heartbeat Timeouts, and send Cancellation requests from a Temporal Client in Go.
5+
description:
6+
Handle Cancellations in Temporal Workflows and Activities, set Activity Heartbeat Timeouts, and send Cancellation
7+
requests from a Temporal Client in Go.
68
toc_max_heading_level: 4
79
keywords:
810
- cancellation
@@ -26,14 +28,19 @@ This pages shows the following:
2628

2729
**How to handle a Cancellation in a Workflow in Go.**
2830

29-
Workflow Definitions can be written to handle execution cancellation requests with Go's `defer` and the `workflow.NewDisconnectedContext` API.
30-
In the Workflow Definition, there is a special Activity that handles clean up should the execution be cancelled.
31+
Workflow Definitions can be written to handle execution cancellation requests with Go's `defer` and the
32+
`workflow.NewDisconnectedContext` API. In the Workflow Definition, there is a special Activity that handles clean up
33+
should the execution be cancelled.
3134

32-
If the Workflow receives a Cancellation Request, but all Activities gracefully handle the Cancellation, and/or no Activities are skipped then the Workflow status will be Complete.
33-
It is completely up to the needs of the business process and your use case which determines whether you want to return the Cancellation error to show a Canceled status or Complete status regardless of whether a Cancellation has propagated to and/or skipped Activities.
35+
If the Workflow receives a Cancellation Request, but all Activities gracefully handle the Cancellation, and/or no
36+
Activities are skipped then the Workflow status will be Complete. It is completely up to the needs of the business
37+
process and your use case which determines whether you want to return the Cancellation error to show a Canceled status
38+
or Complete status regardless of whether a Cancellation has propagated to and/or skipped Activities.
3439

3540
<!--SNIPSTART go-features-cancellation-workflow {"selectedLines": ["14-15", "18", "20-38", "41", "43-45", "47-50"]}-->
41+
3642
[sample-apps/go/features/cancellation/workflow.go](https://github.com/temporalio/documentation/blob/main/sample-apps/go/features/cancellation/workflow.go)
43+
3744
```go
3845
// ...
3946
// YourWorkflow is a Workflow Definition that shows how it can be canceled.
@@ -72,6 +79,7 @@ func YourWorkflow(ctx workflow.Context) error {
7279
return err
7380
}
7481
```
82+
7583
<!--SNIPEND-->
7684

7785
## Handle Cancellation in an Activity {#handle-cancellation-in-an-activity}
@@ -136,13 +144,75 @@ func main() {
136144

137145
## Heartbeating after a Cancellation
138146

139-
Sometimes you may want to continue running your Activity, even after a Cancellation has been issued.
140-
You may want to completely ignore the cancellation and continue Activity
141-
execution, including Heartbeating, or you may want to send one final Heartbeat after Cancellation.
142-
Even though the context is cancelled when the Workflow is Cancelled, you are still able to send
143-
Activity Heartbeats.
147+
Sometimes you may want to continue running your Activity, even after a Cancellation has been issued. You may want to
148+
completely ignore the cancellation and continue Activity execution, including Heartbeating, or you may want to send one
149+
final Heartbeat after Cancellation. Even though the context is cancelled when the Workflow is Cancelled, you are still
150+
able to send Activity Heartbeats.
151+
152+
When you call `activity.RecordHeartbeat` after Cancellation has occurred, a
153+
`WARN RecordActivityHeartbeat with error Error context canceled` message will be logged, and a `context canceled` error
154+
will be returned from the call. However, the Heartbeat **has** still been sent.
155+
156+
## Reset a Workflow Execution {#reset}
157+
158+
Resetting a Workflow Execution terminates the current Workflow Execution and starts a new Workflow Execution from a
159+
point you specify in its Event History. Use reset when a Workflow is blocked due to a non-deterministic error or other
160+
issues that prevent it from completing.
161+
162+
When you reset a Workflow, the Event History up to the reset point is copied to the new Workflow Execution, and the
163+
Workflow resumes from that point with the current code. Reset only works if you've fixed the underlying issue, such as
164+
removing non-deterministic code. Any progress made after the reset point will be discarded. Provide a reason when
165+
resetting, as it will be recorded in the Event History.
166+
167+
<Tabs>
168+
169+
<TabItem value="web-ui" label="Web UI">
170+
171+
1. Navigate to the Workflow Execution details page,
172+
2. Click the **Reset** button in the top right dropdown menu,
173+
3. Select the Event ID to reset to,
174+
4. Provide a reason for the reset,
175+
5. Confirm the reset.
176+
177+
The Web UI shows available reset points and creates a link to the new Workflow Execution after the reset completes.
178+
179+
</TabItem>
180+
181+
<TabItem value="cli" label="Temporal CLI">
182+
183+
Use the `temporal workflow reset` command to reset a Workflow Execution:
184+
185+
```bash
186+
temporal workflow reset \
187+
--workflow-id <workflow-id> \
188+
--event-id <event-id> \
189+
--reason "Reason for reset"
190+
```
191+
192+
For example:
193+
194+
```bash
195+
temporal workflow reset \
196+
--workflow-id my-background-check \
197+
--event-id 4 \
198+
--reason "Fixed non-deterministic code"
199+
```
200+
201+
By default, the command resets the latest Workflow Execution in the `default` Namespace. Use `--run-id` to reset a
202+
specific run. Use `--namespace` to specify a different Namespace:
203+
204+
```bash
205+
temporal workflow reset \
206+
--workflow-id my-background-check \
207+
--event-id 4 \
208+
--reason "Fixed non-deterministic code" \
209+
--namespace my-namespace \
210+
--tls-cert-path /path/to/cert.pem \
211+
--tls-key-path /path/to/key.pem
212+
```
213+
214+
Monitor the new Workflow Execution after resetting to ensure it completes successfully.
215+
216+
</TabItem>
144217

145-
When you call `activity.RecordHeartbeat` after Cancellation has occurred, a
146-
`WARN RecordActivityHeartbeat with error Error context canceled` message will be logged, and a
147-
`context canceled` error will be returned from the call. However, the
148-
Heartbeat **has** still been sent.
218+
</Tabs>

docs/develop/go/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ Send messages to and read the state of Workflow Executions.
8787
Interrupt a Workflow Execution with a Cancel or Terminate action.
8888

8989
- [Handle a Workflow Cancellation Request](/develop/go/cancellation#handle-cancellation-in-workflow): Interrupt a Workflow Execution and its Activities through Workflow cancellation.
90+
- [Reset a Workflow](/develop/go/cancellation#reset): Resume a Workflow Execution from an earlier point in its Event History.
9091
- [Request Cancellation](/develop/go/cancellation#request-cancellation)
9192

9293
## [Asynchronous Activity completion](/develop/go/asynchronous-activity-completion)

0 commit comments

Comments
 (0)