Skip to content

Fix wake to wait for inflight steps before returning - #7382

Merged
masenf merged 3 commits into
mainfrom
claude/modest-edison-7b3zex
Oct 2, 2026
Merged

masenf merged 3 commits into
mainfrom
claude/modest-edison-7b3zex

Conversation

@masenf

@masenf masenf commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • This change requires a documentation update

Description

reflex_workflow.wake was 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 wake from returning (and thus the request from completing) while any steps are still inflight. The worker's loop now 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:

  • Modified loop() to only call self.runtime.settled.record() when not self.inflight, ensuring we don't report as settled while steps are still executing
  • Updated docstrings to clarify that "caught up" requires both claiming nothing AND having no inflight steps

Documentation updates:

  • Updated Settled class docstring in runtime.py to reflect the new requirement
  • Updated wake() docstring in runner.py to clarify the settled condition
  • Updated README.md to explain that wake waits until steps are done running

Test coverage:

  • Added test_wake_waits_for_the_steps_it_took_to_finish which verifies that wake does not return while a step is still executing, even after claiming nothing in a pass

Testing

The new regression test test_wake_waits_for_the_steps_it_took_to_finish verifies the fix by:

  1. Creating a workflow step
  2. Mocking execute to hold execution until the test signals it
  3. Confirming that wake does not complete while the step is running
  4. Releasing the step and confirming wake completes after it finishes

Existing tests continue to pass.

https://claude.ai/code/session_01SsErF8WmKYpvEjrtHHQm85

Review in cubic

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
@masenf
masenf requested a review from a team as a code owner October 1, 2026 23:12
@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Fixes workflow wake to wait for running steps.

The PR appears safe to merge; no outstanding finding was identified.

Summary

The PR makes wake wait until the worker has no steps in flight and no wake-up pending from a step that just finished.

  • Adds regression tests for a running step and a continuation it leaves due.
  • Updates the README, docstrings, and changelog fragment.

Reviews (3) · Last reviewed commit: "Merge branch 'main' into claude/modest-e..."

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@codspeed

codspeed Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 146 untouched benchmarks
⏩ 18 skipped benchmarks1


Comparing claude/modest-edison-7b3zex (38e05c4) with main (a0fb942)

Open in CodSpeed

Footnotes

  1. 18 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

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
@masenf masenf added the on deck PRs lined up to review / merge next label Oct 2, 2026
@masenf
masenf merged commit 53e48dd into main Oct 2, 2026
150 of 151 checks passed
@masenf
masenf deleted the claude/modest-edison-7b3zex branch October 2, 2026 21:28
masenf added a commit that referenced this pull request Nov 17, 2026
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

on deck PRs lined up to review / merge next

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants