Repository navigation
Description
The fleet dispatch fence is meant to keep every workflow row off the claim path once its run is terminal, apart from the escalation step and after-terminal effects (_dispatch_sql.py:313-326, _dispatch_sql.py:368-369). It decides that by looking the root up: the claim leg admits the row when NOT EXISTS a root with that flow_id in a terminal status (_dispatch_sql.py:370-375), and the second fence template, used by the dispatch round's claimable check, has the same check inverted (_dispatch_sql.py:407-412). If the root row is gone, the check passes the same way it does for a live run.
Retention does remove the roots of finished runs. The prune's workflow guard only holds back parent rows of runs that are still live (_leader_shared.py:457-478), so once prune_retention_succeeded passes (30 days by default, settings.py:2168-2169) the root moves to jobs_archive even if a non-terminal row of the same run is still in jobs. No sweep removes that row. The join rederive only selects rows with deps_pending > 0 and a blocking_reason: join marker (_sql_sweep.py:28-34), the deadline sweep needs a schedule_to_close (_sweeps.py:811-815), and the result-TTL sweep only clears result (_sweeps.py:949-958).
The rows this catches today are the extra seeds.join.join rows from issue 745: pending, deps_pending = 0, no blocking marker, under a succeeded root. When a worker claims one after the root is pruned, the execution door reads the workflow name off the root through a LEFT JOIN (_worker_execution.py:109-116). The name comes back NULL and the door raises WorkflowBodyUnresolvableError (_worker_execution.py:1104-1110) before the WorkflowRootMissingError path (_worker_execution.py:1161-1168) can run. The worker handles that error with a 10-second snooze that charges no attempt (run.py:1595-1629), so the row is claimed, refused, snoozed and claimed again indefinitely.
Reproduced on ffcb61f against a real Postgres. The source tree there is identical to main 9b9fa72; nothing under src/ changed in between. The workflow is the map-on-join shape from issue 745:
@app.workflow("map_on_join")
def map_on_join() -> Promise[object]:
first = map_source(step(seeds, key="seeds"), expand)
return build(step(count, map_source(first, ident), key="final"))The run succeeded and left the second seeds.join.join row pending with deps_pending = 0. While the root existed, a dispatch round from a workflow-capable worker claimed nothing. With the run's finished_at set 40 days back, a prune at 30 days' retention archived the root (1 row) and left the stray as the only row of the run in jobs. The next dispatch round claimed it (running, attempt 1). The door raised WorkflowBodyUnresolvableError: the flow root of row 01a20f04-... stamps no workflow name, the worker's snooze for that error moved the row to scheduled, and once the snooze was due it was claimed again, still at attempt 1. A second pass also backdated the stray's own created_at and scheduled_at and ran the leader's row-mutating sweeps once before and once after the prune. The stray stayed pending throughout and was claimed and re-claimed the same way.
No data is lost and the run's result stands. About a month after a run finishes, though, each leftover row starts costing a claim and a dispatch-workflow-body-unresolvable error line roughly every 10 seconds, with no end. The log gives the wrong cause, a missing workflow name, when the root is gone. The row also matches the stranded detector's root-missing leg (_leader_sweeps.py:2960-2981), so TaskQStrandedJobs should fire with reason="workflow_root_missing". The alert and the runbook call that control-plane data corruption and tell the operator to restore the root and investigate the destructive path that dropped it (rules.yaml:444-448, runbooks.md:827), and here that path is the engine's own retention. On main a map-on-join run can still leave one of these rows, depending on whether the fork or the outbox drain writes the join first. PR 751 stops new ones, but its upgrading note leaves the existing ones to a manual taskq job cancel, so an estate that skips the note hits this loop 30 days later. PR 755 edits the same two fence templates to add its hold leg.
Probably wants: both fence legs treating a missing root the same as a terminal one, plus either the prune keeping a finished run's root while any non-terminal row of that run remains or a sweep that cancels non-terminal rows on terminal runs.
Activity
XBeg9 commentedon Nov 24, 2026
This shipped with the workflow engine itself in PR 681 (
5b383f295), so it isn't a regression. Blame on the claim fence's root check (_dispatch_sql.py:371-376), its probe twin (_dispatch_sql.py:407-412), the prune's liveness guard (_leader_shared.py:477-483) and the door'sLEFT JOINroot read (_worker_execution.py:101) all lands on that commit, and the later fence edit in PR 727 only added the after-terminal-effect exemption, so a missing root still reads the same. I ran the reproduction at that commit and at its parent. The parent has no workflows package, so there's nothing to run there; at the commit it fails the same way as on9b9fa7244, with the root archived, the strayseeds.join.joinrow claimed at attempt 1,WorkflowBodyUnresolvableErrorfrom the door, and a second claim after the snooze still at attempt 1. The stray was already produced at that commit, so the duplicate join row from issue 745 is as old as the fence gap, and PR 751 stops new ones but leaves existing ones to a manual cancel. TheWorkflowRootMissingErrorarm and the stranded detector'sworkflow_root_missingleg came later in PR 736, which treats a missing root as corruption and put the door's root-missing pass-through after the older name check, so this case logs as body-unresolvable. PR 755 for issue 748 adds a hold leg to the same two fence templates.fix(workflows): harden pruned-root retention hold, outbox drain, and …
fix(workflows): fence pruned-root dispatch, harden retention hold and…
fix(workflows): fence rootless workflow rows out of every claim door …