Repository navigation
fix: send max_completion_tokens to Azure OpenAI reasoning models - #31952
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c072f4748f
ℹ️ 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".
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Azure OpenAI providers fell through to the OpenAI-compatible client, which drops every provider_options.openai setting and always speaks Chat Completions with max_tokens. Azure now shares the OpenAI client. An unset use_responses_api defaults to Chat Completions for Azure, because a deployment name does not identify the model, and the admin UI shows Use Responses API and Reasoning Model for Azure. Fixes #31714
…type ModelFromConfig checked reasoning_mode against the client name. Azure and Bedrock OpenAI-format models use the OpenAI client, so the runtime check let them through. newModel now runs the same check as the API, with the configured AI provider type, and returns a config error.
ab8e1b1 to
761fea0
Compare
Part of CODAGT-1430 Relates to CODAGT-1541 Stacked on #31743. This bumps fantasy to pick up coder/fantasy#84 and coder/fantasy#85. A Chat Completions tool message can only hold text, so fantasy sends tool result media (images, audio, and now PDFs from #31384) in a `role: "user"` message right after it. That gives whatever the tool returned the authority of the user's own words, which Codex flagged on #31383 as a prompt injection risk for MCP tools that return untrusted files. coder/fantasy#84 starts that user message with a text part naming the tool call and saying the content is tool output, not instructions from the user. It only changes the Chat Completions paths (`openai` without the Responses API, `openaicompat`, OpenRouter and Vercel); Anthropic and Responses keep the media inside the tool result. AI Bridge records the last user message's text as the prompt, so on the step after a tool returns media, it'll now record the label. I think that's fine for now. coder/fantasy#85 fixes the output token limit field. The OpenAI provider sent `max_tokens` unless the model ID looked like a reasoning model, and reasoning models reject it: ``` Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead. ``` That breaks any reasoning model whose ID fantasy doesn't recognise, e.g. an Azure deployment name, which doesn't say what model it serves (Azure providers start using this client in #31952). The OpenAI provider now sends `max_completion_tokens` on every Chat Completions request, which is what OpenAI deprecated `max_tokens` in favour of. `openaicompat`, OpenRouter and Vercel keep `max_tokens`, so self-hosted servers behind the OpenAI Compatible provider are unaffected. I've added a test that checks the field on each route, and the models docs no longer say Max Completion Tokens is only for reasoning models.
|
@codex review |
|
@codex security review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
🛡️ Codex Security ReviewSecurity 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. |
Documentation CheckBlocking
Findings for agents- id: coverage-1
persona: coverage
class: missing
blocking: true
file: docs/coder-agents/models.md
line: 289
quote: "Azure OpenAI models use the Chat Completions API unless you set **Use Responses API** to On, because the deployment name doesn't identify the model."
evidence:
- coderd/x/chatd/chatprovider/chatprovider.go:148-150
- coderd/x/chatd/media_sanitize.go
rule: null
problem: Turning on **Use Responses API** for an Azure model silently drops audio tool-result media, and the note does not mention it.
fix: Add to the Azure note that the Responses route accepts images but not audio or PDFs.
verified: true
- id: coverage-2
persona: coverage
class: missing
blocking: true
file: docs/coder-agents/models.md
line: 289
quote: "Azure OpenAI uses the same options as OpenAI except Reasoning Mode."
evidence:
- site/src/api/chatModelOptionsGenerated.json:90
rule: null
problem: The **Reasoning Model** override is now exposed for Azure, but the Azure note still says Azure uses the same options as OpenAI except Reasoning Mode.
fix: Clarify that the **Reasoning Model** override is available for Azure, distinct from Reasoning Mode.
verified: true
- id: language-1
persona: language
class: rule
blocking: true
file: docs/coder-agents/models.md
line: 289
quote: "Azure OpenAI models use the Chat Completions API unless you set **Use Responses API** to On, because the deployment name doesn't identify the model."
evidence:
- docs/coder-agents/platform-controls/virtual-desktop.md:65
rule: docs/.style/style-guide/formatting.md#bold-for-ui-elements
problem: The option value **On** is literal UI text and should be bolded.
fix: "Azure OpenAI models use the Chat Completions API unless you set **Use Responses API** to **On**, because the deployment name doesn't identify the model."
verified: trueAutomated review via Coder Agents. Reply to a finding's thread with the reason if the finding is wrong. |
| The **OpenAI Compatible** type is a catch-all for any service that exposes an OpenAI-compatible chat completions endpoint. | ||
| Use it to connect to self-hosted models, internal gateways, or third-party proxies like LiteLLM. | ||
|
|
||
| Use the **Azure OpenAI** type for GPT-4o and newer OpenAI models. |
There was a problem hiding this comment.
(Newcomer) The paragraph says which models use the Azure OpenAI type, but it doesn't tell the reader how to check a deployment against that rule. Point them to the model each deployment serves, which the note below says the deployment name doesn't show.
| Use the **Azure OpenAI** type for GPT-4o and newer OpenAI models. | |
| Use the **Azure OpenAI** type for GPT-4o and newer OpenAI models. Check the model that each deployment serves before you choose a type, because the deployment name doesn't show it. |
Bump the fantasy fork to its sync with upstream v0.48.3 (coder/fantasy#86), whose Chat Completions reasoning check knows gpt-6 through gpt-9. Azure OpenAI models now also obey the Reasoning Model setting, and the model form shows it for them, as a deployment name does not have to say what model it serves. This replaces the earlier approach of routing Azure OpenAI through the OpenAI client.
|
@codex review |
|
@codex security review |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
🛡️ Codex Security ReviewSecurity 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. |
coder/fantasy#87 stops treating model IDs that contain -chat as non-reasoning models and recognizes chat-latest, so Azure OpenAI deployments named like gpt-5.1-chat or gpt-chat-latest get max_completion_tokens.
|
@codex review |
|
@codex security review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2390ba084a
ℹ️ 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".
🛡️ Codex Security ReviewSecurity 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. |
…that offer it The OpenAI-compatible client obeyed a stored reasoning model override for every provider type it serves, although the model form offers the setting only for OpenAI, Bedrock and Azure OpenAI. A value stored through the API for a Google, OpenRouter, Vercel or OpenAI Compatible model is ignored again, as on main.
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…names coder/fantasy#88 lets a reasoning marker win over gpt-3, gpt-4 and chatgpt- on Chat Completions, so Azure OpenAI deployments named like chatgpt-5 get max_completion_tokens. It also narrows the oss and computer-use markers to gpt-oss and a leading computer-use, so they no longer match third-party model IDs.
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Closes #31714
Closes WI-31
Azure OpenAI reasoning models reject
max_tokens:We pick between
max_tokensandmax_completion_tokensfrom the model name, and that check only knew names up togpt-5, so agpt-6-lunadeployment failed on default settings. To fix, the fantasy bump (coder/fantasy#86, coder/fantasy#87 and coder/fantasy#88) extends the check togpt-6throughgpt-9. That bump is a full sync with upstream, so it also brings the other chatd changes listed there, which is why a few test expectations move here.On Azure that name is the deployment name though, which doesn't have to say what model it serves. So the model form now also shows the existing Reasoning Model setting for Azure models, and we obey it. With it on, we send
max_completion_tokensand droptemperatureandtop_p, whatever the deployment is called.I confirmed against a real Azure
gpt-5.4deployment that it rejectsmax_tokensand acceptsmax_completion_tokens, but that test resource has since gone, so I haven't run this exact change against Azure.This only fixes the
max_tokenserror. Going by Microsoft's docs, I think GPT-6 chats on Azure will then hit a second error, as on Chat Completions those models only accept tools with the reasoning effort set tonone, or not at all. The OpenAI and Bedrock providers use the Responses API, so they aren't affected. I can't reproduce that for the same reason, so it's being tracked separately at CODAGT-1655.