fix(openai): stream compact responses to Codex clients#3876
Closed
specialpointcentral wants to merge 1 commit into
Closed
fix(openai): stream compact responses to Codex clients#3876specialpointcentral wants to merge 1 commit into
specialpointcentral wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts the OpenAI /responses/compact flow to preserve whether a client originally requested streaming (even though the compact body normalization drops stream), and to support Codex clients that expect an SSE stream by wrapping successful compact JSON responses into a single response.completed SSE event.
Changes:
- Preserve the original compact request’s
stream: truesignal on thegin.Contextbefore compact-body normalization removes it. - When a compact request was originally streaming, return the non-streaming upstream compact JSON as a single
response.completedSSE event (including OAuth passthrough where upstream may returntext/plainJSON). - Add test coverage for the SSE wrapping behavior and for propagation of the stream-requested flag.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| backend/internal/service/openai_gateway_service.go | Adds a context key to track whether a compact request originally requested streaming. |
| backend/internal/service/openai_gateway_response_handling.go | Wraps compact JSON responses as response.completed SSE for streaming Codex clients. |
| backend/internal/service/openai_gateway_request_body.go | Adds helpers to store/read the compact “client stream requested” flag on gin.Context. |
| backend/internal/service/openai_gateway_passthrough.go | Applies the same compact SSE wrapping behavior to OAuth passthrough non-streaming responses. |
| backend/internal/service/openai_compact_model_mapping_test.go | Adds a test validating SSE wrapping for OAuth passthrough compact responses (including text/plain JSON). |
| backend/internal/handler/openai_gateway_handler.go | Captures stream: true from compact request bodies before normalization drops stream. |
| backend/internal/handler/openai_gateway_compact_body_signal_test.go | Extends tests to assert the stream-requested flag is set when stream: true is present. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
c80216a to
5bcc701
Compare
5bcc701 to
68a4816
Compare
Author
|
close because: #3880 |
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/responses/compactrequests non-streaming, but wrap successful compact JSON responses as a singleresponse.completedSSE event for streaming Codex clientstext/plainJSONClose: #3875
Tests
docker run --rm -v /tmp/sub2api-compact-pr:/workspace -w /workspace/backend golang:1.26.5 go test ./internal/service ./internal/handler -run 'TestOpenAIGatewayService_OAuthPassthrough_CompactClientStreamWrapsJSONAsSSE|TestOpenAIGatewayService_OAuthPassthrough_CompactOnlyModelMappingOverridesUpstreamModel|TestOpenAIGatewayService_Forward_CompactOnlyModelMappingOverridesOAuthUpstreamModel|TestNormalizeOpenAIResponsesCompactRequest_BodySignalPromoted|TestNormalizeOpenAIResponsesCompactRequest_PathBasedNoDoubleSuffix'