Skip to content

Send the AwaitingOn message before blocking on input - #318

Merged
slinkydeveloper merged 2 commits into
mainfrom
fix/flush-awaiting-on-before-blocking
Nov 17, 2026
Merged

slinkydeveloper merged 2 commits into
mainfrom
fix/flush-awaiting-on-before-blocking

Conversation

@StephanEwen

Copy link
Copy Markdown
Contributor

Problem

When do_progress returns DoProgressWaitExternalProgress, shared-core has just written an AwaitingOnMessage (protocol V7) to the VM output. The message tells Restate what the attempt is waiting on. The poll loop in create_poll_or_cancel_coroutine then 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() before externalProgressChannel.awaitNext(). It uses the existing take_and_send_output helper, so writes still go through _output_lock and ordering is unchanged.

create_poll_or_cancel_coroutine is the only caller of do_progress, and its other branches already flush before blocking. The sessions driver (explicit-recovery VM) never calls do_progress.

Test

tests/awaiting_on.py drives 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 from tests/sessions_wire.py.

  • A sleep's AwaitingOn (FIRST_COMPLETED{completions:[1], signals:[1]}, executing_side_effects=false) is on the wire while the SDK waits.
  • Nothing is sent while a ctx.run closure executes, and an AwaitingOn follows the ProposeRunCompletion.
  • Closing the input ends in a Suspension.

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 except connect.py::test_options_resolve_from_arguments_and_errors, which fails the same way on main.
  • ruff format --check, ruff check, pyright and mypy are clean.

🤖 Generated with Claude Code

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.

@pullfrog pullfrog 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.

✅ 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_coroutine now calls take_and_send_output() before await self.receive(). The V7 AwaitingOnMessage that do_progress just 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 a ctx.run closure executes, and an AwaitingOn follows ProposeRunCompletion. Each scenario ends in a Suspension.

What I verified:

  • I checked against shared-core 8.7.0 (src/vm/transitions/async_results.rs). AwaitingOnMessage is only emitted on the WaitingExternalProgress { waiting_input: true } path, for V7+ with a non-empty handle set, under the default DontSendWhenExecutingRun policy. 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 until timeout (sent: ['0x40c'] and sent: ['0x411', '0x5']), so they guard the fix.
  • ruff check and ruff format --check are clean. disconnect_hotloop.py, explicit_cancellation.py and servercontext.py still pass.

Pullfrog  | View workflow run | Using claude-opus-5-5 | 𝕏

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Test Results

  8 files  ±0    8 suites  ±0   3m 46s ⏱️ -12s
 71 tests ±0   71 ✅ ±0  0 💤 ±0  0 ❌ ±0 
322 runs  ±0  322 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 965d7ea. ± Comparison against base commit c16e4ed.

♻️ This comment has been updated with latest results.

@slinkydeveloper
slinkydeveloper merged commit 4dec3a9 into main Nov 17, 2026
12 checks passed
@slinkydeveloper
slinkydeveloper deleted the fix/flush-awaiting-on-before-blocking branch November 17, 2026 14:12
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants