Michael Schwartz
08/31/2025, 12:52 AM{
"type": "event",
"match": {},
"match_related": {
"prefect.resource.role": "flow-run"
},
"after": [],
"expect": [
"cdf.publish_audited_tables"
],
"for_each": [],
"posture": "Reactive",
"threshold": 1,
"within": 0
}
the problem I'm having is it consistently triggers the flow it runs 3 times, each within ~30 minutes of each other. What might be causing this? the event is only emitted once @MarvinMarvin
08/31/2025, 12:52 AMMarvin
08/31/2025, 1:05 AMcdf.publish_audited_tables
is received
- It requires the event to have a related resource with prefect.resource.role = flow-run
(i.e., typically when you emit the event from inside a flow run, Prefect includes that flow run as a related resource)
- threshold: 1
and within: 0
means “fire immediately when the event arrives”
Why you might get 3 runs ~30 minutes apart even if “the event is only emitted once”:
1) Event loop (most common)
- If the flow that your automation runs also emits the same event (cdf.publish_audited_tables
) when it runs (e.g., at the end), that new event will match the same automation and trigger again. If that flow takes ~30 minutes, you’ll see a new run ~30 minutes later, and so on.
- This can happen even if you only intentionally emit the event once upstream — the triggered flow emitting it again creates the loop.
2) Multiple related flow-run resources attached to the single event
- If the single event includes more than one related flow-run
(e.g., parent and child runs), the automation can evaluate separately and fire for each unless you partition with for_each
.
3) Action retries or duplicate automations (less common)
- If the action (e.g., RunDeployment) could not be recorded as completed due to a transient error, the automations service may try again later.
- Or there may be multiple automations or multiple actions configured that look similar.
How to confirm the root cause:
- Check the Automation’s Activity in the UI. For each firing, look at:
- triggering_event.type and triggering_event.id — are they different events?
- If they are different events of the same type at ~30 min intervals, it’s likely a feedback loop from the triggered flow.
- Verify whether the flow that is being triggered emits cdf.publish_audited_tables
itself.
- Ensure there aren’t duplicate automations or multiple actions on the same automation.
- You can also watch events live:
prefect events stream --format text
and filter for cdf.publish_audited_tables
to see exactly when and how often they appear.
Ways to make it fire only once (and avoid loops):
- Partition the trigger per originating flow run:
- Add for_each: ["prefect.resource.id"]
- This evaluates the trigger separately per related flow run and prevents multiple firings for the same run if multiple matching events occur.
- Avoid matching events emitted by the triggered flow:
- If your triggered flow also emits cdf.publish_audited_tables
, either:
- Change the event name the triggered flow emits (e.g., make a distinct name), or
- Add a distinguishing label to the original event (e.g., cdf.origin=upstream
) and add that to match
so only upstream-originated events trigger:
"match": { "cdf.origin": "upstream" }
- Then ensure the triggered flow does not include that label when emitting.
- Narrow related resources:
- If your custom event unintentionally includes multiple flow-run
related resources, only attach the one you need, or switch to match
if the flow run is the primary resource emitting the event.
Helpful docs:
- Event triggers (Automations) in Prefect 3
- Automation schema reference
- prefect events
CLI help (for streaming): run
prefect events --help
prefect events stream --help
If you can share:
- A screenshot/snippet from the Automation’s Activity tab for the three firings (showing triggering_event.id and timestamps)
- Whether the triggered flow emits cdf.publish_audited_tables
- The action configuration (e.g., is it a single RunDeployment action)Marvin
08/31/2025, 1:05 AMfor_each: ["prefect.resource.id"]
and ensuring the triggered flow does not emit the same event will resolve this.