Skip to content

fix(chat-completions): validate non-streaming choices - #4697

Open
rioyu123 wants to merge 1 commit into
openai:mainfrom
rioyu123:codex/fix-nonstreaming-multiple-choices
Open

fix(chat-completions): validate non-streaming choices#4697
rioyu123 wants to merge 1 commit into
openai:mainfrom
rioyu123:codex/fix-nonstreaming-multiple-choices

Conversation

@rioyu123

Copy link
Copy Markdown

Summary

This pull request fixes non-streaming Chat Completions handling for provider responses that contain multiple choices or nonzero choice indexes.

  • align strict feature validation with the existing streaming guard by raising UserError
  • preserve the released default behavior of using the first returned choice while warning once per model instance
  • share the unsupported-choice diagnostic across streaming and non-streaming paths

Test plan

  • bash .agents/skills/code-change-verification/scripts/run.sh
  • uv run pytest tests/models/test_openai_chatcompletions.py tests/models/test_openai_chatcompletions_stream.py -q

Issue number

Follow-up to #3314.

Checks

  • I've added new tests, if relevant
  • I've run .agents/skills/code-change-verification/scripts/run.sh
  • I've confirmed all verification steps pass
  • If using Codex, I've run /review before submitting this PR

@rioyu123

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: 027644f203

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@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: 027644f203

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

f"{error_details}"
)

self._handle_unsupported_choices(response.choices)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Record usage before rejecting unsupported choices

When strict feature validation receives a completed response with multiple choices or a nonzero choice index, this call raises before the response's request and token usage is copied to span_generation.span_data.usage. Consequently, tracing and cost accounting omit an already completed, potentially billable request, unlike the later finish_reason='length' failure path that deliberately records usage before raising; account for the response usage before invoking this validation.

AGENTS.md reference: AGENTS.md:L147-L147

Useful? React with 👍 / 👎.

@seratch seratch changed the title fix: validate non-streaming Chat Completions choices fix(chat-completions): validate non-streaming choices Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants