Conversation
Contributor
Greptile SummaryThis PR strengthens agent and provider-stream teardown so cancellation covers the stream-attachment race and provider resources close deterministically.
Confidence Score: 5/5The PR appears safe to merge; no concrete changed-code defect remains after reviewing the cancellation, settlement, detachment, and provider-stream closure paths. The new cleanup boundaries are bounded and exception-safe, preserve SDK self-cancellation, and deterministically release wrapped streams across all tested termination modes. Important Files Changed
Reviews (1): Last reviewed commit: "fix(execution): cancel agent streams dur..." | Re-trigger Greptile |
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
Problem
Runner.run_streamed()starts its background task beforeAgentCoordinator.attach_stream()completes. If the owning agent task is cancelled while attachment is pending, the old cleanup boundary is never entered and the detached SDK task can continue model or sandbox work during teardown.The model idle-timeout wrapper also closes its inner stream only on timeout. Closing the outer guarded model generator does not synchronously close that wrapper, leaving provider cleanup to async-generator finalization.
Changes
mode="immediate"run_loop_taskto unwind before detachmentcontextlib.aclosing()around the idle-timeout wrapperaclose()andclose()supportTesting
uv run pytest tests/test_execution.py tests/test_stream_idle_timeout.py— 70 passeduv run pytest— 1685 passedFixes #1106