Skip to content

Fix stale OpenAI Responses WebSocket reuse#6515

Open
MMYurt wants to merge 1 commit into
livekit:mainfrom
MMYurt:codex/openai-responses-stale-websocket
Open

Fix stale OpenAI Responses WebSocket reuse#6515
MMYurt wants to merge 1 commit into
livekit:mainfrom
MMYurt:codex/openai-responses-stale-websocket

Conversation

@MMYurt

@MMYurt MMYurt commented Jul 22, 2026

Copy link
Copy Markdown

Summary

  • add an optional validate_cb to ConnectionPool so unavailable pooled connections can be discarded before reuse
  • configure the OpenAI Responses WebSocket pool to reject connections whose closed state is already known
  • add hermetic regression coverage for both the generic pool and the OpenAI Responses transport

Fixes #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.closed for 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.py cases could not set up because the local machine does not have the external livekit-server binary installed.

@MMYurt
MMYurt requested a review from a team as a code owner July 22, 2026 18:58
@CLAassistant

CLAassistant commented Jul 22, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAI Responses WebSocket pool may reuse stale connections after concurrent requests

2 participants