Skip to content

fix(models): retry pre-request WebSocket handshake failures - #4780

Open
CoralGarden52 wants to merge 1 commit into
openai:mainfrom
CoralGarden52:fix/responses-ws-handshake-retry
Open

fix(models): retry pre-request WebSocket handshake failures#4780
CoralGarden52 wants to merge 1 commit into
openai:mainfrom
CoralGarden52:fix/responses-ws-handshake-retry

Conversation

@CoralGarden52

Copy link
Copy Markdown

Summary

OpenAIResponsesWSModel could fail immediately when the peer closed during the WebSocket HTTP upgrade. With the supported websockets>=15 client, a close before a valid HTTP 101 response is reported as websockets.exceptions.InvalidMessage. That exception was raised before _ensure_websocket_connection returned, so the existing pre-event retry path never handled it.

This change:

  • includes connection acquisition in the existing cleanup/retry boundary;
  • recognizes the exact pre-upgrade InvalidMessage case;
  • retries at most once, only before any request frame can have been sent;
  • marks that handshake failure as replay-safe for retry advice;
  • preserves the existing no-replay behavior for send/receive failures after a request may have been transmitted.

Test plan

  • Reproduced with a local raw TCP WebSocket server that closes the first connection before HTTP 101, then completes a valid handshake on the second connection.
  • The production model completed with 2 handshakes, exactly one response.create frame, and response_id=resp_local_probe.
  • make tests: 9292 passed, 29 skipped; serial tests: 77 passed, 4 skipped.
  • .agents/skills/code-change-verification/scripts/run.sh: passed (format, lint, typecheck, and tests).
  • Added regression coverage for handshake retry and replay-safe retry advice.
  • Searched open upstream PRs for InvalidMessage, websocket handshake, pre-event websocket, and websocket retry; no duplicate open PR was found.

Issue number

No existing issue found; the failure was reproduced locally against the real websockets handshake path.

Checks

  • I've added new tests, if relevant
  • I've run .agents/skills/code-change-verification/scripts/run.sh
  • I've confirmed all verification steps pass
  • If using Codex, I've run a read-only code review before submitting this PR

This PR is intentionally opened as a draft pending maintainer review.

@CoralGarden52
CoralGarden52 marked this pull request as ready for review August 30, 2026 11:32
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