Fix wake to wait for inflight steps before returning

Merged
MA
2mo ago
+142-11

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