fix(chat-completions): validate non-streaming choices - #4697
Conversation
|
@codex review |
|
Security review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
There was a problem hiding this comment.
💡 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) |
There was a problem hiding this comment.
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 👍 / 👎.
Summary
This pull request fixes non-streaming Chat Completions handling for provider responses that contain multiple choices or nonzero choice indexes.
UserErrorTest plan
bash .agents/skills/code-change-verification/scripts/run.shuv run pytest tests/models/test_openai_chatcompletions.py tests/models/test_openai_chatcompletions_stream.py -qIssue number
Follow-up to #3314.
Checks
.agents/skills/code-change-verification/scripts/run.sh/reviewbefore submitting this PR