Require closable async iterators - #473
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens streaming interfaces in lmi to require closable async generators and adds explicit aclose() calls so upstream provider streams can be interrupted and cleaned up reliably (in preparation for PR #471’s streaming behavior).
Changes:
- Narrow streaming type contracts from generic
AsyncIterable/AsyncIteratortoAsyncGeneratorwhere closure is required. - Ensure committed/limited streaming wrappers close their upstream generators via
aclose(). - Add tests asserting upstream streams are closed when wrappers are closed.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/lmi/src/lmi/llms.py | Tightens streaming return types to AsyncGenerator and adds upstream aclose() in committed and limiter wrappers. |
| packages/lmi/src/lmi/cost_tracker.py | Adds TrackedStreamWrapper.aclose() delegating to the wrapped provider stream. |
| packages/lmi/tests/test_dispatch.py | Updates generator typing and adds a regression test ensuring committed streams close their source. |
| packages/lmi/tests/test_cost_tracking.py | Adds a test ensuring TrackedStreamWrapper.aclose() closes the wrapped stream. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
sidnarayanan
approved these changes
Jul 21, 2026
elimoss
force-pushed
the
closable-async-generators
branch
from
July 21, 2026 22:24
1a90dfd to
e2195da
Compare
sidnarayanan
approved these changes
Jul 21, 2026
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.
In a few places we are passing around async iterators that may or may not implement
aclose. tighten this to specify that they do and add unconditional call to aclose after exit or cancellation. this allows more reliable stream interruption handling and lifecycle management in preparation for #471