Skip to content

[codex] Handle OpenAI chat request EOF with failover#3034

Draft
cyglawi-bit wants to merge 1 commit into
Wei-Shaw:mainfrom
cyglawi-bit:codex/openai-chat-eof-failover
Draft

[codex] Handle OpenAI chat request EOF with failover#3034
cyglawi-bit wants to merge 1 commit into
Wei-Shaw:mainfrom
cyglawi-bit:codex/openai-chat-eof-failover

Conversation

@cyglawi-bit

Copy link
Copy Markdown

Summary

  • Treat pre-response OpenAI Chat Completions upstream request failures as failoverable errors instead of immediately writing a downstream 502.
  • Share request-error ops recording between the converted Responses path and raw Chat Completions path.
  • Add regression coverage for OAuth/Responses and raw Chat Completions EOF-before-response cases.

Root Cause

When httpUpstream.Do(...) failed before an upstream response was available, the service wrote a Chat Completions 502 response directly and returned a plain error. The OpenAI chat handler only switches accounts for UpstreamFailoverError, so transient connection failures such as an upstream EOF could bypass the existing failover loop and stop the client request.

Impact

Transient upstream connection failures before any downstream bytes are written can now reuse the existing account failover path. Errors that happen after a response stream has already started are not retried, avoiding duplicate or corrupted client output.

Validation

  • git diff --check
  • GOPROXY=https://goproxy.cn,direct GOSUMDB=sum.golang.google.cn go test -tags unit -run 'TestForwardAs(ChatCompletions|RawChatCompletions)_UpstreamRequestEOFTriggersFailoverWithoutWritingResponse' ./internal/service -count=1

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Before we can merge this PR, we need you to sign our Contributor License Agreement (CLA).

To sign, please reply with the following comment:

I have read the CLA Document and I hereby sign the CLA

You only need to sign once — it will be valid for all your future contributions to this project.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

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