Skip to content

fix: mark realtime session as closed before CancelledError on cycle detection#3926

Open
AAliKKhan wants to merge 1 commit into
openai:mainfrom
AAliKKhan:fix/realtime-close-inconsistent-state
Open

fix: mark realtime session as closed before CancelledError on cycle detection#3926
AAliKKhan wants to merge 1 commit into
openai:mainfrom
AAliKKhan:fix/realtime-close-inconsistent-state

Conversation

@AAliKKhan

Copy link
Copy Markdown
Contributor

When RealtimeSession.close() detects that the current task is a tracked guardrail or tool call task, it raises CancelledError to avoid a cycle (the cleanup task is already waiting for this tracked task). However, it did not set _closed = True before raising, leaving the session in an inconsistent state where subsequent calls to close() would attempt cleanup again. The fix sets both _closing and _closed before raising.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a1de5c62e9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

):
# Cleanup is already waiting for this tracked task, so waiting here would form a cycle.
self._closing = True
self._closed = True

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid marking the session closed before cleanup finishes

When a cancelled guardrail/tool task re-enters close() while _cleanup_task is active, this marks _closed before _cleanup has finished cancelling background work and closing the model. Any other close() call in that window returns immediately without waiting, and if model.close() later fails the retry path is disabled because _closed remains true, leaving the transport unclosed. Keep this path as in-progress and let _cleanup mark the session closed after resources are coherent. .agents/references/realtime-session-lifecycle.mdL25-L26

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants