Repository navigation
Fix wake to wait for inflight steps before returning - #7382
Conversation
A pass that claimed nothing was counted as the worker catching up even while a step it claimed on the previous pass was still running (the row is leased, so the next pass takes nothing). wake() then returned early, which made test_wake_settles_once_the_worker_has_nothing_left_to_take flaky and, on a host that suspends when wake returns, could stop that step midway. Only count the pass when nothing is in flight; each finished step wakes the loop for another pass, so the count still arrives once the work is done. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SsErF8WmKYpvEjrtHHQm85
|
There was a problem hiding this comment.
All reported issues were addressed across 5 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Merging this PR will not alter performance
Comparing Footnotes
|
A pass that claimed nothing could still be counted once the last step in flight finished while the worker was asking when work is next due: nothing was in flight by then, but that step may have left its next one due, which the pass never looked for. Skip counting when the wake event was set during the pass; the loop then goes round again and counts the pass after. The in-flight regression test now waits for the empty pass itself instead of sleeping, so a slow runner cannot let it pass without checking anything. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SsErF8WmKYpvEjrtHHQm85
* docs: add a Workflows section for reflex-workflow Thirteen pages under docs/workflows, grouped in the Backend sidebar: an overview, a tutorial, guides to defining workflows, steps, runs, events, schedules, fan-out, concurrency, workers and inspecting runs, an explanation of how the engine works and what it guarantees, and an API reference. Also fixes the package README's wake route, which used an app.api attribute Reflex does not have. * docs: qualify lease-bound claims and complete example imports * docs: retryable webhook response, precise cancel status, and what history records * docs: acknowledge webhooks only on known delivery, guard the cancel status, describe history as committed attempts * reflex-workflow: answer a message whose wake was refused while a held one ran A run holds one event at a time. When the conversation example's turn was running a held wake, a wake for a message that arrived after the turn read the transcript was refused, and nothing read that message until the four-hour reminder. That is what timed out test_a_burst_after_a_restart_is_answered_in_order in CI: a message landing while the previous reply step was still committing is held, and the next one can land in that gap. reply now reads the transcript again under the arrival lock before it waits, as remind already does, and takes another turn for anything new. A message that lands after that read finds the run still stepping, so its wake is held. The regression test drives the race deterministically: it fails on a thirty-second timeout before this change and passes in under a second after. * reflex-workflow: arm every conversation wait in one step that rereads first Checking for unread messages in reply was not enough. When reply found one it took another turn with the earlier wake still held, and the turn that finally ran that wake found nothing new and armed the wait directly: a message whose wake was refused while it ran then waited for the reminder. Every wait is now armed by settle, a step of its own that rereads the transcript under the arrival lock. reply and a turn with nothing new both go through it. The regression test now also drives a message into the turn that runs the stale wake, and fails without this change. The reminder race test waited on the status, which is set as soon as a wait is armed; it now waits until no wake is held and no step is running, since a held wake replaying through settle takes the lock the test holds. * docs: give Workflows its own top-level sidebar section Moved out of the State section, between State and Recipes as masenf suggested, with the guides grouped into Building and Running Workflows. Single pages are one-child groups, as elsewhere in the sidebar: the index that opens the active group counts top-level entries that way. * docs: keep inline code out of link text, which the docs site does not render * Revert "docs: keep inline code out of link text, which the docs site does not render" This reverts commit efcdd2e. * Name this PR's news fragments by its number * docs: wake also waits for the steps it started to finish Matches #7385. * Revert "reflex-workflow: arm every conversation wait in one step that rereads first" This reverts commit 47588c9. * Revert "reflex-workflow: answer a message whose wake was refused while a held one ran" This reverts commit 16cf37e. * docs(workflows): bring the Workflows docs up to date with main - Stop registering the workflow base with rx.ModelRegistry.register. Since #7797 a registered base turns off detection of the app's other DeclarativeBase bases, so reflex db makemigrations would write a revision dropping their tables. Explain detection, when registering is needed, and point MappedAsDataclass bases (the database docs' default) at reflex_workflow.dataclass. Same fix in the package README. - Describe the held event being released once a worker takes it (#7396). - Document OpenTelemetry tracing of step attempts (#7635). - Require Python 3.11 (#7449), spell Cron's default zone as UTC, say wake waits for the work to run (#7382), and import rx in the wake example. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01ESN8DiahHo8P4FLFNr6fHK * docs(workflows): say which bases Reflex detects, and why registering drops others Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01ESN8DiahHo8P4FLFNr6fHK * docs(reflex-workflow): rewrap the README's Reflex setup paragraph Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01ESN8DiahHo8P4FLFNr6fHK --------- Co-authored-by: Masen Furer <[email protected]> Co-authored-by: Claude <[email protected]>
Type of change
Description
reflex_workflow.wakewas returning while steps the worker had taken were still running. On hosts that suspend when the request returns, this could stop a step midway through execution.The fix prevents
wakefrom returning (and thus the request from completing) while any steps are still inflight. The worker'sloopnow only records that it has settled (caught up) when it has both claimed nothing in a pass AND has no steps still running.Changes
Core fix in
runner.py:loop()to only callself.runtime.settled.record()whennot self.inflight, ensuring we don't report as settled while steps are still executingDocumentation updates:
Settledclass docstring inruntime.pyto reflect the new requirementwake()docstring inrunner.pyto clarify the settled conditionwakewaits until steps are done runningTest coverage:
test_wake_waits_for_the_steps_it_took_to_finishwhich verifies thatwakedoes not return while a step is still executing, even after claiming nothing in a passTesting
The new regression test
test_wake_waits_for_the_steps_it_took_to_finishverifies the fix by:executeto hold execution until the test signals itwakedoes not complete while the step is runningwakecompletes after it finishesExisting tests continue to pass.
https://claude.ai/code/session_01SsErF8WmKYpvEjrtHHQm85