Repository navigation
Send the AwaitingOn message before blocking on input - #318
Merged
Merged
Conversation
When do_progress cannot resolve the awaited future without input, the shared core writes an AwaitingOn message (service protocol V7) to the output. The poll loop then blocked on the next input event without sending it: Restate got the message only with whatever it sent next, when it was stale, and never saw the attempt idle, which it needs to suspend it early. Send the output right before awaiting input, as the TypeScript SDK does. tests/awaiting_on.py drives a handler through the ASGI app at V7, with the test playing Restate: the await is on the wire while the SDK waits, none is sent while a run executes, one is after the run's proposal, and closing the input suspends the invocation.
Contributor
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
I reviewed the one-line flush in the poll loop and the new wire-level test module.
- Flush before blocking: on
DoProgressWaitExternalProgress,create_poll_or_cancel_coroutinenow callstake_and_send_output()beforeawait self.receive(). The V7AwaitingOnMessagethatdo_progressjust wrote now goes out while the SDK waits, not after the next input arrives. Writes still go through_output_lock, and the count of messages sent per iteration doesn't change. tests/awaiting_on.py: plays Restate over ASGI at V7 and checks three things: the sleep's AwaitingOn is on the wire while the SDK is idle, nothing is sent while actx.runclosure executes, and an AwaitingOn followsProposeRunCompletion. Each scenario ends in aSuspension.
What I verified:
- I checked against shared-core 8.7.0 (
src/vm/transitions/async_results.rs).AwaitingOnMessageis only emitted on theWaitingExternalProgress { waiting_input: true }path, for V7+ with a non-empty handle set, under the defaultDontSendWhenExecutingRunpolicy. That matches both test expectations, including no AwaitingOn while the run executes. - Both new tests pass in about 0.3s. With line 724 reverted, both fail on the
untiltimeout (sent: ['0x40c']andsent: ['0x411', '0x5']), so they guard the fix. ruff checkandruff format --checkare clean.disconnect_hotloop.py,explicit_cancellation.pyandservercontext.pystill pass.
claude-opus-5-5 | 𝕏
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Problem
When
do_progressreturnsDoProgressWaitExternalProgress, shared-core has just written anAwaitingOnMessage(protocol V7) to the VM output. The message tells Restate what the attempt is waiting on. The poll loop increate_poll_or_cancel_coroutinethen awaited the next input without sending that output. The message only went out on the next loop iteration, after new input or a run completion had arrived, and by then it was already stale.So Restate never saw a Python invocation as idle-waiting while it actually was. Restate Server is starting to use this signal to suspend idle invocations early when concurrency slots run out, and that can't work for Python handlers without this fix.
Fix
Take and send the output before awaiting input. This is what the TypeScript SDK does:
outputPump.awaitNextProgress()beforeexternalProgressChannel.awaitNext(). It uses the existingtake_and_send_outputhelper, so writes still go through_output_lockand ordering is unchanged.create_poll_or_cancel_coroutineis the only caller ofdo_progress, and its other branches already flush before blocking. The sessions driver (explicit-recovery VM) never callsdo_progress.Test
tests/awaiting_on.pydrives a handler through the ASGI app at V7, with the test playing Restate on the wire. No Restate server is needed. It reuses the codec fromtests/sessions_wire.py.FIRST_COMPLETED{completions:[1], signals:[1]},executing_side_effects=false) is on the wire while the SDK waits.ctx.runclosure executes, and an AwaitingOn follows theProposeRunCompletion.Both tests fail on
main(the AwaitingOn never shows up) and pass with the fix in about 0.1 s.Other checks:
pytest tests/* -m "not server": everything passes exceptconnect.py::test_options_resolve_from_arguments_and_errors, which fails the same way onmain.ruff format --check,ruff check,pyrightandmypyare clean.🤖 Generated with Claude Code