Skip to content

fix(kimi-code): correct maxTokens defaults and add server-side override - #1217

Merged
taltas merged 2 commits into
Zoo-Code-Org:mainfrom
myk1yt:fix/kimi-code-clean
Aug 10, 2026
Merged

fix(kimi-code): correct maxTokens defaults and add server-side override#1217
taltas merged 2 commits into
Zoo-Code-Org:mainfrom
myk1yt:fix/kimi-code-clean

Conversation

@myk1yt

@myk1yt myk1yt commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #1215

Kimi Code OAuth provider displayed incorrect Max Output values (32,768) for all models. According to Kimi's official documentation, the correct default for kimi-k3 is 131,072.

Root Cause

Three issues in the codebase:

  1. kimiCodeDefaultModelInfo.maxTokens was hardcoded to 32_768 instead of 131_072
  2. The Zod schema for /models API response didn't include max_tokens field (silently stripped)
  3. mapKimiCodeModel() overrode contextWindow from server but not maxTokens

Changes (3 files, +47/-1)

File Change
packages/types/src/providers/kimi-code.ts Update maxTokens to 131_072, add kimiCodeModelDefaults for per-model fallback
src/api/providers/fetchers/kimi-code.ts Add max_tokens to Zod schema, override in mapKimiCodeModel()
src/api/providers/fetchers/__tests__/kimi-code.spec.ts Add 4 tests for maxTokens override and fallback

Fallback Chain

maxTokens = server.max_tokens
         ?? kimiCodeModelDefaults[model.id].maxTokens
         ?? kimiCodeDefaultModelInfo.maxTokens (131,072)

This ensures automatic updates when the server provides max_tokens, with per-model and global fallbacks.

Verification

  • Vitest: 11/11 passed (7 existing + 4 new)
  • ESLint: clean
  • TypeScript: clean

Summary by CodeRabbit

  • New Features

    • Increased the maximum token capacity for supported Kimi Code models to 131,072 tokens.
    • Added model-specific token limits for improved handling of available models.
    • Added support for reading token limits provided by the Kimi Code service.
  • Bug Fixes

    • Kimi Code now prioritizes server-provided limits, followed by model-specific and global defaults.
    • Invalid fractional token limits are now rejected.

Fixes Zoo-Code-Org#1215

- Update kimiCodeDefaultModelInfo.maxTokens from 32768 to 131072

- Add kimiCodeModelDefaults for per-model fallback values

- Add max_tokens to kimiCodeModelSchema for server response parsing

- Override maxTokens in mapKimiCodeModel: server > model-default > global-default

- Add 4 new tests for maxTokens override and fallback behavior
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 291347cc-2bd4-4e44-bd6d-12e02b3a4960

📥 Commits

Reviewing files that changed from the base of the PR and between 568b7c9 and 4cba8fd.

📒 Files selected for processing (2)
  • src/api/providers/fetchers/__tests__/kimi-code.spec.ts
  • src/api/providers/fetchers/kimi-code.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/api/providers/fetchers/kimi-code.ts

📝 Walkthrough

Walkthrough

Kimi Code now uses 131,072-token defaults, parses optional server-provided max_tokens, and applies precedence between server values, per-model defaults, and the global fallback. Tests cover each resolution path and reject fractional values.

Changes

Kimi Code max token handling

Layer / File(s) Summary
Max token defaults and mapping
packages/types/src/providers/kimi-code.ts, src/api/providers/fetchers/kimi-code.ts, src/api/providers/fetchers/__tests__/kimi-code.spec.ts
The global Kimi Code default is 131,072 tokens. Four model IDs have per-model defaults. The response schema accepts positive integer max_tokens values. Mapping prioritizes server values, then model defaults, then the global default. Tests cover server overrides, fallback paths, and fractional-value rejection.

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

Possibly related PRs

Suggested labels: awaiting-review

Suggested reviewers: edelauna, taltas

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR fixes schema parsing, server overrides, and global defaults, but all four model fallbacks use 131,072 instead of the documented kimi-for-coding limit. Set the kimi-for-coding fallback to its documented model-specific limit, or implement an equivalent prompt-aware calculation.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the Kimi Code maxTokens fix and server-side override.
Description check ✅ Passed The description explains the issue, implementation, fallback order, affected files, and verification results, although several template sections are omitted.
Out of Scope Changes check ✅ Passed All production and test changes directly support the linked Kimi Code maxTokens issue and its validation requirements.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/api/providers/fetchers/__tests__/kimi-code.spec.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

src/api/providers/fetchers/kimi-code.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.


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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/api/providers/fetchers/__tests__/kimi-code.spec.ts`:
- Around line 1-2: Update the fallback assertions in the kimi-code tests around
the cases at lines 124-134 to use independent fixture values for the documented
model defaults, rather than kimiCodeModelDefaults or
kimiCodeDefaultModelInfo.maxTokens. Remove those production-constant imports if
they are no longer used, while preserving the existing fallback behavior checks.

In `@src/api/providers/fetchers/kimi-code.ts`:
- Line 15: Update the max_tokens schema in the Kimi Code response validation to
require positive integers by adding integer validation before the existing
positivity and optional checks. Add a rejection test covering a fractional
max_tokens value and ensure mapKimiCodeModel does not receive it as
ModelInfo.maxTokens.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 072dd6a8-85c9-4888-bf7b-29f3278580fb

📥 Commits

Reviewing files that changed from the base of the PR and between fcc507c and 568b7c9.

📒 Files selected for processing (3)
  • packages/types/src/providers/kimi-code.ts
  • src/api/providers/fetchers/__tests__/kimi-code.spec.ts
  • src/api/providers/fetchers/kimi-code.ts

Comment thread src/api/providers/fetchers/__tests__/kimi-code.spec.ts Outdated
Comment thread src/api/providers/fetchers/kimi-code.ts Outdated
@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

- Replace production constant imports in tests with hardcoded fixture values

- Add .int() validation to max_tokens Zod schema

- Add fractional max_tokens rejection test

- Export kimiCodeModelSchema for test access
@github-actions github-actions Bot added the awaiting-review PR changes are ready and waiting for maintainer re-review label Aug 10, 2026
@taltas
taltas added this pull request to the merge queue Aug 10, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 10, 2026
@taltas
taltas added this pull request to the merge queue Aug 10, 2026
Merged via the queue into Zoo-Code-Org:main with commit abaf732 Aug 10, 2026
15 checks passed
@myk1yt
myk1yt deleted the fix/kimi-code-clean branch August 10, 2026 19:12
@myk1yt

myk1yt commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

@taltas I am so sorry! I didn't know how to handle the changes in my fork, so I made a mistake. Could you please check/help again?

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

Labels

awaiting-review PR changes are ready and waiting for maintainer re-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Kimi Code OAuth shows incorrect Max Output (32K instead of 131K)

2 participants