fix(openai): prime Images streams before upstream first byte#2349
Open
jiwangyihao wants to merge 1 commit into
Open
fix(openai): prime Images streams before upstream first byte#2349jiwangyihao wants to merge 1 commit into
jiwangyihao wants to merge 1 commit into
Conversation
Prime OpenAI Images stream responses after local validation and routing but before waiting for upstream response headers. Use SSE comments for the primer and convert post-primer upstream errors/fallbacks to SSE error events. Refs Wei-Shaw#2031
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
stream=trueresponses after local validation/routing and before waiting for the upstream response header.gateway.image_stream_keepalive_interval.Motivation
Images stream requests can spend a long time waiting for the upstream response header before any downstream byte is written. Reverse proxies/CDNs with first-byte or idle timeouts may close the client connection before the existing stream keepalive loop starts.
This change moves the downstream SSE opening point earlier for Images
stream=truerequests without changing non-streaming behavior.Behavior
stream=falseis unchanged.stream=trueImages requests receive SSE headers and an initial:comment before upstream headers arrive.event: errorevents instead of JSON responses.Tests
C:/Users/34404/Documents/GitHub/workbench/toolchains/go/bin/go.exe test -tags unit ./internal/handler ./internal/service -run 'TestOpenAIImagesStreamPrimer|TestHandleOpenAIImagesStreamPrimerForwardError|TestShouldWriteOpenAIImagesStreamPrimerForwardErrorIgnoresPrimerComments|TestOpenAIGatewayServiceForwardImages_(APIKeyStream|OAuthStreaming|APIKeyStreamJSONAfterPrimer|APIKeyStreamHTTPErrorAfterPrimer|OAuthStreamHTTPErrorAfterPrimer)' -count=1 -timeout=120sC:/Users/34404/Documents/GitHub/workbench/toolchains/go/bin/go.exe test -tags unit ./internal/handler ./internal/service -count=1 -timeout=180sgit diff --check origin/main...HEADRefs #2031