fix(realtime): await cancelled guardrail and tool-call tasks during cleanup#3764
Closed
Diwak4r wants to merge 1 commit into
Closed
fix(realtime): await cancelled guardrail and tool-call tasks during cleanup#3764Diwak4r wants to merge 1 commit into
Diwak4r wants to merge 1 commit into
Conversation
…leanup RealtimeSession._cleanup() cancelled pending guardrail and tool-call background tasks but neither awaited them nor deferred clearing the tracking sets, so cleanup could return before the tasks' finally blocks ran. Clear the tracking sets before cancelling and await the cancelled tasks with return_exceptions=True so their finally blocks run before cleanup returns. Fixes openai#3334
Member
|
Thanks again for your interest here. The issue was resolved by #3767 |
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
RealtimeSession._cleanup()cancels pending guardrail and tool-call background tasks but never awaited them, so cleanup could return before the tasks'finallyblocks executed. The tracking sets (_guardrail_tasks,_tool_call_tasks) were also cleared before cancellation took effect, which could drop references to in-flight tasks.This makes
_cleanup_guardrail_tasksand_cleanup_tool_call_tasksasync: they now collect the not-yet-done tasks, clear the tracking set first, cancel the tasks, andawait asyncio.gather(..., return_exceptions=True)so each task'sfinallyblock runs and the cancellation is observed before_cleanupreturns.Fixes #3334
Test plan
tests/realtime/test_session.py::test_cleanup_awaits_cancelled_guardrail_and_tool_call_tasks: seeds two never-returning background tasks into the tracking sets, calls_cleanup(), and asserts both tasks are done, thefinishedevent is set (proving thefinallyblocks ran), and the tracking sets are empty.uv run python -m pytest tests/realtime/test_session.py— full suite passes (111 passed), no regressions.Note: this repo does not require DCO sign-off, so the commit is not
-s.