<@ULVA73B9P> I cannot mark a `cancelling` flow-ru...
# ask-marvin
y
@Marvin I cannot mark a
cancelling
flow-run as cancelled in prefect ui, is there a way to force this?
m
thought for 161.7 seconds
Short answer: not from the UI today. The Cancel action in the UI moves a run to Cancelling and waits for the worker/infrastructure to stop it; there isn’t a “force to Cancelled” button. Ways to force it: - Kill the underlying infrastructure - If a pod/container/process is hung, terminating it at the infra level usually lets Prefect complete the transition to Cancelled. - Force the state via the API - You can override orchestration and set the flow run to Cancelled with `force=True`:
Copy code
import asyncio
  from prefect.states import Cancelled
  from prefect.client.orchestration import get_client

  async def force_cancel(flow_run_id: str):
      async with get_client() as client:
          result = await client.set_flow_run_state(
              flow_run_id=flow_run_id,
              state=Cancelled(message="Force-cancelling stuck run"),
              force=True,   # bypasses orchestration to apply the state
          )
          print(result.status, getattr(result, "details", None))

  asyncio.run(force_cancel("00000000-0000-0000-0000-000000000000"))
- Note: this bypasses normal orchestration checks; use with care. - CLI note -
prefect flow-run cancel <id>
only sets Cancelling; there is no CLI “force cancel” at the moment. I verified the available subcommands with
prefect flow-run --help
. Docs/refs: - States in Prefect (Cancelling → Cancelled) - REST API: Set Flow Run State If you share whether you’re on Cloud or OSS and the run ID, I can help you craft an exact one-liner to run and confirm it completes.