You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Fix] Send max output tokens when the OpenAI Compatible checkbox shows ticked - #2231
The "Include max output tokens" checkbox and the request builder use different defaults. The UI reads an unset includeMaxTokens as checked. The request builder sends max_completion_tokens only for an explicit true. Thus a profile that does not store the value shows a ticked box and sends no limit.
This PR makes the two agree:
Add DEFAULT_OPEN_AI_INCLUDE_MAX_TOKENS = true in packages/types, next to DEFAULT_OPEN_AI_STRICT_TOOL_SCHEMAS.
OpenAiHandler.addMaxTokensIfNeeded() reads includeMaxTokens ?? DEFAULT_OPEN_AI_INCLUDE_MAX_TOKENS. Only an explicit false opts out.
OpenAiHandler.addMaxTokensIfNeeded() adds the field only when a limit exists (modelMaxTokens or info.maxTokens). It does not assign undefined.
OpenAICompatible.tsx uses the same constant for the checkbox.
KimiCodeHandler extends OpenAiHandler and has no checkbox. It now passes includeMaxTokens: options.includeMaxTokens === true. This keeps its previous behavior.
Reviewers, check these points:
Behavior change: existing OpenAI Compatible profiles with an unset value now send max_completion_tokens. This occurs only when a max output token value is set. Profiles without a value do not change.
DeepSeek sets true, MiMo sets false, and Moonshot overrides addMaxTokensIfNeeded(). These providers do not change.
pnpm --dir webview-ui exec vitest run src/components/settings/providers/__tests__/OpenAICompatible.spec.tsx: 22 passed. The existing test checks that the box shows checked when the value is unset.
pnpm --dir src run check-types and tsc --noEmit in webview-ui: pass.
eslint --prune-suppressions --max-warnings=0 on the changed src files: pass. No suppression count changed.
New tests:
openai.spec.ts: an it.each test for unset, true, and false. It checks streaming and non-streaming requests. It replaces the old test that expected no limit for an unset value.
kimi-code.spec.ts: an it.each test that checks Kimi Code stays opt-in.
Pre-Submission Checklist
Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
Scope: My changes are focused on the linked issue (one major feature/fix per PR).
Self-Review: I reviewed my own code with care.
Writing Style: The PR title and description use Simplified Technical English (ASD-STE100): short sentences, plain words, active voice, one idea per sentence, no contractions.
Testing: New and/or updated tests have been added to cover my changes (if applicable).
Visual Snapshot (UI changes only): Not applicable. The checkbox looks the same.
Documentation Impact: I checked if my changes need documentation updates (see "Documentation Updates" section below).
…s ticked
The "Include max output tokens" checkbox treated an unset value as checked,
but the request builder only sent max_completion_tokens for an explicit true.
Profiles that never toggled the box showed it ticked and sent no limit.
Add DEFAULT_OPEN_AI_INCLUDE_MAX_TOKENS and read it in both places, so only an
explicit false opts out. Skip the field when no limit is configured instead of
assigning undefined. Kimi Code has no such control, so it keeps the previous
opt-in behaviour.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Auto reviews are limited based on label configuration.
🏷️ Required labels (at least one): 1
coderabbit-review-active
Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Summary
Summary by CodeRabbit
New Features
OpenAI-compatible providers now include the maximum output token limit by default when a limit is available.
Bug Fixes
Turning off “Include max output tokens” continues to omit the limit from requests.
Kimi Code only includes the limit when the setting is explicitly enabled.
OpenAI-compatible max-token inclusion now uses a shared default of true when the setting is unset. The request handler adds a token limit when enabled and a configured or model fallback limit is truthy. Kimi Code enables the option only when it is explicitly set to true.
The OpenAI handler applies the default when the option is unset and adds max_completion_tokens when the selected token limit is truthy. Kimi Code passes true only when explicitly enabled. Tests cover unset, false, and true cases.
The change aligns unset OpenAI-compatible profiles with the checked checkbox while preserving Kimi Code’s opt-in behavior. No established issue requires blocking merge; normal validation still applies.
Pre-merge checks: 7 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Regression Evidence
The OpenAI request-builder change has focused coverage for unset, true, and false values in streaming and non-streaming requests. However, the changed Kimi Code adapter at `src/api/providers/kimi-code…
Add a Kimi Code request-level test using a mocked client.chat.completions.create call. Exercise includeMaxTokens as unset, false, and true with a model max-token value, then assert that the generated request omits `max_completion_tokens…
Passed checks: 7 passed
Check name
Status
Explanation
Title check
The title clearly states the main fix: sending max output tokens when the OpenAI Compatible checkbox is checked.
Description check
The description includes the linked issue, implementation details, affected provider behavior, test procedure and results, checklist, visual snapshot assessment, and documentation impact.
Linked Issues check
Issue #2230 requires the OpenAI Compatible request to match the checked checkbox when a maximum-token value exists. OpenAiHandler.addMaxTokensIfNeeded() now treats unset includeMaxTokens as `DEFAU…
Out of Scope Changes check
The changes remain within issue #2230. The shared default export supports consistent UI and request-builder behavior. The Kimi Code adapter explicitly preserves its prior opt-in behavior, and its regr…
Security Boundaries
No changed path violates the security-boundary conditions. The PR adds a boolean default and changes OpenAiHandler.addMaxTokensIfNeeded() to send only a numeric max_completion_tokens value from va…
Persistence Integrity
No changed persistence path exists. The diff only adds DEFAULT_OPEN_AI_INCLUDE_MAX_TOKENS, consumes it in the checkbox and OpenAiHandler.addMaxTokensIfNeeded, and sets an in-memory Kimi Code optio…
Lifecycle Resource Cleanup
No changed lifecycle path exists. The PR changes only the max-token default, request-field assignment, Kimi option mapping, and checkbox fallback. The OpenAI call sites still use the existing request …
Full details: Linked Issues check
Explanation
Issue #2230 requires the OpenAI Compatible request to match the checked checkbox when a maximum-token value exists. OpenAiHandler.addMaxTokensIfNeeded() now treats unset includeMaxTokens as DEFAULT_OPEN_AI_INCLUDE_MAX_TOKENS (true), omits the field only for explicit false, and assigns max_completion_tokens only when modelMaxTokens or modelInfo.maxTokens exists. OpenAICompatible.tsx uses the same default. The updated OpenAI tests cover unset, true, and false values for streaming and non-streaming requests.
Full details: Out of Scope Changes check
Explanation
The changes remain within issue #2230. The shared default export supports consistent UI and request-builder behavior. The Kimi Code adapter explicitly preserves its prior opt-in behavior, and its regression test covers that compatibility case. The added provider tests directly validate the requested behavior.
Full details: Security Boundaries
Explanation
No changed path violates the security-boundary conditions. The PR adds a boolean default and changes OpenAiHandler.addMaxTokensIfNeeded() to send only a numeric max_completion_tokens value from validated provider/model settings; it does not expose secrets or PII, execute input, or alter URL, header, authentication, approval, or allowlist handling. KimiCodeHandler uses an exact-true check and does not broaden its opt-in behavior.
Full details: Persistence Integrity
Explanation
No changed persistence path exists. The diff only adds DEFAULT_OPEN_AI_INCLUDE_MAX_TOKENS, consumes it in the checkbox and OpenAiHandler.addMaxTokensIfNeeded, and sets an in-memory Kimi Code option. Provider settings still store includeMaxTokens as an optional field; no write, migration, rollback, or persistence operation changed. Both changed consumers read the shared default, so no persisted default is left unpropagated.
Full details: Lifecycle Resource Cleanup
Explanation
No changed lifecycle path exists. The PR changes only the max-token default, request-field assignment, Kimi option mapping, and checkbox fallback. The OpenAI call sites still use the existing request flow and abort signal. The existing UI debounce timer and message subscription are unchanged, including their existing cleanup behavior. No listener, watcher, timer, task, provider, or other resource is newly allocated or duplicated.
Full details: Regression Evidence
Explanation
The OpenAI request-builder change has focused coverage for unset, true, and false values in streaming and non-streaming requests. However, the changed Kimi Code adapter at src/api/providers/kimi-code.ts:46-49 is covered only by src/api/providers/__tests__/kimi-code.spec.ts:49-63, which reads the protected options field. This mirrors the assignment and does not verify the concrete request behavior: unset and false must omit max_completion_tokens, while true must include it. The UI expression keeps the existing visible behavior, so no snapshot is required.
Resolution
Add a Kimi Code request-level test using a mocked client.chat.completions.create call. Exercise includeMaxTokens as unset, false, and true with a model max-token value, then assert that the generated request omits max_completion_tokens for unset/false and includes it for true. Keep or replace the internal-options assertion with this behavioral test.
Finishing Touches
🧪 Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
Recent review details
Additional context used
Path-based instructions: 7
Treat model, provider, MCP, path, command, and tool data as untrusted.
CodeRabbit configuration file
Files:
src/api/providers/__tests__/kimi-code.spec.ts
src/api/providers/kimi-code.ts
src/api/providers/__tests__/openai.spec.ts
src/api/providers/openai.ts
For persisted settings, verify the complete schema/storage/runtime/webview round trip, shared default semantics, and focused true plus false/unset tests.
Require regression coverage at the lowest valid harness with behavior-focused assertions, including relevant negative, error, false/unset, and boundary cases.
CodeRabbit configuration file
Files:
src/api/providers/__tests__/kimi-code.spec.ts
src/api/providers/__tests__/openai.spec.ts
Check strict typing and exhaustive behavior across normal, boundary, error, cancellation, retry, and compatibility paths.
[warning] 186-186: Mutation test advisory
webview-ui/src/components/settings/providers/OpenAICompatible.tsx:186: Survived OptionalChaining mutant (replacement: apiConfiguration.includeMaxTokens). See the job summary for the complete list and resolution guidance.
packages/types/src/provider-settings/openai.ts
[warning] 22-22: Mutation test advisory
packages/types/src/provider-settings/openai.ts:22: Survived BooleanLiteral mutant (replacement: false). See the job summary for the complete list and resolution guidance.
Thanks for contributing. This comment tracks the review sequence and the next action.
Current step: Wait for required CI checks; awaiting-maintainer requires CI and automated review completion.
Review-state labels are managed by this workflow; do not edit them manually. community-approved is managed the same way — do not add or remove it manually. It signals a fresh community code approval for the current head as an advisory priority only; maintainer review is still required.
…-include-max-tokens-default
Keep the shared DEFAULT_OPEN_AI_INCLUDE_MAX_TOKENS default and adopt the
non-optional apiConfiguration access from main.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-include-max-tokens-default
Keep the provider-settings move from main and place
DEFAULT_OPEN_AI_INCLUDE_MAX_TOKENS next to the strict tool schema default
in packages/types/src/providers/openai.ts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This PR has been awaiting author changes for 14 days and will be automatically closed in 7 days. Please address the review comments or leave a comment if you need more time.
I've been running into the same issue and this fix is what I was going to propose as well. I think one case needs an additional guard. Profiles saved before #1847 can store openAiCustomModelInfo.maxTokens: -1, because the old sane defaults were spread into the profile on any field edit. With an unset includeMaxTokens, this PR now sends max_completion_tokens: -1. Fireworks rejects that with 400. Please use maxTokens && maxTokens > 0, as openrouter.ts does, and add a test for -1. After that, please re-request review from @taltas. The PR closes automatically in about 5 days.
Impact evidence: with Claude Opus 5.5 behind an OpenAI-compatible gateway, the missing limit makes the gateway use 4096 tokens. Reasoning uses the full budget and the turn ends with finish_reason: "length" and no output.
Need to tag as do-not-close to prevent the autoclose - I think this fell through the cracks because the author never re-requested review after making the changes.
@edelauna, can you reopen this PR and add do-not-close, please? I cannot reopen it because the bot closed it.
The fork branch has these updates. GitHub does not show them while the PR is closed:
I merged the latest main. There are no conflicts.
I applied the guard from @SoccerField24x7. The request now includes max_completion_tokens only when the limit is more than 0. This agrees with openrouter.ts. Thus profiles that store the old maxTokens: -1 default do not send -1.
The regression test now has -1 and 0 cases. I removed the guard as a check, and the test failed.
Latest commit: 121c69235.
@taltas, I resolved the conflict that you asked about on Oct 31. GitHub does not let me re-request your review. Can you review this PR again after it is open?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related GitHub Issue
Closes: #2230
Description
The "Include max output tokens" checkbox and the request builder use different defaults. The UI reads an unset
includeMaxTokensas checked. The request builder sendsmax_completion_tokensonly for an explicittrue. Thus a profile that does not store the value shows a ticked box and sends no limit.This PR makes the two agree:
DEFAULT_OPEN_AI_INCLUDE_MAX_TOKENS = trueinpackages/types, next toDEFAULT_OPEN_AI_STRICT_TOOL_SCHEMAS.OpenAiHandler.addMaxTokensIfNeeded()readsincludeMaxTokens ?? DEFAULT_OPEN_AI_INCLUDE_MAX_TOKENS. Only an explicitfalseopts out.OpenAiHandler.addMaxTokensIfNeeded()adds the field only when a limit exists (modelMaxTokensorinfo.maxTokens). It does not assignundefined.OpenAICompatible.tsxuses the same constant for the checkbox.KimiCodeHandlerextendsOpenAiHandlerand has no checkbox. It now passesincludeMaxTokens: options.includeMaxTokens === true. This keeps its previous behavior.Reviewers, check these points:
max_completion_tokens. This occurs only when a max output token value is set. Profiles without a value do not change.true, MiMo setsfalse, and Moonshot overridesaddMaxTokensIfNeeded(). These providers do not change.Test Procedure
pnpm --dir src exec vitest run api/providers/__tests__/openai.spec.ts api/providers/__tests__/kimi-code.spec.ts api/providers/__tests__/deepseek.spec.ts api/providers/__tests__/moonshot.spec.ts api/providers/__tests__/mimo.spec.ts: 301 passed, 1 skipped.pnpm --dir webview-ui exec vitest run src/components/settings/providers/__tests__/OpenAICompatible.spec.tsx: 22 passed. The existing test checks that the box shows checked when the value is unset.pnpm --dir src run check-typesandtsc --noEmitinwebview-ui: pass.eslint --prune-suppressions --max-warnings=0on the changedsrcfiles: pass. No suppression count changed.New tests:
openai.spec.ts: anit.eachtest for unset,true, andfalse. It checks streaming and non-streaming requests. It replaces the old test that expected no limit for an unset value.kimi-code.spec.ts: anit.eachtest that checks Kimi Code stays opt-in.Pre-Submission Checklist
Visual Snapshots
Not applicable. The UI does not change visually.
Documentation Updates
Additional Notes
A ticked box still sends no limit when no max output token value exists. This PR does not change that case. A UI hint can be a separate change.
🤖 Generated with Claude Code