Skip to content

fix(reasoning): auto-select kimi_k25 for Kimi-K2.6/K2.7 - #1917

Open
key4ng wants to merge 1 commit into
mainfrom
fix/kimi-k2-reasoning-automap
Open

fix(reasoning): auto-select kimi_k25 for Kimi-K2.6/K2.7#1917
key4ng wants to merge 1 commit into
mainfrom
fix/kimi-k2-reasoning-automap

Conversation

@key4ng

@key4ng key4ng commented Jul 14, 2026

Copy link
Copy Markdown
Member

Description

Problem

Kimi-K2.6 and Kimi-K2.7 have no reasoning-parser auto-select pattern. Reasoning-parser auto-selection matches the model id against registered patterns with a first-match substring check, so these SKUs fell through to the generic kimi entry — the legacy Kimi-K2-Instruct parser that expects unicode ◁think▷ / ◁/think▷ delimiters.

K2.6/K2.7 actually use <think> / </think> (the same chat-template family as K2.5, with <think> prefilled into the generation prompt when thinking is on). So for any deployment relying on --reasoning-parser auto-detection, K2.6/K2.7 reasoning was mis-split into content.

Solution

Add explicit kimi-k2.6 / kimi-k2.7kimi_k25 patterns, matching the existing kimi-k2.5 mapping (all three share the same template). The .-versioned patterns do not match kimi-k2-instruct, which stays on the legacy unicode parser; kimi-k2-thinking continues to map to kimi_thinking.

Note: this only affects name-based auto-selection. Deployments that pass --reasoning-parser explicitly (e.g. the nightly A/B) are unaffected.

Changes

  • crates/reasoning_parser/src/factory.rs: register kimi-k2.6 and kimi-k2.7kimi_k25.
  • Add test_kimi_k2_family_automap locking the full K2 family mapping.

Test Plan

factory.create(model).model_type() for the auto-select path:

model id before after
moonshotai/Kimi-K2.5 kimi_k25 kimi_k25
moonshotai/Kimi-K2.6 kimi (legacy ◁think▷) kimi_k25
moonshotai/Kimi-K2.7-Code kimi (legacy ◁think▷) kimi_k25
moonshotai/Kimi-K2-Thinking kimi_thinking kimi_thinking
moonshotai/Kimi-K2-Instruct kimi kimi
cargo test -p reasoning-parser --lib factory::tests::test_kimi_k2_family_automap
# test result: ok. 1 passed
Checklist
  • cargo +nightly fmt passes
  • cargo clippy --all-targets --all-features -- -D warnings passes
  • (Optional) Documentation updated
  • (Optional) Please join us on Slack #sig-smg to discuss, review, and merge PRs

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved automatic recognition and routing for the Kimi K2 model family, including K2.6 and K2.7-Code.
    • Enhanced model-pattern handling so Kimi K2.5, K2.6, K2.7-Code, K2-Thinking, and legacy Kimi K2 variants resolve to the correct reasoning parser behavior.

@key4ng
key4ng requested a review from CatherineSue as a code owner July 14, 2026 04:10
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 79d4552b-a88f-4449-87d6-66c223ba7a15

📥 Commits

Reviewing files that changed from the base of the PR and between 41860aa and 60136fd.

📒 Files selected for processing (1)
  • crates/reasoning_parser/src/factory.rs

📝 Walkthrough

Walkthrough

The parser factory maps kimi-k2.6 and kimi-k2.7 variants to the kimi_k25 reasoning parser. A new test verifies routing across Kimi-K2.5, K2.6, K2.7-Code, K2-Thinking, and legacy Kimi-K2-Instruct identifiers.

Changes

Kimi-K2 parser automapping

Layer / File(s) Summary
Factory mapping and validation
crates/reasoning_parser/src/factory.rs
Registers kimi-k2.6 and kimi-k2.7 with the kimi_k25 parser and tests automapping for multiple Kimi-K2 family identifiers.

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

Possibly related PRs

Suggested reviewers: catherinesue

Poem

