Nicholas Pini
11/04/2025, 11:20 AMprefect.server.events.actions - Action failed: 'Failed to set state: Cannot transition flows that are cancelling to a state other than Cancelled.'
Why?Marvin
11/04/2025, 11:20 AMMarvin
11/04/2025, 11:32 AMAction failed: 'Failed to set state: Cannot transition flows that are cancelling to a state other than Cancelled.'
What to change
- Update your automation so that when a run has been in Cancelling for ≥ 1 hour, the action is “Set flow run state” and you choose “Cancelled”.
- Do not use “Cancel flow run” for runs already in Cancelling.
Why this happens
- Cancelling is a non-terminal “cleanup in progress” state. The only valid next state is Cancelled. Reissuing a cancel (which sets Cancelling) from Cancelling is rejected by the server’s orchestration rules.
Relevant docs
- States in Prefect 3.x: States
- Cancellation workflow: Cancel workflows
- Flow run set-state API (shows the “Cancelled” terminal state): Set flow run state
- Orchestration/core policy and rules (the rule behind that error): Core policy and Rules
If you want, I can help double-check your automation config—could you share a screenshot or describe the exact action you selected?Nicholas Pini
11/04/2025, 11:35 AMMarvin
11/04/2025, 11:35 AMMarvin
11/04/2025, 11:40 AMprefect flow-run delete <flow-run-id> (this command exists in Prefect 3.x; run prefect flow-run delete --help to confirm)
- REST API: DELETE endpoint DELETE /flow-runs/{id}
- Python client:
from uuid import UUID
from prefect.client.orchestration import get_client
async def delete_run(run_id: str):
async with get_client() as client:
await client.delete_flow_run(UUID(run_id))
If you want it “automated”
- Use an Automation that triggers on your condition (e.g., Cancelling for ≥ 1h) and then:
- Run a “cleanup” deployment (action: Run deployment) that calls the API to delete matching runs, or
- Call a webhook (action: Call webhook) that performs the deletion via the REST API.
Notes
- Deleting a run is destructive: it removes the run record (and associated logs/artifacts). It does not stop any underlying infrastructure. If the run is actually still executing somewhere, cancel/clean up that infra first.
- There’s no built‑in retention policy for flow runs in Prefect 3; if you need periodic cleanup, schedule a small maintenance flow to prune old runs. For general maintenance guidance, see Database maintenance.