Repository navigation
fix(ai): send max_tokens on Model Studio compatible-mode endpoints - #168513
synthalorian wants to merge 1 commit into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Proof for head Before this commit, the new "Model Studio compatible-mode" cases failed: After the fix:
Request-builder proof only. No Model Studio key was used, so live vendor handling of |
|
Codex review: needs real behavior proof before merge. What this changesThe PR sends Model Studio compatible-mode output budgets as max_tokens while preserving Coding Plan behavior and explicit overrides. Example: A qwen3.5-plus request to https://dashscope.aliyuncs.com/compatible-mode/v1 has an output budget of 1234 tokens.
Review scores
ProductKind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Complete Merge readiness⛔ Blocked before merge - 2 items remain This PR addresses a current provider-contract mismatch with a focused shared-owner fix; no concrete introduced bug was found. Priority: P2 Decision needed
Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherThe shared completions compatibility resolver combines provider metadata, endpoint identity, and explicit model overrides; both direct and managed transports consume its selected request field. flowchart LR
A[Model settings] --> C[Shared compatibility resolver]
B[Provider metadata] --> C
C --> D[Request builder]
D --> E[Direct or managed transport]
E --> F[Model Studio endpoint]
Technical reviewBest possible solution: Use the documented field through the existing shared resolver, with Coding Plan and explicit overrides preserved. Do we have a high-confidence way to reproduce the issue? Current-main source deterministically selects the undocumented field for the reported routes, matching the reporter's resolver output; vendor-side failure remains unobserved. Is this the best way to solve the issue? The scoped change uses the existing owner shared by both transport modes and avoids a broader plugin API expansion. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2dd42a977aa9. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +26, Tests +109. Total +135 across 2 files. Added test files: 0. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed October 12, 2026, 9:19 PM ET / October 13, 2026, 01:19 UTC (Revision 2). |
49c97ff to
ecdd7b8
Compare
|
Live request proof for head No Model Studio, OpenAI, or Coding Plan endpoint was contacted, and no provider API key was read or printed. Commands: That Vitest run: 3 files, 81 tests, all passed. The local capture was a one-shot
{
"model": "qwen3.5-plus",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "ping",
"cache_control": { "type": "ephemeral" }
}
]
}
],
"stream": true,
"stream_options": { "include_usage": true },
"max_tokens": 1234
}
{
"model": "gpt-5.4",
"messages": [
{
"role": "user",
"content": "ping"
}
],
"stream": true,
"stream_options": { "include_usage": true },
"store": false,
"max_completion_tokens": 1234
}
{
"model": "qwen3.5-plus",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "ping",
"cache_control": { "type": "ephemeral" }
}
]
}
],
"stream": true,
"stream_options": { "include_usage": true },
"max_completion_tokens": 1234
}Explicit |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
ecdd7b8 to
3a4a6fa
Compare
Model Studio documents max_tokens for /compatible-mode/v1 and does not document max_completion_tokens. The shared completions resolver already recognizes the family, but usesMaxTokens omitted it, so compatible-mode requests wrote the cap on the undocumented field. Limit the switch to Alibaba compatible-mode hosts. Coding Plan keeps max_completion_tokens, explicit compat.maxTokensField overrides still win, and OpenAI plus other vendors stay unchanged.
3a4a6fa to
f6cc650
Compare
|
Thanks @synthalorian for identifying this and contributing the fix! Landed as credited replacement #189870 (2c2bf4b), using the existing compatibility flag with a regression proven red on main and green after. Coding Plan and explicit overrides remain unchanged. |
What Problem This Solves
Model Studio compatible-mode requests (
qwen,qwencloud,modelstudio,dashscope,qwen-token-plan, andbailian-token-plan) send the output cap asmax_completion_tokens. Alibaba's OpenAI-compatibility reference documentsmax_tokensfor that surface and does not listmax_completion_tokens, so the configured cap can be ignored or the request can be rejected.Why This Change Was Made
resolveOpenAICompletionsCompatDefaultsalready treats this family as Model Studio for other flags, butusesMaxTokensomitted it and fell through to the OpenAI field. The fix adds that family only when the base URL is an Alibaba compatible-mode host (*.dashscope*.aliyuncs.comor*.maas.aliyuncs.comwith a/compatible-mode/path).Coding Plan hosts stay on
max_completion_tokens. That surface shares themodelstudio-nativeendpoint class, and the cited reference does not cover it. Explicitmodel.compat.maxTokensFieldstill wins. OpenAI and the other vendors that already selectmax_tokensormax_completion_tokensare unchanged. Unrelated/compatible-mode/proxy URLs are unchanged.User Impact
Compatible-mode Model Studio calls now send the configured output budget as
max_tokens. A budget stored asparams.max_completion_tokensis still honored; only the wire field changes. Coding Plan, OpenAI, and other providers keep their current field. No config migration is required.Evidence
On head
ecdd7b81ce7a9740b097340d0b336fb64134040c(rebased onto currentupstream/main):Live transport proof did not call Model Studio, OpenAI, or Coding Plan. A local HTTP server on
127.0.0.1received the raw POST body fromstreamOpenAICompletionsRequestin managed mode. Host classification came fromresolveProviderRequestCapabilities(plugin metadata). The fetch hook refused every hostname except the three proof hosts and forwarded only the request body to that local server. No provider key was read or sent.qwen,https://dashscope.aliyuncs.com/compatible-mode/v1, classifiedmodelstudio-native/modelstudio) sentmax_tokensand notmax_completion_tokens.openai,https://api.openai.com/v1, classifiedopenai-public/openai-family) sentmax_completion_tokens.qwen,https://coding.dashscope.aliyuncs.com/v1, classifiedmodelstudio-native/modelstudio) sentmax_completion_tokens.The redacted bodies are in the PR comment on this head. Vendor acceptance of the field was not observed. The field choice follows https://www.alibabacloud.com/help/en/model-studio/compatibility-of-openai-with-dashscope
Fixes #127119