Repository navigation
fix(controller): await non-coroutine awaitables in local workers - #703
Open
cccccindy-hub1 wants to merge 1 commit into
Open
cccccindy-hub1 wants to merge 1 commit into
cccccindy-hub1 wants to merge 1 commit into
Conversation
asyncio.run only accepts real coroutines; a custom awaitable returned by a synchronous run() fails with 'ValueError: a coroutine was expected'. Wrap the awaitable in a coroutine before handing it to asyncio.run, and drop the now unneeded type: ignore. Add tests for sync, coroutine, custom-awaitable and raising agents. Closes microsoft#666
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the change enabling local workers to handle non-coroutine awaitables.
No open issues 🎉
What changed in this PR
Fixes local worker handling of non-coroutine awaitables, addressing #666. The change allows custom awaitables returned by an agent’s synchronous run() method to execute on Python 3.12.
Changes:
- Wraps awaitable results in a coroutine before passing them to
asyncio.run, removing the argument-type suppression. - Adds four regression tests covering synchronous results, coroutines, custom awaitable execution, and agent exceptions.
| File | Description |
|---|---|
tests/controller/test_local_reconciler_worker.py |
Adds worker entry-point tests, including a completion assertion for custom awaitables. |
agentlightning/controller/local_reconciler.py |
Adds a coroutine wrapper to await results accepted by inspect.isawaitable. |
Review effort: Balanced
Author
|
@microsoft-github-policy-service agree |
This branch has not been deployed
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.
Summary
_run_local_reconciler_workerdetects async results withinspect.isawaitablebut passes them straight toasyncio.run, which only accepts realcoroutines. A valid custom awaitable returned by an agent's synchronous
run()fails on Python 3.12 withValueError: a coroutine was expected, so thelocal worker exits with code 1 and the rollout never completes.
Closes #666
Problem
On Python 3.12,
inspect.isawaitableis broader thanasyncio.run: it returnsTruefor any object implementing__await__, whileasyncio.run(viaRunner.run -> loop.run_until_complete -> tasks.ensure_future) only accepts genuine coroutines. The mismatch is silent at the type level becauseasyncio.runis annotated to acceptCoroutine[Any, Any, T]and the result was passed with a# type: ignore[arg-type].