Automation notifications contain wrong state

While testing a webhook to capture all flow state transitions, I discovered that states are being missed or reported incorrectly if the transitions happen quickly enough.

Going through the event log, it looks like the notification triggers contain the correct data, but when the notification is executed, it seems that state available to construct the notification payload (via templating) is the state of the environment at the “current” time, not the state at the time when the notification was triggered. This results in missed transitions and duplicate notifications for the same state.