Fix stale OpenAI Responses WebSocket reuse#6515
Open
MMYurt wants to merge 1 commit into
Open
Conversation
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
validate_cbtoConnectionPoolso unavailable pooled connections can be discarded before reuseclosedstate is already knownFixes #6513.
Problem
Concurrent Responses API requests can grow the WebSocket pool to multiple connections. If one or more of those connections close while idle, a later request may reuse a known-closed socket and fail at
send_str(). The outer LLM retry eventually recovers, but each stale connection can add a warning and retry backoff to a live voice turn.This change removes connections that fail a cheap, synchronous validation before returning them from the pool. The OpenAI transport uses
not ws.closedfor that check. Existing retry behavior remains unchanged for races where a connection becomes unusable after validation or during the send itself.Testing
uv run pytest tests/test_connection_pool.py --unit -q(5 passed)uv run pytest tests/test_plugin_openai_responses.py --plugin openai -q(3 passed)make check(format, lint, and strict mypy across 623 source files)Additional local unit-suite validation completed 1,216 tests with 4 skipped. Nine
tests/test_room.pycases could not set up because the local machine does not have the externallivekit-serverbinary installed.