Problem
When Runner.run_async() is cancelled mid-execution via asyncio.CancelledError, the tool_context resources (open connections, auth sessions, file handles) may not be properly cleaned up if the cleanup code doesn't handle CancelledError.
Impact
Each cancelled run can leak resources. Under repeated cancellation patterns (e.g., timeout-based cancellation in production), accumulated resource exhaustion can crash the runtime.
Suggestion
Consider wrapping cleanup in asyncio.shield() or ensuring the finally block catches CancelledError to guarantee cleanup runs even when the task is cancelled.
Problem
When
Runner.run_async()is cancelled mid-execution viaasyncio.CancelledError, thetool_contextresources (open connections, auth sessions, file handles) may not be properly cleaned up if the cleanup code doesn't handleCancelledError.Impact
Each cancelled run can leak resources. Under repeated cancellation patterns (e.g., timeout-based cancellation in production), accumulated resource exhaustion can crash the runtime.
Suggestion
Consider wrapping cleanup in
asyncio.shield()or ensuring thefinallyblock catchesCancelledErrorto guarantee cleanup runs even when the task is cancelled.