Fix wake to wait for inflight steps before returning
Merged
MA
2mo ago+142+142+012345678901234567890123456789-11-11-01234567890123456789
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 callself.runtime.settled.record()whennot 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
Settledclass docstring inruntime.pyto reflect the new requirement - Updated
wake()docstring inrunner.pyto clarify the settled condition - Updated README.md to explain that
wakewaits until steps are done running
Test coverage:
- Added
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 pass
Testing
The new regression test test_wake_waits_for_the_steps_it_took_to_finish verifies the fix by:
- Creating a workflow step
- Mocking
executeto hold execution until the test signals it - Confirming that
wakedoes not complete while the step is running - Releasing the step and confirming
wakecompletes after it finishes
Existing tests continue to pass.