Repository navigation
Send max output tokens when the OpenAI Compatible checkbox shows ticked - #2684
SoccerField24x7 wants to merge 1 commit into
Conversation
The "Include max output tokens" checkbox shows an unset value as checked. The Chat Completions and Responses request builders sent a limit only for an explicit true. Both builders now use one resolver with the shared DEFAULT_OPEN_AI_INCLUDE_MAX_TOKENS default. Only an explicit false opts out. The resolver returns only positive limits. Profiles saved before Zoo-Code-Org#1847 with maxTokens: -1 do not send a negative limit. Kimi Code stays opt-in. This continues Zoo-Code-Org#2231 by @scriptxyz. Closes Zoo-Code-Org#2230 Co-authored-by: scriptxyz <11991772+scriptxyz@users.noreply.github.com>
|
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
Review statusThanks for contributing. This comment tracks the review sequence and the next action. Current step: Awaiting fresh human maintainer or CODEOWNER approval. Automated review is complete for the latest commit but does not replace human approval. Review-state labels are managed by this workflow; do not edit them manually. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Changed-code mutation testingReport for PR head
Details: mutants, guidance, and reproductionChanged-code mutation testing
Focused tests
All surviving and uncovered mutantsWarning annotations highlight up to 20 unique locations (maximum 7 per file). This summary lists every advisory mutant. types
|
Line | Status | Mutator | Replacement |
|---|---|---|---|
1120 | Survived | BooleanLiteral | false |
extension
src/api/providers/utils/openai-compatible-max-tokens.ts
Line | Status | Mutator | Replacement |
|---|---|---|---|
22 | Survived | ConditionalExpression | true |
Resolve a mutation gap
Add or strengthen a focused test that fails under the mutation. If the mutant is equivalent, request maintainer approval for the narrowest mutator-specific exclusion and explain why it cannot change behavior:
// Stryker disable next-line ConditionalExpression: normalized input cannot reach the alternate branch
const result = condition ? value : fallbackBroad all exclusions and exclusions without a concrete reason are reported as advisories.
Reproduce locally
From a full checkout containing both commits:
pnpm install --frozen-lockfile
node scripts/stryker-diff.mjs ci --base d672d7961a3c553f28f0436364a50481009850e1 --head 57e87f51bd77ae31ed1d337738ee70de29b622e8Mutation reports
- types:
reports/mutation/types/mutation.html - extension:
reports/mutation/extension/mutation.html - webview:
reports/mutation/webview/mutation.html
The workflow uploads generated reports in the changed-code-mutation-report artifact. A direct artifact link appears below after upload.
Related GitHub Issue
Closes: #2230
Credit
This PR continues #2231 by @scriptxyz. The shared default, the Kimi Code opt-in, and the base tests come from that PR. The bot closed #2231 because the author was inactive. @scriptxyz is a co-author of the commit.
Description
The "Include max output tokens" checkbox shows an unset value as checked (
?? true). The request builders sent a limit only for an explicittrue. Thus a profile that never toggled the checkbox showed it as ticked but sent no limit. Some gateways then used a low default limit. For example, a gateway default of 4096 tokens let reasoning use the full budget. The turn then stopped withfinish_reason: "length"and no output.This PR makes the UI and the request builders use the same default:
DEFAULT_OPEN_AI_INCLUDE_MAX_TOKENS = trueinpackages/types. The checkbox inOpenAICompatible.tsxreads it.resolveOpenAiCompatibleMaxTokens()insrc/api/providers/utils/openai-compatible-max-tokens.tsdecides the limit. An unset ornullvalue follows the default. Only an explicitfalseopts out. The resolver returns the first positive value frommodelMaxTokens, thenmodelInfo.maxTokens.addMaxTokensIfNeeded()sendsmax_completion_tokens) and the Responses API (buildResponsesRequest()sendsmax_output_tokens) cannot drift apart again.openAiModelInfoSaneDefaultshadmaxTokens: -1. Profiles saved before fix: update openai sane-default parameter values for custom models #1847 can still storeopenAiCustomModelInfo.maxTokens: -1. fix: update openai sane-default parameter values for custom models #1847 removed-1because Fireworks returns400 max_tokens must be non-negative. The resolver skips values that are not positive, so these profiles still send no limit.includeMaxTokens: options.includeMaxTokens === trueto the base handler. A value left in the profile by OpenAI Compatible does not opt it in.Changes since #2231:
=== trueproblem.if (maxTokens)to positive values only.if (maxTokens)lets a legacy-1through.Other subclasses do not change. DeepSeek passes
includeMaxTokens: trueand uses its own logic. MiMo passesincludeMaxTokens: false. Moonshot overridesaddMaxTokensIfNeeded(). DeepSeek, MiMo, Moonshot, and Kimi Code all passopenAiUseResponsesApi: false, so none of them can reachbuildResponsesRequest().Roadmap area: Reliability First (support more AI providers and models).
Reviewer callouts:
includeMaxTokensand a positive max output token value now sends the limit. This matches what the checkbox shows.false, legacy-1profiles, DeepSeek, MiMo, Moonshot, and Kimi Code.Test Procedure
New and changed tests (35 new test cases, 1 replaced, net +34):
openai-compatible-max-tokens.spec.ts(new)includeMaxTokensofundefined,null,true,false, each with 6 limit pairs:(456, 1000),(undefined, 1000),(0, 1000),(undefined, -1),(-1, 1000),(undefined, undefined)openai.spec.ts, Chat Completionstrue,false, and unset with legacy-1. Each case checks streaming, non-streaming, andcompletePromptopenai.spec.ts, Responses APImax_output_tokensfromcreateMessageand fromcompletePromptopenai-compatible-responses.spec.tsmodel: -1andcustom: -1kimi-code.spec.tsundefined,false, andtruegivefalse,false, andtrueWhen I restore the old request builder code, 6 of the new tests fail. The new resolver and
openai-compatible-responses.tshave 100% line and branch coverage.The existing
OpenAICompatible.spec.tsxtests already check that an unset value and anullvalue show the checkbox as checked. They pass without changes.Commands:
ESLint passes on all changed files. No suppression count in
src/eslint-suppressions.jsonchanges.Manual evidence: before the fix, an OpenAI Compatible gateway with
reasoning_effort: highused its default limit of 4096 tokens. Reasoning used the full budget, and the turn ended withfinish_reason: "length"and no output. After a toggle of the checkbox, Zoo Code sentmax_completion_tokens: 32000and the turn completed.Pre-Submission Checklist
src/test-utils/,@/utils/test-utils) are used only for mechanical duplication. Test intent and scenario-specific mocks remain visible.Visual Snapshots
Not applicable. The rendered UI does not change.
Videos (interaction / animation only)
Not applicable.
Documentation Updates
Additional Notes
Out of scope (possible follow-up issues):
max_tokenstogether withmax_completion_tokensfor gateways that ignore the newer field.maxTokens: -1values. The resolver guard makes this unnecessary for correctness.AI assistance: I used an AI coding assistant to help write the code and tests. I reviewed each change, and I ran the tests on my computer.
@taltas, please review this PR. @p12tic, you approved #2231. This PR keeps that design.
Get in Touch
CodeNja