# Request Cancel for an Activity

> For the complete documentation index, see [llms.txt](https://docs.temporal.io/llms.txt).
> Any documentation page is available as raw Markdown by appending `.md` to its URL.
> For related questions, query `https://docs.temporal.io/api/retrieve?q=<question>&jtb=<job-to-be-done>&src=md-page&agent=<your-name>` (no auth; returns JSON `{content, source_url, page_url}`, with `source_url` pointing to Markdown for docs pages). Don't include personal data or credentials.
> If this page is wrong or missing something you needed, or Temporal behaves differently from what it says, report it with `https://docs.temporal.io/api/feedback?title=<summary>&message=<what-happened>&category=documentation&page_url=/activity-operations/request-cancel&src=md-page&agent=<your-name>` (use `category=product` when the product, not the page, is wrong). Report only a specific problem you hit, send it once, and don't include personal data or credentials.

> Ask a Standalone Activity to stop at a safe point. Cancellation reaches a running attempt through Heartbeats, so your code can clean up.

Request Cancel asks an Activity Execution to close gracefully, giving your code a chance to clean up.

## When to Request Cancel

- A [Standalone Activity](/standalone-activity) is no longer needed, and you want it to stop at a safe point rather
  than be killed mid-attempt.
- A job was submitted in error, and you want the Activity to release the resources it has already acquired.

A [Workflow Activity](/workflow-activity) can't be canceled directly. It receives a cancellation request when its
Workflow is canceled, and from that point behaves the same way a Standalone Activity does.

## What happens when you Request Cancel an Activity

The Activity Execution transitions to `CancelRequested`.

- **If no attempt is running,** the execution closes immediately. This doesn't depend on the Activity Heartbeating.
- **If an attempt is running,** the request reaches your code through the Activity's
  [Heartbeat](/encyclopedia/detecting-activity-failures#activity-heartbeat). A Cancellation error is raised when the
  next Heartbeat response is received, and the Activity transitions to canceled status if your code lets that error
  propagate.
- **If the Activity doesn't Heartbeat,** it isn't interrupted mid-attempt. The request takes effect at the next attempt
  boundary, for example when the
  [Start-To-Close Timeout](/encyclopedia/detecting-activity-failures#start-to-close-timeout) elapses.

See [Cancellation](/activity-execution#cancellation) for how your Activity code accepts or ignores a Cancellation.

## CLI usage

```bash
temporal activity cancel \
  --activity-id my-activity \
  --reason "No longer needed"
```

See the [CLI reference for `temporal activity cancel`](/cli/command-reference/activity#cancel) for all options.

## Important considerations

- **A successful response means the request was accepted, not that the Activity stopped.** Your code may complete or
  fail non-retryably instead of honoring the request.
- **Cancellation can be requested only once.** Repeating the request doesn't deliver a second Cancellation.
- **Request Cancel takes precedence** over Reset and Pause. See [Successive operations](/activity-operations#successive-operations).
