SIGTERM in `reschedule` mode un-cancels a flow run the server already marked Cancelled
Author: chuqCTCCreated Sep 30, 2026Updated Sep 30, 2026
Labelsbug
Bug summary
With PREFECT_FLOW_RUN_EXECUTE_SIGTERM_BEHAVIOR=reschedule, a SIGTERM that arrives after the server has marked the run Cancelled makes _terminate_on_signal propose AwaitingRetry. The server accepts it, and the run starts again.
On Kubernetes pools with the default backoffLimit: 0, this happens whenever a cancellation times out: cancellation_cleanup marks the run Cancelled, the worker deletes the Job, and the pod's SIGTERM reschedules the run. We saw AwaitingRetry 247 ms after the timeout's Cancelled.
import asyncio
import os
import signal
import subprocess
import sys
import time
from prefect import flow, get_client
from prefect.states import Cancelled
@flow
def sleepy():
time.sleep(300)
async def main():
deployment_id = await (await sleepy.ato_deployment("repro")).apply()
async with get_client() as client:
flow_run = await client.create_flow_run_from_deployment(deployment_id)
supervisor = subprocess.Popen(
[sys.executable, "-m", "prefect", "flow-run", "execute", str(flow_run.id)],
env={**os.environ, "PREFECT_FLOW_RUN_EXECUTE_SIGTERM_BEHAVIOR": "reschedule"},
)
while not (await client.read_flow_run(flow_run.id)).state.is_running():
await asyncio.sleep(0.5)
# what a cancelling timeout does, then the teardown's SIGTERM
await client.set_flow_run_state(flow_run.id, Cancelled(), force=True)
supervisor.send_signal(signal.SIGTERM)
supervisor.wait(timeout=60)
print((await client.read_flow_run(flow_run.id)).state.name) # AwaitingRetry
if __name__ == "__main__":
asyncio.run(main())Expected: the run stays Cancelled. Crashed should stay reschedulable, since the Kubernetes observer can mark an evicted run Crashed before the reschedule lands.
Version info
Server and worker: Prefect 3.8.6, prefect-kubernetes 0.7.12
Also reproduces on main (420d0d6a78)Source: PrefectHQ/prefect