I hop through Kimi’s model lane,
K2.6 and K2.7 join the train.
Tests check each route where Kimi goes,
Think tags bloom in tidy rows.
Squeak—mapped clean, the burrow glows!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: routing Kimi-K2.6/K2.7 models to the existing kimi_k25 parser.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/kimi-k2-reasoning-automap

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

@github-actions github-actions Bot added the reasoning-parser Reasoning parser changes label Jul 14, 2026

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request adds pattern registration for kimi-k2.6 and kimi-k2.7 to reuse the kimi_k25 reasoning format, along with a comprehensive test suite for the Kimi K2 family automapping. The reviewer suggested a great improvement to simplify the registration by using a single pattern "kimi-k2." to match all current and future Kimi K2.x models (K2.5+) using substring matching.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines 196 to +198
registry.register_pattern("kimi-k2.5", "kimi_k25");
registry.register_pattern("kimi-k2.6", "kimi_k25"); // K2.6/K2.7 share the K2.5 <think> template
registry.register_pattern("kimi-k2.7", "kimi_k25");

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.

medium

Instead of registering individual patterns for each minor version of the Kimi K2 family (e.g., kimi-k2.5, kimi-k2.6, kimi-k2.7), we can register a single pattern kimi-k2. to match all current and future Kimi K2.x models. Since the matching logic uses substring matching (contains), this single pattern will correctly match Kimi-K2.5, Kimi-K2.6, Kimi-K2.7, and any future versions (like Kimi-K2.8), while avoiding matching kimi-k2-thinking or kimi-k2-instruct which do not contain a dot after k2.

Suggested change
registry.register_pattern("kimi-k2.5", "kimi_k25");
registry.register_pattern("kimi-k2.6", "kimi_k25"); // K2.6/K2.7 share the K2.5 <think> template
registry.register_pattern("kimi-k2.7", "kimi_k25");
registry.register_pattern("kimi-k2.", "kimi_k25"); // Kimi K2.x models (K2.5+) share the <think> template

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good. Small, correct change — pattern ordering is right (dotted-version patterns before the catch-all kimi), and the test comprehensively locks the full K2 family mapping.

Kimi-K2.6 and K2.7 use the same chat template family as K2.5 (<think>/</think>
delimiters, <think> prefilled when thinking is on), but had no auto-select
pattern, so they fell through to the legacy unicode 'kimi' parser (◁think▷) and
mis-split reasoning. Map both to kimi_k25, matching K2.5.

The .-versioned patterns don't match kimi-k2-instruct, which stays on the legacy
unicode parser.

Signed-off-by: key4ng <rukeyang@gmail.com>
@key4ng
key4ng force-pushed the fix/kimi-k2-reasoning-automap branch from 41860aa to 60136fd Compare July 15, 2026 16:21

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 60136fd543

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

registry.register_pattern("kimi-k2-thinking", "kimi_thinking");
registry.register_pattern("kimi-k2.5", "kimi_k25");
registry.register_pattern("kimi-k2.6", "kimi_k25"); // K2.6/K2.7 share the K2.5 <think> template
registry.register_pattern("kimi-k2.7", "kimi_k25");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Map K2.7 to a prefilled-think parser

For auto-detected moonshotai/Kimi-K2.7-Code requests with separate_reasoning, this selects kimi_k25, whose parser does not start in reasoning mode; the gateway only calls mark_reasoning_started() when should_mark_reasoning_started() sees a thinking toggle (ThinkingToggle::None => false), but the K2.7-Code template pre-fills <think> unconditionally and has no toggle (HF template). The generated text therefore starts after the prefilled token, e.g. reasoning</think>answer, and BaseReasoningParser treats it as normal text unless it was already marked or sees <think> in the output, so reasoning still leaks into content despite this new auto-map.

Useful? React with 👍 / 👎.

@mergify

mergify Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Hi @key4ng, this PR has merge conflicts that must be resolved before it can be merged. Please rebase your branch:

git fetch origin main
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

@mergify mergify Bot added the needs-rebase PR has merge conflicts that need to be resolved label Jul 16, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Jul 27, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-rebase PR has merge conflicts that need to be resolved reasoning-parser Reasoning parser changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants