fix(kimi-code): correct maxTokens defaults and add server-side override - #1216
fix(kimi-code): correct maxTokens defaults and add server-side override#1216myk1yt wants to merge 33 commits into
Conversation
# Conflicts: # src/core/tools/error-interception/StructuralValidator.ts
# Conflicts: # src/core/assistant-message/__tests__/NativeToolCallParser.spec.ts # src/core/assistant-message/__tests__/presentAssistantMessage-parser-dedup.integration.spec.ts # src/core/assistant-message/presentAssistantMessage.ts
# Conflicts: # src/core/assistant-message/__tests__/presentAssistantMessage-parser-dedup.integration.spec.ts
…ception refs from backup
MimoHandler was passing raw tool schemas to the API without the strict mode conversion that all other OpenAI-compatible providers use. This caused tool call errors due to missing required/strict fields. - Call this.convertToolsForOpenAI(tools) instead of raw assignment - Adds strict: true, required properties, additionalProperties: false
An id-less argument-continuation chunk belongs to the most recent id chunk seen at its index. When a provider reuses index 0 with a NEW id (a disguised second parallel call), the new call's id chunk was dropped but its id-less argument fragments were still kept and concatenated into the FIRST call's accumulator, corrupting its JSON. Track dropped indexes in filterToFirstToolCall state and drop subsequent id-less fragments for those indexes. Also rewrite the function docblock, which referenced a non-existent error-interception retry loop.
The parseErrors/parseFailures docblocks claimed presentAssistantMessage routes recorded failures to an INVALID_JSON_ARGUMENTS error-interception pattern. No such routing exists on this codebase; describe the actual lifecycle (consumed via the consume* APIs, cleared on new API request). Comment-only change, no behavior difference.
parseErrors/parseFailures static maps accumulated an entry per malformed tool call and were never cleared in production (the consume* APIs have no production callers), slowly leaking for the extension-host lifetime. Add NativeToolCallParser.clearParseFailures() and call it in Task.recursivelyMakeClineRequests alongside clearAllStreamingToolCalls()/ clearRawChunkState(), where other per-stream state is reset. The consume* APIs keep working for tests.
MiMo sends tools through convertToolsForOpenAI(), which attaches a strict flag to every function tool. An OpenAI-compatible endpoint that doesn't support structured outputs rejects the request with a 400 and the turn fails outright. Mirror the existing parallel_tool_calls fallback: detect schema-rejection errors narrowly (400 status plus a mention of strict/additionalProperties in a tools context, so unrelated 400s like MiMo's missing-reasoning_content rejection are not retried) and retry once with the original schemas and no strict flag.
…1132) CI failure: E2E Tests (Mocked) failed with '404 No fixture matched' because provider-cost.test.ts calls startNewTask with probe tag 'provider-cost-e2e' but no fixture existed.
…stubs and custom endpoints
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
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (29)
📝 WalkthroughWalkthroughThe change adds model-aware tool-call policies, MiMo single-call handling, ghost-call quarantine, classified parser failures, metadata-only telemetry, Kimi Code token defaults, provider cost validation, and related type and configuration updates. ChangesTool-call control
Provider metadata and cost handling
Estimated code review effort: 5 (Critical) | ~120 minutes Possibly related issues
Possibly related PRs
Suggested labels: Suggested reviewers: ✨ Finishing Touches🧪 Generate unit tests (beta)
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
apps/vscode-e2e/src/suite/provider-cost.test.tsESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox. packages/telemetry/src/TelemetryService.tsESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox. packages/types/src/model.tsESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration 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. Comment Warning |
|
Closing this PR because it includes unrelated changes from the fork. Reopening a clean PR with only kimi-code changes. |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
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-k3is 131,072.Root Cause
Three issues in the codebase:
kimiCodeDefaultModelInfo.maxTokenswas hardcoded to32_768instead of131_072/modelsAPI response didn't includemax_tokensfield (silently stripped)mapKimiCodeModel()overrodecontextWindowfrom server but notmaxTokensChanges (3 files, +47/-1)
packages/types/src/providers/kimi-code.tsmaxTokensto131_072, addkimiCodeModelDefaultsfor per-model fallbacksrc/api/providers/fetchers/kimi-code.tsmax_tokensto Zod schema, override inmapKimiCodeModel()src/api/providers/fetchers/__tests__/kimi-code.spec.tsFallback Chain
This ensures automatic updates when the server provides
max_tokens, with per-model and global fallbacks.Verification
Summary by CodeRabbit
New Features
Bug Fixes
Tests