You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
RealtimeSession._cleanup() cancels pending Realtime guardrail and tool-call background tasks, but the current cleanup helpers clear the tracking sets immediately after task.cancel(). They do not await the cancelled tasks with asyncio.gather(..., return_exceptions=True) or an equivalent exception-collecting wait.
Impact:
_cleanup() can return before cancelled task finally blocks have run.
Cancellation exceptions or task callbacks can be processed after the session has already moved on to model close.
Guardrail and tool-call task cleanup behaves differently from the usual asyncio cancel-and-await cleanup pattern.
Relevant edge cases considered:
Guardrail background tasks and tool-call background tasks should both be awaited during cleanup.
Cancelled task finally blocks should complete before _cleanup() returns.
Cancellation exceptions should be collected with return_exceptions=True.
Tracking sets should be cleared only after the cancelled tasks have been awaited.
Debug information
Agents SDK version: upstream main at 479640e
Python version: Python 3.12.1
Repro steps
Run this minimal script from a repository checkout.
RealtimeSession._cleanup() should cancel pending guardrail and tool-call background tasks, await the tracked tasks while collecting cancellation exceptions, and only then clear the tracking sets and continue shutdown.
Please read this first
Describe the bug
RealtimeSession._cleanup()cancels pending Realtime guardrail and tool-call background tasks, but the current cleanup helpers clear the tracking sets immediately aftertask.cancel(). They do not await the cancelled tasks withasyncio.gather(..., return_exceptions=True)or an equivalent exception-collecting wait.Impact:
_cleanup()can return before cancelled taskfinallyblocks have run.Relevant edge cases considered:
finallyblocks should complete before_cleanup()returns.return_exceptions=True.Debug information
mainat479640eRepro steps
Run this minimal script from a repository checkout.
Actual result on upstream
mainat479640e:Expected behavior
RealtimeSession._cleanup()should cancel pending guardrail and tool-call background tasks, await the tracked tasks while collecting cancellation exceptions, and only then clear the tracking sets and continue shutdown.