PrefectHQ
prefect
BlogDocsChangelog

fix: prevent heartbeat events after flow run completes

#19641
Comparing
fix-heartbeat-after-completion
(
5c3f1f1
) with
main
(
f702f1e
)
CodSpeed Performance Gauge
0%
Untouched
2
Ignored
6

Benchmarks

Passed

bench_import_prefect_flow
benches/bench_import.py
CodSpeed Performance Gauge
0%
1.4 s1.4 s
bench_task_decorator
benches/bench_tasks.py
CodSpeed Performance Gauge
0%
465.1 µs465 µs

Ignored

bench_import_prefect
benches/bench_import.py
Ignored
CodSpeed Performance Gauge
0%
1.1 s1.1 s
bench_flow_decorator
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
-2%
5.5 ms5.6 ms
bench_task_submit
benches/bench_tasks.py
Ignored
CodSpeed Performance Gauge
+92%
20.8 ms10.9 ms
bench_flow_call[options1]
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
0%
107.7 ms107.9 ms
bench_flow_call[options0]
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
-2%
166.2 ms170.2 ms
bench_task_call
benches/bench_tasks.py
Ignored
CodSpeed Performance Gauge
-5%
33.1 ms35 ms

Commits

Click on a commit to change the comparison range
Base
main
f702f1e
+0.04%
fix: prevent heartbeat events after flow run completes Fixes a race condition where heartbeat events could be emitted after a flow run has already completed. This could incorrectly trigger zombie flow detection automations. The issue occurred because the periodic heartbeat loop iterates over _flow_run_process_map and collects flow runs to emit heartbeats for. Between iteration and actual emission (which involves async lookups), a flow run could complete and be removed from the map. The heartbeat would still be emitted, appearing after the terminal state event. The fix adds a check_incomplete parameter to _emit_flow_run_heartbeat. When True (used by the periodic heartbeat loop), it verifies the flow run is still in the process map before emitting. This prevents emitting heartbeats for flow runs that completed during heartbeat preparation. Closes #19598 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
5c3f1f1
13 hours ago
by zzstoatzz
© 2025 CodSpeed Technology
Home Terms Privacy Docs