The Cancellation Cleanup service in Prefect is responsible for managing the cancellation of flow runs. When a cancellation request is made, the flow run moves to a "Cancelling" state. If the deployment uses a work pool-based deployment with a worker, the worker monitors the state and sends a termination signal to the flow run infrastructure. If the run doesn't terminate within a grace period (default is 30 seconds), the infrastructure is forcibly terminated to ensure the flow run exits.
Key points include:
- Cancellation requires an associated deployment.
- Inline nested flow runs cannot be cancelled independently unless deployed separately.
- The service is resilient to worker restarts and uses metadata to track infrastructure.
For more details, you can refer to the
Prefect documentation on cancellation.