When to cancel a Temporal workflow and when to terminate it
The choice is between letting workflow code clean up and stopping the execution now. Cancellation sends a request to a running workflow. The workflow code receives that request, can run compensation logic, can cancel the activities it started, and decides when to finish. Termination stops the execution immediately. Workflow code does not get a chance to run its cleanup, and activities that were in progress are not allowed to complete. Cancellation fits when the business process has steps that must be undone or closed out, such as releasing a reservation or notifying a customer. Termination fits when code is not responding, or when continuing at all is unsafe and the cleanup can be handled outside Temporal.
The choice matters most for compensation, downstream side effects and audit trails. An activity may already have called an external payment or messaging API before the stop request arrived. A cancelled workflow can reverse that effect because its code is still running. A terminated workflow cannot, so the reversal becomes a manual task for your operations team. Both actions are recorded in the workflow's event history, but they record different things. Cancellation records a request followed by the outcome of the cancellation, while termination records a single terminal event that carries the reason the caller supplied. Confirm the exact event names and fields for your SDK and server versions in the Temporal documentation before you write alerts or audit queries against them.
Before you choose, check three things. First, confirm that the workflow handles cancellation in its code and that its activities are written to respond to cancellation, because a workflow that ignores the request will keep running. Second, decide what reason text the team will require when terminating, so the history explains who stopped the workflow and why. Third, record the reversal steps for any side effects that could already have happened, so an operator knows what to check after a termination. Use cancellation first in most incidents and reserve termination for executions that do not respond to a cancel request within the time your runbook allows.
Cancellation, termination and when each fits
This table compares cancellation and termination of a Temporal workflow on what workflow code runs, whether compensation is possible, what lands in event history, and how each is issued. Read each row as a question to answer for your workflow before an operator reaches for either command. The main takeaway is that cancellation is cooperative and reversible in design, while termination is immediate and leaves no room for cleanup.
| Aspect | Cancellation | Termination |
|---|---|---|
| Workflow code runs | Yes, the workflow receives a cancellation request and can handle it in its code | No, the execution stops without running further workflow code |
| Compensation possible | Yes, cleanup and compensating activities can run before the workflow closes | No, compensation must be run separately by an operator or another process |
| Event history written | A cancellation request event is recorded, followed by the workflow's own closing events | A termination event is recorded as the final event of the execution |
| Can it be undone | No, a cancelled execution is closed, though a new run can be started with the same business ID | No, a terminated execution is closed and cannot be resumed |
| Issued from the CLI | Use the workflow cancel command with the workflow ID or run ID | Use the workflow terminate command with a reason, which is stored in history |
| Issued from an SDK | Call the client cancel method on the workflow handle | Call the client terminate method on the workflow handle with an optional reason |
| Safer default | Routine stops, user-initiated cancellation, and any workflow with saga-style cleanup | Workflows that are stuck and cannot respond, or code that cannot be deployed to handle cancellation |
| What to confirm first | Whether the workflow catches cancellation and how long cleanup activities can run | Whether a cancel attempt has already failed and whether downstream side effects need manual repair |
Running a cancel or terminate safely
This sequence gives operators a repeatable order of checks so a cancellation is tried first, its effect is confirmed in workflow history, and termination is used only when cancellation cannot complete.
Identify the target with a visibility query
Start by finding the executions you intend to act on using a visibility query in the Temporal Web UI or the CLI, filtering on workflow type, status, and business attributes such as customer or order identifiers where your workflows set them. Confirm the query returns only the expected population before going further. Record the count and a sample of workflow IDs in your change ticket. Done when the result set matches what the owning team described, and nothing outside that set appears.
Confirm the workflow ID and run ID
For each target, open the execution and record both the workflow ID and the run ID. The workflow ID can be reused by a newer run, so the run ID tells you which exact execution you are acting on. Check that the status is still Running and that the workflow is not already closing. Done when the pair of IDs is written down and the status shows the execution is still open.
Check whether the workflow handles cancellation
Ask the team that owns the workflow whether its code catches the cancellation signal, runs compensation or cleanup in a cancellation scope, and which activities it expects to finish. Read the workflow source for the handling path if you have access. A workflow that does not handle cancellation will stop at its next wait point without cleanup. Done when the owner has confirmed the expected behavior in writing and you know whether compensation will run.
Send cancellation first
Request cancellation for the specific run ID, using the Web UI cancel action or the CLI cancel command, and avoid terminate at this stage. Cancellation is delivered as a request that the workflow code receives, so the workflow decides how to respond. Record the time and the operator in your change log. Done when the request has been accepted by the service, which you can see as a cancellation request in the execution's history.
Verify the status and history event
Watch the execution until it reaches a terminal status, then open its event history. A successful cancellation shows a cancellation requested event followed by the workflow closing as canceled, with any compensation activities listed in between. If the workflow is still running after your agreed checkpoint, or the history shows a workflow task failure instead, stop and investigate rather than escalate straight to terminate. Done when the status is closed as canceled and the history shows the expected cleanup events.
Terminate only when cancellation cannot complete
Use terminate only if cancellation has not completed, the workflow cannot respond because its worker is unavailable or its code is stuck, and the owner has approved stopping it without cleanup. Terminate stops the execution immediately, so no workflow code runs afterward and no compensation happens. Record the reason and the owner's approval in the change log. Done when the execution shows a terminated close event with your recorded reason attached.
Confirm downstream state after the close
After the execution closes, check the systems the workflow touched, such as payments, orders, or external tickets, against what the workflow would have done. If cancellation ran compensation, confirm those steps completed. If you terminated, list any work that remains half done and hand it to the owning team with the workflow ID and run ID. Done when the owning team has signed off that downstream records are consistent or have a tracked follow-up.
Handle many executions with batch operations
Running this sequence across a large set of executions is covered on a separate page on batch operations from the CLI, which covers batch jobs, progress tracking, and their own safety checks. Use this sequence for single executions or a small pilot of the batch's query results. Done when you have confirmed that the batch process is documented for the population you need to act on.
What each action records in workflow history
A cancellation and a termination leave different trails in workflow history, and that difference is what incident reviewers and auditors rely on. A cancellation request is recorded as an event in the history of the workflow, and the workflow code keeps running after it receives the request. Its cleanup logic, including any activities it schedules in response, appears as ordinary later events after the cancellation request. When you review a cancelled workflow, read the history forward from the cancellation request and confirm which compensating activities ran, which completed, and whether the workflow then closed as cancelled. Confirm the exact event names for your SDK and server version in the Temporal documentation before you write queries or alert rules against them.
A termination closes the workflow without giving workflow code a chance to respond. The history shows the termination as the final event, with no cleanup activities after it, so any work the workflow meant to do was left undone. That absence is the evidence to check: if a termination was recorded while a payment or external update was in progress, the history will not show whether the downstream system received the intended call. Ask the team that ran the termination to record the reason in the termination reason field, and confirm that your deployment keeps that field in the stored history for the retention period your audit requires.
During an incident review, start with the workflow ID and run ID, then read the history to establish the order of events: the request, any compensation, and the close. Auditors typically look for three things: who issued the action, when it was issued, and why. The temporal CLI and API expose the initiating identity only if your authorization layer records it, so confirm that your frontend authorization and audit logging capture the caller for both operations before you rely on them. Treat the history as the record of what the workflow did, and keep your own change or access logs as the record of who acted, because the two sources answer different questions.
Access control and audit for cancel and terminate
Cancelling and terminating a workflow both change production state, so the same access questions apply to each. The cards below cover who should hold these permissions, how the Temporal authorization layer limits them, and what the audit trail should capture when someone acts.
Decide who may cancel and terminate
Separate the people who can request a cancellation from those who can force a termination. A cancellation lets workflow code run its cleanup, so it suits routine operator requests. A termination skips cleanup entirely, so limit it to a small on-call or incident group. Write the rule per namespace and per workflow type, and confirm it with the workflow owners before go-live.
Check the default noopAuthorizer
If no Authorizer is configured, self-hosted Temporal uses the default noopAuthorizer, which allows every API request with no authentication or access control. In that state any caller that can reach the frontend can cancel or terminate any workflow. Confirm the Authorizer is set on every self-hosted cluster before any operator, service or CI job receives network access to the frontend.
Self-hosted security docsMap roles through the ClaimMapper
The ClaimMapper turns JWT or certificate claims into namespace roles, and the Authorizer then decides whether a given role may call a given API. Map a dedicated incident role to termination rights and a separate operator role to cancellation only. Test each mapping with a non-production identity, because a claim that maps to a broader role grants termination without any other warning.
Limit network reach to the frontend
Temporal services should run on hosts that are not reachable from the public internet, with network access restricted to trusted internal networks. Authorization controls who may call the API, but network placement determines who can attempt the call at all. Confirm that workstations, bastions and CI runners only reach the frontend through the paths your security team has approved.
Require mTLS for internal calls
Self-hosted Temporal supports mTLS with separate settings for internode and frontend traffic. Mutual TLS proves which client or service is making a call, which is the identity that the audit trail needs. Without it, a cancel or terminate request can be tied only to a token or a network address, which is weak evidence in an incident review.
Record who acted and why
Workflow history records the terminate or cancel request, but it does not capture the change ticket, the approver or the reason unless your process adds them. Require each manual call to reference a ticket ID, put the requesting identity and reason in the ticket, and copy the workflow ID and run ID into it. Ask your team how these records are retained, since the platform does not set that policy for you.
Decision path for cancel or terminate
The path starts with confirming the workflow is still open in the Temporal Web UI or CLI, since a closed workflow needs neither action. Next, check whether the workflow code handles cancellation and runs its cleanup or compensation steps. If it does, send a cancel request and watch the history for the cleanup activities to finish. Terminate only when cancellation stalls or the code cannot run, then record the outcome in the workflow history and the incident ticket so the next operator can see which path was taken.
Decision path from confirming an open workflow to recording how it was stopped.
Limits to confirm in your environment
Cancellation and termination behave differently depending on your Temporal server version, SDK and the code you have written. The checks below connect the cancellation path to the cleanup window, activity heartbeats and child workflow handling, so you can confirm each one against your own deployment before you choose a stop method for production workflows.
Cancellation handling in workflow code
A cancel request only helps if the workflow code catches the cancellation and runs its cleanup. Check whether your workflows wrap activity calls and timers in cancellation scopes, and whether compensation logic runs when the cancellation arrives. Confirm the exact pattern in your SDK's documentation, because the way cancellation surfaces in workflow code differs between languages. Test it with a workflow you can cancel on purpose, and read the resulting history.
Temporal deployment docsCleanup window in your deployment
Cleanup after a cancel runs inside workflow and activity timeouts, and your deployment sets the limits on how long that can last. Ask your platform team which workflow run timeout and task timeout settings apply to each workflow type, and whether any custom limits exist in your namespace. If a compensation step may take longer than the window allows, plan for it explicitly instead of assuming the cancel will finish.
Heartbeats for activity cancellation
A running activity learns it was cancelled only when it heartbeats or the worker reports the cancellation back to it, depending on how your SDK handles this. Check whether long-running activities send heartbeats, how often, and whether the heartbeat timeout in your activity options is short enough to detect a stuck attempt. Activities that never heartbeat may keep running after the workflow has moved on, which affects both cleanup and cost.
Child workflows and open activities
Termination does not give child workflows or open activities the same chance to clean up that cancellation does. Check the parent close policy set on each child workflow, which decides whether children are cancelled, terminated or left running when the parent ends. Also confirm which activities could still be open at the time of a stop, and whether any external systems need reconciliation afterward.
Recorded history and audit needs
Cancellation and termination each write a different event to workflow history, and your audit or incident process may depend on which one appears. Confirm with your compliance and operations teams what evidence they need, how long history is retained in your visibility and persistence stores, and who is authorized to send either command. Check the exact event names against your server version's documentation rather than relying on memory.
Server version and SDK compatibility
Cancellation and termination behavior can change between Temporal Server releases and SDK versions, so the behavior you tested may not match what you run in production. Record the server version, SDK version and worker build that each environment uses, and confirm the behavior in the release notes for those exact versions. Repeat the cancel and terminate tests after every server upgrade before you change production runbooks.
Upgrade server docsQuestions teams ask before cancelling or terminating workflows
How much does it cost to cancel or terminate Temporal workflows?
Cost depends on how many executions need action, how much cleanup logic each workflow has, and whether the work happens once or repeatedly. The cancel or terminate command itself is cheap to run. The expensive part is deciding which executions to stop, checking what each one has done in its history, and confirming that compensation ran correctly. A fixed-scope quote follows from a written list of workflow types, execution counts and the compensation steps each type needs. Ask any partner to price those inputs separately, and to state which items are one-time (the investigation and runbook) and which recur (later batch jobs or new workflow types).
How long does a cancellation or termination project take?
Duration is driven by the number of workflow types in scope, how complex their compensation logic is, and how many executions are running at once. A single well-understood workflow type with no side effects can be handled quickly. A fleet of long-running workflows that touch payments, inventory or external APIs needs review of each type, a dry run against a non-production namespace, and a staged rollout. Ask for the plan to list those phases with the decisions each one needs from your team, rather than a single headline duration.
What does the work need from our team?
Your team needs to name the business owner for each workflow type, because only they can say whether a stopped workflow should be compensated, retried later or left alone. Engineers who wrote the workflow code must explain its cleanup path, and someone with access to the namespace must run the commands and watch metrics during the operation. Plan for a named approver for the batch list, a change window that matches downstream dependencies, and access to the event history for each affected type. Without these people, the operation tends to stall at the first unclear compensation step.
Can our own engineers cancel or terminate workflows without a partner?
Yes, for a small number of executions of a workflow type that has simple or no compensation logic. The Temporal CLI and Web UI both expose cancel and terminate actions, and your engineers can read the event history to confirm the outcome. A partner adds value when the list is large, the compensation paths are untested, or the operation has to be repeatable and auditable. A common pattern is for your team to own the decision and the runbook while an outside team runs the investigation, the dry run and the batch execution. Confirm the exact commands against the Temporal version you run before relying on them.
What makes compensation logic expensive to get right?
Compensation is expensive when a workflow has called external systems, such as payment APIs, provisioning services or messaging, and those calls cannot be easily reversed. Each activity type needs a known undo step, and each undo step needs to be idempotent, because a cancelled workflow may have partly completed. Workflows that use child workflows, signals or timers add more branches to check. The effort scales with the number of distinct side effects per workflow type, not with the number of executions. Ask for a list of side effects per type before agreeing a scope.
How does the number of affected executions change the approach?
A larger number of executions moves the work from manual handling to a batch process. Small sets can be cancelled one at a time with a visibility query to confirm the list. Large sets need a batch job with a tested query, a progress check and a plan for rate limits, so the cluster and downstream systems are not overloaded. Termination across many executions also removes any chance for cleanup code to run, so the list should be reviewed before the job starts. Confirm how your Temporal deployment's visibility store handles the query you intend to use.
Does cancelling or terminating a workflow leave a record for auditors?
Both actions are recorded in the workflow's event history, so the record exists for each execution that was affected. A cancellation request is recorded and lets the workflow code run its cleanup, and the outcome appears in the history as the workflow completes or records its own failure. A termination is recorded as the end of the execution without cleanup. For compliance evidence, record who issued each command, when, and the reason, in your change system, because the event history alone does not capture your approval process. Confirm the retention period for event history in your deployment, since it sets how long the record is available.
How self-hosted and Temporal Cloud deployments differ for operators
Cancellation and termination behave the same way whether you run Temporal yourself or use Temporal Cloud. A cancel request is delivered to the workflow code, which can run cleanup and compensation before it finishes, while a terminate request ends the execution at once and records a termination event in history. What changes between deployments is who is responsible for the systems that carry those requests and keep the resulting history reliable. Your team should settle that split before an incident forces the question, because the cancel-or-terminate decision is only as safe as the access and visibility behind it.
On a self-hosted deployment, your team owns the whole path. You run the Temporal Server services, the persistence store that holds the history, and the advanced visibility store that your operators query when they look for the executions to cancel or terminate. Access control is also yours to build. If no Authorizer is configured, the default noopAuthorizer allows every API request with no authentication, which means any caller that can reach the frontend could terminate a production workflow. Confirm that the frontend is reachable only from trusted networks, that mTLS and a ClaimMapper restrict who can act in each namespace, and that the Authorizer limits termination to the roles you intend. Keep the visibility store sized and current, since a slow or stale store makes batch cancellation and termination harder to target accurately. Upgrades to the server and schema also fall to you, and the upgrade guidance asks you to move one minor version at a time.
On Temporal Cloud, Temporal Technologies operates the service, and your responsibilities shift toward identity, namespace configuration and support planning. Pricing is set on the Temporal pricing page: pay-as-you-go starts at 50 US dollars per million actions, with a 99.9% SLA or 99.99% with high availability, and SAML SSO is listed. Support add-ons range from Business at 500 US dollars per month with a 2-hour P0 response in business hours to Enterprise and Mission Critical, which are quoted by sales and include SCIM. Confirm with the vendor which tier matches the response time your on-call process needs, and ask whether the cancel and terminate permissions you need can be assigned through your identity provider. Check current terms on the pricing page before you budget, since these figures can change.
How DeployOpen scopes cancel and terminate runbooks
DeployOpen approaches cancellation and termination as a scoped operations change on your own self-hosted Temporal deployment, starting from which workflows are affected and what their code must clean up. Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts.
How we scope
- Inventory which workflow types and namespaces need cancel or terminate guidance, and who can run each action.
- Confirm whether workflow code handles cancellation scopes, compensation and cleanup before any runbook is written.
- Agree in writing which visibility queries, batch jobs and audit records the runbook must cover.
How we build
- Write runbook steps for cancel and terminate, including the expected history events each action records in your environment.
- Test both actions against non-production workflows, checking compensation runs on cancel and is skipped on terminate.
- Set access controls so only approved operators can send terminate requests, mapped to your namespace roles.
How we hand over
- Deliver a decision guide, step-by-step runbook and history reference documented for your operations team.
- Walk operators through a dry run so they can identify cancel and terminate events in workflow history.
- Record the chosen approach and its owners so future workflow changes keep the runbook current.
How we support
- Offer ongoing support and continuous testing for runbooks as your workflow code and Temporal Server versions change.
- Review runbooks after each Temporal Server upgrade, using the upgrade steps your release notes call for.
- Available as a retainer alongside an agreed scope for future operational changes.

