Yu(Irene) Chen
04/07/2026, 2:00 AMcancelling flow-run as cancelled in prefect ui, is there a way to force this?Marvin
04/07/2026, 2:00 AMMarvin
04/07/2026, 2:03 AMimport 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.