Skip to content

[Fix] Send max output tokens when the OpenAI Compatible checkbox shows ticked - #2231

Open
scriptxyz wants to merge 3 commits into
Zoo-Code-Org:mainfrom
scriptxyz:fix/openai-compatible-include-max-tokens-default
Open

scriptxyz wants to merge 3 commits into
Zoo-Code-Org:mainfrom
scriptxyz:fix/openai-compatible-include-max-tokens-default

Conversation

@scriptxyz

Copy link
Copy Markdown

Related GitHub Issue

Closes: #2230

Description

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.

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-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).
  • Contribution Guidelines: I read and agree to the Contributor Guidelines.

Visual Snapshots

Not applicable. The UI does not change visually.

Documentation Updates

  • No documentation updates are required.

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

…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>
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

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.

Run configuration

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.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 0e208c4 and 53fa6de.

Files selected for processing: 8
  • packages/types/src/provider-settings.ts
  • packages/types/src/provider-settings/index.ts
  • packages/types/src/provider-settings/openai.ts
  • src/api/providers/__tests__/kimi-code.spec.ts
  • src/api/providers/__tests__/openai.spec.ts
  • src/api/providers/kimi-code.ts
  • src/api/providers/openai.ts
  • webview-ui/src/components/settings/providers/OpenAICompatible.tsx

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.

CodeRabbit configuration file

Files:

  • webview-ui/src/components/settings/providers/OpenAICompatible.tsx
  • packages/types/src/provider-settings/index.ts
  • packages/types/src/provider-settings.ts
  • packages/types/src/provider-settings/openai.ts
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.

CodeRabbit configuration file

Files:

  • webview-ui/src/components/settings/providers/OpenAICompatible.tsx
  • src/api/providers/__tests__/kimi-code.spec.ts
  • packages/types/src/provider-settings/index.ts
  • src/api/providers/kimi-code.ts
  • packages/types/src/provider-settings.ts
  • src/api/providers/__tests__/openai.spec.ts
  • packages/types/src/provider-settings/openai.ts
  • src/api/providers/openai.ts
Check React state and effect dependencies, cleanup, accessibility, i18n, and light/dark theme behavior.

CodeRabbit configuration file

Files:

  • webview-ui/src/components/settings/providers/OpenAICompatible.tsx
Verify extension/webview contracts, cancellation and error propagation, VS Code lifecycle correctness, and behavior under retries and partial failure.

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
Act as an adversarial second-opinion reviewer.

CodeRabbit configuration file

Files:

  • webview-ui/src/components/settings/providers/OpenAICompatible.tsx
  • src/api/providers/__tests__/kimi-code.spec.ts
  • packages/types/src/provider-settings/index.ts
  • src/api/providers/kimi-code.ts
  • packages/types/src/provider-settings.ts
  • src/api/providers/__tests__/openai.spec.ts
  • packages/types/src/provider-settings/openai.ts
  • src/api/providers/openai.ts
Learnings: 2
Learning: 2026-10-20T22:54:54.079Z
Learnt from: CR
Repo: Zoo-Code-Org/Zoo-Code PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-10-20T22:54:54.079Z
Learning: Source excerpt:
# AGENTS.md

## Shared Test Utilities

- Use `src/test-utils/stream.ts` for mechanical async-stream setup and collection.

Applied to files:

  • src/api/providers/__tests__/openai.spec.ts
Learning: 2026-10-20T22:54:54.079Z
Learnt from: CR
Repo: Zoo-Code-Org/Zoo-Code PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-10-20T22:54:54.079Z
Learning: Source excerpt:
# AGENTS.md

## Persisted Setting Checklist

- [ ] Define the setting, validation, and optionality in `packages/types/src/global-settings.ts` (or the appropriate provider/settings schema). Define a shared default constant when multiple readers need the same default.

Applied to files:

  • packages/types/src/provider-settings/openai.ts
GitHub Check: mutation-diff
webview-ui/src/components/settings/providers/OpenAICompatible.tsx

[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.

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.

Changes: OpenAI max-token inclusion

Layer / File(s) Summary
Shared setting default
packages/types/src/provider-settings/openai.ts, packages/types/src/provider-settings/index.ts, packages/types/src/provider-settings.ts, webview-ui/src/components/settings/providers/OpenAICompatible.tsx
The exported default is true. The settings checkbox uses this constant when includeMaxTokens is unset.
Provider request handling
src/api/providers/openai.ts, src/api/providers/kimi-code.ts, src/api/providers/__tests__/openai.spec.ts, src/api/providers/__tests__/kimi-code.spec.ts
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.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · previous review 53fa6

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: Passed 7 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Regression Evidence Warning 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 Passed checks: 7 passed
Check name Status Explanation
Title check Passed The title clearly states the main fix: sending max output tokens when the OpenAI Compatible checkbox is checked.
Description check Passed 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 Passed 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 Passed 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 Passed 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 Passed 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 Passed 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.

Share

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review status

Thanks for contributing. This comment tracks the review sequence and the next action.

Current step: Address maintainer or CODEOWNER feedback, push an update, then re-request review from the blocking maintainer.

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.

@codecov

codecov Bot commented Oct 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions github-actions Bot added coderabbit-review-active Required CI passed; CodeRabbit review is active awaiting-coderabbit Waiting for CodeRabbit to approve the latest commit labels Oct 29, 2026
coderabbitai[bot]
coderabbitai Bot previously approved these changes Oct 29, 2026
@github-actions github-actions Bot added awaiting-maintainer CodeRabbit approved; waiting for a human maintainer and removed coderabbit-review-active Required CI passed; CodeRabbit review is active awaiting-coderabbit Waiting for CodeRabbit to approve the latest commit labels Oct 29, 2026
@github-actions github-actions Bot added community-approved Fresh community approval on the current head; maintainer review still required has-conflicts PR has merge conflicts with the base branch awaiting-author PR is waiting for the author to address requested changes and removed awaiting-maintainer CodeRabbit approved; waiting for a human maintainer community-approved Fresh community approval on the current head; maintainer review still required labels Oct 29, 2026
…-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>
@github-actions github-actions Bot added awaiting-author PR is waiting for the author to address requested changes has-conflicts PR has merge conflicts with the base branch and removed has-conflicts PR has merge conflicts with the base branch awaiting-author PR is waiting for the author to address requested changes labels Oct 31, 2026
…-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>
@github-actions github-actions Bot added awaiting-author PR is waiting for the author to address requested changes and removed has-conflicts PR has merge conflicts with the base branch awaiting-author PR is waiting for the author to address requested changes labels Nov 1, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-author PR is waiting for the author to address requested changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] OpenAI Compatible does not send max output tokens when the checkbox shows ticked

3 participants