reflex-workflow: take a held event when its step is claimed
Summary
Fixes ENG-12995 / #7384.
A run holds one event at a time. A held event stayed in pending_event until the step running it committed, so while that step ran, the row still showed waiting_for = <step> and the held answer, and deliver() refused every new event. When the step armed the same wait again, as a conversation's turn does, the refused event was for that next wait, and nothing would deliver it again: the run sat on the wait until its deadline (4 hours in the ex13 example).
The claim now takes the held event (claim.taking, shared by the claim statement and the tests' claim_row):
- the event's step and arguments become
next_step/next_args, and the row is due now; waiting_forandpending_eventare cleared;- the event's key travels with the arguments and is remembered when that step's attempt commits, so a run moved on by
run()before the step ran still accepts a resend;deliverrefuses a resend while the step is pending.
A row holding an event for its wait is claimable only as an event, by a worker serving the event's step: not through its due next_step, which is the wait's timeout and may be in another lane (this was also possible on main).
An event delivered while that step runs is then held for the wait it arms next, the same as one delivered while any other step runs.
One-answer waits keep their semantics: a second answer to a wait whose held event has not been taken yet is still refused (test_a_second_event_cannot_take_a_wait_that_already_holds_one is unchanged and passes). A key is still taken when the attempt that runs the event commits, success or failure, as before.
Execution no longer looks for a held event itself (every claim has already taken it), so settle_event and abandon lose their event parameter.
Test plan
- New
test_an_event_delivered_while_the_held_one_runs_is_held_for_the_next_wait(engine): delivering while the held event's step runs returns 1 and the event runs next. Fails onmain(deliverreturns 0). - New
test_a_message_arriving_while_a_held_turn_runs_is_answered(the ticket's reproduction against ex13). Fails onmain(times out waiting for "Your balance is 80."). - New
test_a_held_event_beats_a_due_timeout_in_another_laneandtest_an_event_taken_but_moved_past_before_it_ran_can_be_sent_again, from review; both fail against the previous commit. - Full
tests/units/reflex_workflowpasses (1046) against Postgres 16; ex13 five times and the event/key tests three times in a row. -
deliver()docstring, the ex13wake()docstring and the README describe the new behavior; pre-commit (including pyright) clean.