Repository navigation
Wake every poller after an input event reaches the VM (fixes #315) - #325
Open
kirillsergeev-workato wants to merge 1 commit into
Open
kirillsergeev-workato wants to merge 1 commit into
kirillsergeev-workato wants to merge 1 commit into
Conversation
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]>
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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_typedfuture. Runs regularly stalled untilinactivity_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_coroutineloop, and they all read the oneReceiveChannel. 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 toreceive(). A stays blocked until the next input, which may never come.restate.run_completedevents 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_progressagain for their own handle. The reader wakes them in afinally, so if it fails or is cancelled, another poller takes over. A cancelledreceive()doesn't consume the event.restate.gather/selectand single-task handlers behave as before.This follows the same idea as the TypeScript fix in restatedev/sdk-typescript#724.
Tests.
tests/concurrent_awaits.pydrives 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.pyonly 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.