Skip to content

fix(openai): keep responses streams alive#3806

Open
GitBruceSun wants to merge 1 commit into
router-for-me:devfrom
GitBruceSun:codex/stream-keepalive-fix
Open

fix(openai): keep responses streams alive#3806
GitBruceSun wants to merge 1 commit into
router-for-me:devfrom
GitBruceSun:codex/stream-keepalive-fix

Conversation

@GitBruceSun

Copy link
Copy Markdown

Summary

  • emit OpenAI Responses SSE keep-alives while waiting for the first upstream chunk
  • add ping/pong heartbeat handling to the Responses WebSocket endpoint
  • cover WebSocket heartbeat behavior with a regression test

Tests

  • go test ./sdk/api/handlers ./sdk/api/handlers/openai
  • go test ./...

@github-actions github-actions Bot changed the base branch from main to dev June 11, 2026 13:19
@github-actions

Copy link
Copy Markdown

This pull request targeted main.

The base branch has been automatically changed to dev.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces keep-alive and heartbeat mechanisms to prevent connection timeouts for both SSE streaming and WebSocket connections. Specifically, it adds a keep-alive ticker to the OpenAI SSE handler to periodically send keep-alive comments, and implements a background heartbeat goroutine for WebSockets that sends ping messages and manages read/write deadlines. A unit test has also been added to verify the WebSocket heartbeat functionality. There are no review comments, and I have no additional feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@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: cfdd11a278

ℹ️ 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".

Comment on lines +445 to +447
_ = conn.SetReadDeadline(time.Now().Add(responsesWebsocketReadTimeout))
conn.SetPongHandler(func(string) error {
return conn.SetReadDeadline(time.Now().Add(responsesWebsocketReadTimeout))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep reading pongs during long websocket streams

With this read deadline, the only downstream reads happen in ResponsesWebsocket before each request, while forwardResponsesWebsocket waits on upstream chunks and writes events without reading from conn. For any upstream response that keeps the server in that forwarding loop for more than 60 seconds, pong frames are not processed to refresh the deadline, so the next ReadMessage after the response returns a timeout and closes the session even if the client answered every ping; this breaks follow-up response.append/next-turn messages on long responses. Either drain control frames while forwarding or avoid a read deadline that cannot be refreshed during streaming.

Useful? React with 👍 / 👎.

@sususu98 sususu98 force-pushed the dev branch 2 times, most recently from 80d61a3 to ac4017e Compare June 11, 2026 13:49
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.

1 participant