Scott Pedersen
06/23/2026, 8:47 PMMarvin
06/23/2026, 8:47 PMMarvin
06/23/2026, 8:49 PMRunning — not for runs/jobs stuck in Pending.
If you want to cancel runs that stay Pending for more than 10 minutes, the recommended approach is to create a custom automation with a proactive event trigger.
Example pattern:
- watch for prefect.flow-run.Pending
- expect prefect.flow-run.Running or prefect.flow-run.Crashed
- if neither happens within 600 seconds
- run CancelFlowRun
Example YAML:
yaml
name: Cancel long-pending flow runs
enabled: true
trigger:
type: event
posture: Proactive
after:
- prefect.flow-run.Pending
expect:
- prefect.flow-run.Running
- prefect.flow-run.Crashed
for_each:
- prefect.resource.id
threshold: 1
within: 600
match:
prefect.resource.id:
- "prefect.flow-run.*"
actions:
- type: cancel-flow-run
A small terminology note:
- Pending = submitted, waiting on execution/infrastructure
- Late = scheduled start time passed, but the run has not entered Pending yet
So if your concern is specifically “worker never picked this up / infra never started”, Pending is usually the right target. If your concern is “scheduled run missed its start”, that’s more of a Late case.
Docs:
- Automations
- Event triggers
- Creating automations
- Managed zombie-flow detection example
If you want, I can also give you:
- a UI-based setup walkthrough, or
- a version scoped to work-pool/job variables or only certain deployments.Scott Pedersen
06/23/2026, 8:52 PMMarvin
06/23/2026, 8:52 PMMarvin
06/23/2026, 8:52 PMPending for more than 10 minutes, as long as the automation’s match criteria include those runs.
If you use:
yaml
match:
prefect.resource.id:
- "prefect.flow-run.*"
then it will apply broadly to all flow runs in that workspace.
A few notes:
- It acts on flow runs, not individual infrastructure “jobs” directly.
- It cancels the run after it has entered Pending and failed to transition out within the time window.
- It will not catch runs that are stuck in `Scheduled`/`Late` and never make it to Pending.
- You can narrow scope by deployment, work pool, tags, etc. if you do not want it workspace-wide.
So the short answer is: yes, for any flow run that actually reaches Pending and stays there longer than 10 minutes.
Docs:
- Event triggers
- Automations
If you want, I can help you write a version that targets:
- all runs in the workspace,
- only one deployment,
- only one work pool, or
- only tagged runs.Scott Pedersen
06/23/2026, 9:20 PMMarvin
06/23/2026, 9:20 PMMarvin
06/23/2026, 9:20 PMjob in the name unless your team consistently uses that term, since the automation is acting on flow runs.
Best of your options:
- Cancel flow runs stuck in Pending for longer than 10 minutes
Slightly cleaner versions:
- Cancel flow runs pending for more than 10 minutes
- Cancel stuck Pending flow runs after 10 minutes
- Cancel flow runs stuck in Pending >10m
My recommendation for clarity:
- Cancel flow runs pending for more than 10 minutes
Why:
- uses Prefect’s actual object name: flow runs
- avoids ambiguity with worker/infrastructure jobs
- concise but still specific
If you want, I can also suggest:
- a user-facing name and
- a shorter ops/internal naming convention version.Scott Pedersen
06/23/2026, 9:54 PMMarvin
06/23/2026, 9:54 PMMarvin
06/23/2026, 9:55 PMyaml
actions:
- type: cancel-flow-run
- type: send-notification
# notification configuration here
If you want, I can help draft the full automation for:
- cancel + Slack notification, either
- in YAML, or
- as a step-by-step UI configuration.Scott Pedersen
06/23/2026, 9:56 PMflow_run_id, flow_run_name, deployment_name?Marvin
06/23/2026, 9:56 PMMarvin
06/23/2026, 9:57 PMflow_run_name
- flow_run_id
- deployment_name
- the reason it was cancelled, e.g. “Pending for more than 10 minutes”
- a link to the flow run in Prefect Cloud, if available
- optionally:
- flow_name
- work_pool_name
- scheduled start time
- how long it was pending
A good Slack message should help someone answer:
1. What was cancelled?
2. Why was it cancelled?
3. Where do I go inspect it?
A practical message shape:
text
Prefect automation cancelled a flow run that remained in Pending for more than 10 minutes.
Flow run: <flow_run_name>
Flow run ID: <flow_run_id>
Deployment: <deployment_name>
Reason: Exceeded 10-minute Pending threshold
View run: <run URL>
If you want a slightly more operational version:
text
:warning: Prefect cancelled a flow run stuck in Pending.
Flow run: <flow_run_name>
Flow run ID: <flow_run_id>
Flow: <flow_name>
Deployment: <deployment_name>
Work pool: <work_pool_name>
Reason: Pending for >10 minutes
Run URL: <run URL>
My recommendation: keep it short, but always include:
- run name
- run ID
- deployment name
- reason
- run URL
That usually gives responders enough to investigate quickly.
If you want, I can help you turn this into a Prefect automation notification template using the actual event/resource variables available in the message body.Scott Pedersen
06/23/2026, 10:29 PMMarvin
06/23/2026, 10:29 PMMarvin
06/23/2026, 10:31 PMRunning but do not reach a terminal state within some time window.
A common pattern is:
- `after`: prefect.flow-run.running
- `expect`: terminal events like prefect.flow-run.completed and prefect.flow-run.cancelled
- `posture`: Proactive
- `within`: your timeout window, like 1 hour
- action(s): cancel the flow run, send a notification, etc.
Conceptually:
- start watching when a run enters Running
- if no completion/cancellation event happens within the configured window
- fire the automation
Example shape:
python
from datetime import timedelta
from prefect.automations import Automation
from prefect.events.schemas.automations import EventTrigger, Posture
from prefect.server.events.actions import CancelFlowRun
automation = Automation(
name="Cancel zombie flow runs",
trigger=EventTrigger(
match={"prefect.resource.id": "prefect.flow-run.*"},
for_each={"prefect.resource.id"},
after={"prefect.flow-run.running"},
expect={"prefect.flow-run.completed", "prefect.flow-run.cancelled"},
posture=Posture.Proactive,
within=timedelta(hours=1),
threshold=1,
),
actions=[CancelFlowRun()],
).create()
A few notes for 2.20.16:
- This is a Prefect Cloud feature.
- It’s custom automation, not built-in managed automation.
- You can attach multiple actions, like cancel + Slack/email notification.
- timeout_seconds on a flow is useful, but it’s different — that handles flow execution timeouts, not orchestration-level “zombie” detection in Cloud.
Docs:
- Automations concepts
- Automations guide
- Events and triggers
- Prefect Cloud Automations API
One important note: if you’re planning new automation work, I’d recommend using Prefect 3.x where possible, since that’s the current default platform direction.
If you want, I can help you write the exact 2.20.16 automation for:
- zombie Running flows, or
- Pending flows older than 10 minutes.Scott Pedersen
06/23/2026, 10:36 PMMarvin
06/23/2026, 10:36 PMMarvin
06/23/2026, 10:37 PM2.20.16, that makes sense.
The important distinction is:
- Managed automations are configured in the UI by Prefect Cloud
- they are Cloud-side features
- they are not tied strictly to your Python package version in the same way SDK APIs are
So even if your flows are running with Prefect 2.20.16, you may still see managed automation capabilities in the Cloud UI.
For zombie flow detection specifically:
- if the UI shows a managed automation for detecting unresponsive/zombie flow runs, then yes, you can use that even though your runtime is on 2.20.16
- that feature is part of Prefect Cloud’s control plane behavior, not just the local SDK version
So the practical answer is:
- Yes, trust what you see in the UI
- if the managed automation is available in your workspace, you can use it
- your 2.20.16 runtime does not necessarily prevent that
If you want, send me the exact label/text you see in the UI, and I can help interpret whether it’s:
- the built-in zombie/unresponsive run managed automation, or
- a regular custom automation template.