Latest Results
fix(hooks): check how a flow hook takes its arguments before calling it
Calling `on_crashed` and `on_cancellation` hooks positionally fixed #23714,
but as pointed out in review, it broke keyword-only hooks that worked in
the runner and handed the wrong objects to hooks that name `flow`,
`flow_run` and `state` in a different order.
So instead of picking one calling convention, the hook's signature is
checked first. If the hook names its parameters `flow`, `flow_run` (or
`run`, like the states docs) and `state`, it gets them by name, in any
order and keyword-only included. Otherwise it gets them positionally,
whatever the names are. If neither fits, the hook isn't called and the
log says which signatures work. Nothing is retried after a `TypeError`,
so a hook that raises one still runs only once.
The engine and the runner now share this rule, which also fixes two quiet
problems in `on_failure` and `on_completion`: keyword-only hooks never ran
there, and reordered parameters got swapped values. The worker bootstrap
keeps its own copy of the rule because it runs with the flow's runtime,
which may have an older Prefect.
`FlowStateHook` now describes both forms, the `on_*` decorators return the
hook's own type, and `docs/v3/concepts/states.mdx` lists the accepted
signatures.
I ran 23 hook signatures through the four call paths on `main` and on
this branch: nothing that worked before receives different objects, and
30 cases that failed or got swapped values now work. The one difference
for existing hooks is that a hook taking only `*args, **kwargs` now gets
positional arguments in the runner too, the same as in the engine.CassianoE:fix-hook-keyword-call Latest Branches
0%
Wilson0511:fix/lock-release-after-expiry 0%
devin/oss-8403-release-expired-lock-noop 0%
CassianoE:fix-hook-keyword-call © 2026 CodSpeed Technology