Skip to content

Wake every poller after an input event reaches the VM (fixes #315) - #325

Open
kirillsergeev-workato wants to merge 1 commit into
restatedev:mainfrom
kirillsergeev-workato:fix/315-concurrent-awaits-lose-wakeups
Open

kirillsergeev-workato wants to merge 1 commit into
restatedev:mainfrom
kirillsergeev-workato:fix/315-concurrent-awaits-lose-wakeups

Conversation

@kirillsergeev-workato

@kirillsergeev-workato kirillsergeev-workato commented Nov 24, 2026 •

Copy link
Copy Markdown

Hi Restate team, thank you for the SDK!

We're building AI agents at Workato on Restate with pydantic-ai. pydantic-ai runs each parallel tool call in its own asyncio task, and each task awaits its own ctx.run_typed future. Runs regularly stalled until inactivity_timeout, even though every step had already completed and been journaled. This is #315.

Cause. Every awaiting task runs its own create_poll_or_cancel_coroutine loop, and they all read the one ReceiveChannel. When task B reads the event that completes task A's handle, B hands it to the VM, checks only its own handle and goes back to receive(). A stays blocked until the next input, which may never come. restate.run_completed events can be taken the same way.

Fix. Only one poller reads the input channel at a time. The others wait until it has handed the event to the VM, then call do_progress again for their own handle. The reader wakes them in a finally, so if it fails or is cancelled, another poller takes over. A cancelled receive() doesn't consume the event. restate.gather/select and single-task handlers behave as before.

This follows the same idea as the TypeScript fix in restatedev/sdk-typescript#724.

Tests. tests/concurrent_awaits.py drives the poll loop in-process against a fake VM. It covers an event that completes several handles, a handle completed by an event another poller read, run_completed, cancelling the reader, and a disconnect. Without the change, four of these tests hang until their timeout. tests/disconnect_hotloop.py only gains the two new attributes in its hand-built context.

Until this lands, we serialize awaits in our durability layer with a lock plus restate.gather. We'd be happy to remove that workaround and to adjust this PR however you prefer.

When futures are awaited from several asyncio tasks at once, each task ran its
own poll loop and read the shared input channel. An event read by one task
could complete another task's handle; that task stayed blocked in receive()
until the next input, which might never come, so the attempt stalled until the
inactivity timeout.

Now only one poller reads the input channel at a time. The others wait until
it has handed the event to the VM, then poll again for their own handle. The
reader wakes them even when it fails or is cancelled, so one of them takes over
reading.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@kirillsergeev-workato

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant