Skip to content

fix(sse): refine kimi thinking handling and add unit tests - #3191

Merged
diegosouzapw merged 7 commits into
cheaper-inference:release/v3.8.11from
bypanghu:main
Jun 5, 2026
Merged

diegosouzapw merged 7 commits into
cheaper-inference:release/v3.8.11from
bypanghu:main

Conversation

@bypanghu

@bypanghu bypanghu commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Describe the user-facing or operational change.
  • fix(sse): refine kimi thinking handling and add unit tests
  • Import ExecuteInput type for future extensibility
  • Add tsconfig include path for .build/next/dev/dev/types
  • Add unit test for assistant tool call reasoning_content injection

Related Issues

  • Closes #
  • Related to #

Validation

  • npm run lint
  • npm run test:unit
  • npm run test:coverage
  • Coverage is still >= 60% for statements, lines, functions, and branches
  • SonarQube PR analysis is green or any remaining issues are explicitly documented below

Tests Added Or Updated

  • List every changed or added automated test file.
  • If no production code changed, state that here.

Coverage Notes

  • If this PR changes src/, open-sse/, electron/, or bin/, explain which tests cover the change.
  • If coverage moved down in any touched file, explain why and what follow-up task will recover it.

Reviewer Notes

  • Call out any risky areas, migrations, feature flags, or manual validation that reviewers should know about.

bypanghu added 5 commits June 4, 2026 10:07
- Remove debug file write (writeHandlerBodyToLocalFile) from transformRequest
- Import ExecuteInput type for future extensibility
- Add tsconfig include path for .build/next/dev/dev/types
- Add unit test for assistant tool call reasoning_content injection
@bypanghu
bypanghu requested a review from diegosouzapw as a code owner June 5, 2026 03:28
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

type ProviderCredentials,
} from "./base.ts";

import { ExecuteInput, type ProviderCredentials } from "./base.ts";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: Extra space in import statement between { and ExecuteInput - should be { ExecuteInput for consistent formatting

if (!hasActiveKimiThinking(kimiBody)) return kimiBody;

let modified = false;
const sourceMessages = Array.isArray(kimiBody.messages) ? kimiBody.messages : record.messages;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: The fallback record.messages on line 102 is unnecessary. By line 93, we've already verified record.messages is an array, and disableKimiPreservedThinking() only modifies the thinking field without affecting messages. Can simplify to const sourceMessages = kimiBody.messages;

type ProviderCredentials,
} from "./base.ts";

import { ExecuteInput, type ProviderCredentials } from "./base.ts";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: Extra space in import statement between { and ExecuteInput - should be { ExecuteInput for consistent formatting

if (!hasActiveKimiThinking(kimiBody)) return kimiBody;

let modified = false;
const sourceMessages = Array.isArray(kimiBody.messages) ? kimiBody.messages : record.messages;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: The fallback record.messages on line 102 is redundant. disableKimiPreservedThinking returns {...body, thinking: {...}} which preserves all existing fields including messages. Since line 93 already verified record.messages is an array, this fallback cannot be reached.

const cleanedBody = super.transformRequest(model, body, stream, credentials);
return applyKimiRequestDefaults(cleanedBody);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: Trailing whitespace on this line (before closing brace) - should be removed for clean code.

@kilo-code-bot

kilo-code-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown

Code Review Summary

Status: 3 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 2
Issue Details (click to expand)

WARNING

File Line Issue
open-sse/executors/kimi.ts 3 Extra space in import statement between { and ExecuteInput - inconsistent formatting

SUGGESTION

File Line Issue
open-sse/executors/kimi.ts 102 Redundant fallback record.messages - disableKimiPreservedThinking preserves all existing fields including messages, and line 93 already verified the array type
open-sse/executors/kimi.ts 130 Trailing whitespace before closing brace
Other Observations (not in diff)

Issues found in unchanged code that cannot receive inline comments:

File Line Issue
tests/unit/executor-kimi.test.ts 35 Test assertion expects reasoning_content: "" but code sets it to NON_ANTHROPIC_THINKING_PLACEHOLDER ("(prior reasoning summary unavailable)") when input has reasoning_content: null. This may be intentional (placeholder is required by Kimi), but worth verifying the test expectation matches the intended behavior.
Files Reviewed (3 files)
  • open-sse/executors/kimi.ts - 3 issues
  • tests/unit/executor-kimi.test.ts - 1 observation
  • tsconfig.json - no issues (additive change is correct)

type ProviderCredentials,
} from "./base.ts";

import { ExecuteInput, type ProviderCredentials } from "./base.ts";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CRITICAL: Extra space in import statement - should be { ExecuteInput for consistent formatting

if (!hasActiveKimiThinking(kimiBody)) return kimiBody;

let modified = false;
const sourceMessages = Array.isArray(kimiBody.messages) ? kimiBody.messages : record.messages;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: Redundant fallback record.messages - disableKimiPreservedThinking preserves all existing fields including messages, and line 93 already verified the array type

Comment thread tests/unit/executor-kimi.test.ts Outdated
) as { messages?: Array<Record<string, unknown>> };

assert.ok(Array.isArray(transformed.messages));
assert.equal(transformed.messages?.[1]?.reasoning_content, "");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CRITICAL: Test assertion mismatch. The code sets reasoning_content to NON_ANTHROPIC_THINKING_PLACEHOLDER ("(prior reasoning summary unavailable)") when input has reasoning_content: null, but the test expects "". The placeholder is required by Kimi (see claudeHelper.ts:10-11 - empty thinking strings cause 400 errors).

@kilo-code-bot

kilo-code-bot Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
open-sse/executors/kimi.ts 3 Extra space in import statement + unused ExecuteInput import (type-only, never used in file)
open-sse/executors/kimi.ts 102 Redundant fallback record.messages — disableKimiPreservedThinking preserves messages, fallback is unreachable
Other Observations (not in diff)

Issues found in unchanged code that cannot receive inline comments:

File Line Issue
open-sse/executors/kimi.ts 130 Trailing whitespace on this line (before closing brace)
Files Reviewed (2 files)
  • open-sse/executors/kimi.ts - 2 issues
  • tests/unit/executor-kimi.test.ts - 0 issues (previous CRITICAL finding was incorrect; test correctly expects NON_ANTHROPIC_THINKING_PLACEHOLDER which the code produces)

Reviewed by laguna-m.1-20260312:free · 1,275,854 tokens

@diegosouzapw

Copy link
Copy Markdown
Collaborator

Thanks @bypanghu — the Kimi thinking handling is genuinely tricky (the #2900 reasoning_content replay contract), so improving it is welcome. Two things to sort out before this can land:

  1. Test coverage is thin for the size of the change. This is a substantial rewrite — it drops the old reasoning_effort / reasoning.effort detection in favor of thinking-object + Claude-protocol detection, and adds disableKimiPreservedThinking, isClaudeProtocolBody, and thinking-block injection. There's only one test (the empty-reasoning_content case). Could you add coverage for: the Claude-protocol body path (thinking block injected before the first tool_use), disableKimiPreservedThinking setting keep: null, and a case asserting the dropped reasoning_effort handling is intentional (not a regression for OpenAI-style callers)?

  2. Please drop the tsconfig.json change. The added include ".build/next/dev/dev/types/**/*.ts" has a doubled dev/dev segment — it looks like a local build artifact and shouldn't ship.

Once those are addressed I'll re-review and validate. Leaving open for your update.

@bypanghu

bypanghu commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

ok, I will fix this

@bypanghu

bypanghu commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @bypanghu — the Kimi thinking handling is genuinely tricky (the #2900 reasoning_content replay contract), so improving it is welcome. Two things to sort out before this can land:

  1. Test coverage is thin for the size of the change. This is a substantial rewrite — it drops the old reasoning_effort / reasoning.effort detection in favor of thinking-object + Claude-protocol detection, and adds disableKimiPreservedThinking, isClaudeProtocolBody, and thinking-block injection. There's only one test (the empty-reasoning_content case). Could you add coverage for: the Claude-protocol body path (thinking block injected before the first tool_use), disableKimiPreservedThinking setting keep: null, and a case asserting the dropped reasoning_effort handling is intentional (not a regression for OpenAI-style callers)?
  2. Please drop the tsconfig.json change. The added include ".build/next/dev/dev/types/**/*.ts" has a doubled dev/dev segment — it looks like a local build artifact and shouldn't ship.

Once those are addressed I'll re-review and validate. Leaving open for your update.

1:There are often errors in calling kimi in claude, because kimi only adapts to the openai protocol, and there are resoning_content in it, but claude does not have this.
the error is :[400]: thinking is enabled but reasoning_content is missing in assistant tool call message at index 285
2: I have fix it

@diegosouzapw
diegosouzapw changed the base branch from main to release/v3.8.11 June 5, 2026 11:54
@diegosouzapw

Copy link
Copy Markdown
Collaborator

Thanks @bypanghu! 🙏 The refined Kimi thinking handling (reasoning_content injection for assistant tool-call turns, with the new thinking/tool_use block helpers) looks solid and the unit tests (4/4) pass. I restored the trailing newline on tsconfig.json (prettier) — typecheck:core is green. Merging into release/v3.8.11. 🚀

@diegosouzapw
diegosouzapw merged commit dfcaeba into cheaper-inference:release/v3.8.11 Jun 5, 2026
2 checks passed
type ProviderCredentials,
} from "./base.ts";

import { ExecuteInput, type ProviderCredentials } from "./base.ts";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: Extra space in import statement between { and ExecuteInput. Additionally, ExecuteInput is imported but never used in this file — KimiExecutor does not override execute() and transformRequest doesn't use this type.

if (!hasActiveKimiThinking(kimiBody)) return kimiBody;

let modified = false;
const sourceMessages = Array.isArray(kimiBody.messages) ? kimiBody.messages : record.messages;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: Redundant fallback record.messages — disableKimiPreservedThinking returns {...body, thinking: {...}} preserving all existing fields including messages. Since line 93 already verified record.messages is an array, this fallback cannot be reached.

diegosouzapw added a commit that referenced this pull request Jun 5, 2026
…s + add contributor hall

Consolidate the split [Unreleased]/[3.8.11] sections into one, add entries for
every merged contributor PR that was missing credit (#3170/#3171/#3172 @pizzav-xyz,
#3185/#3195 @zhiru, #3188 @xz-dev, #3189/#3203/#3204/#3241 @wilsonicdev, #3191 @bypanghu,
#3206 @juandisay, #3217 @oyi77, #3226 @miracuves, #3187/#3200 maintainer), drop stale
v3.8.8 leftovers (#2958/#2959 already shipped) and 3 empty v3.8.10 stub headers.
@diegosouzapw diegosouzapw mentioned this pull request Jun 5, 2026
HouMinXi pushed a commit to HouMinXi/OmniRoute that referenced this pull request Aug 2, 2026
…nference#3191)

Refine Kimi thinking handling (reasoning_content for tool-call turns) + tests. Integrated into release/v3.8.11.
Poid-ZA pushed a commit to Poid-ZA/OmniRoute that referenced this pull request Aug 5, 2026
…nference#3191)

Refine Kimi thinking handling (reasoning_content for tool-call turns) + tests. Integrated into release/v3.8.11.
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
…nference#3191)

Refine Kimi thinking handling (reasoning_content for tool-call turns) + tests. Integrated into release/v3.8.11.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants