Skip to content

fix: normalize responses streaming terminal output#2854

Open
ttt132 wants to merge 1 commit into
Wei-Shaw:mainfrom
ttt132:fix/responses-stream-completed-output
Open

fix: normalize responses streaming terminal output#2854
ttt132 wants to merge 1 commit into
Wei-Shaw:mainfrom
ttt132:fix/responses-stream-completed-output

Conversation

@ttt132
Copy link
Copy Markdown
Contributor

@ttt132 ttt132 commented May 28, 2026

Fixes #2819

Related: #2838

Summary

  • normalize terminal Responses SSE events when response.output is null, missing, non-array, or empty while accumulated output exists
  • rebuild terminal response.output from streamed deltas and image output items when available
  • fall back to response.output: [] so OpenAI SDK clients can iterate terminal output safely
  • preserve response.failed events without adding synthetic output

Difference from #2838

  • fix(openai): normalize terminal responses output #2838 normalizes null/missing terminal output to an empty array
  • this PR preserves final output content when prior streaming deltas are available, then falls back to an empty array only when there is no reconstructable output

Tests

  • GOPROXY=https://goproxy.cn,direct /tmp/go1.26.3/bin/go test ./internal/service -run 'TestOpenAIStreamingNormalizesTerminalOutput' -count=1
  • GOPROXY=https://goproxy.cn,direct /tmp/go1.26.3/bin/go test ./internal/service -run 'TestOpenAIStreaming|TestHandleNonStreamingResponse_APIKeyFallsBackToSSEBodyWhenContentTypeIsWrong|TestHandleSSEToJSON_ReconstructsImageGenerationOutputItemDone' -count=1
  • GOPROXY=https://goproxy.cn,direct /tmp/go1.26.3/bin/go test ./internal/service -count=1

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.

[Bug] OpenAI Responses streaming terminal event may emit response.output:null, causing OpenAI Python SDK TypeError

1 participant