Skip to content

fix(kosong): restore Kimi preserved-thinking sessions - #1684

Merged
RealKai42 merged 3 commits into
mainfrom
kaiyi/investigate-empty-thinking-error
Jul 14, 2026
Merged

fix(kosong): restore Kimi preserved-thinking sessions#1684
RealKai42 merged 3 commits into
mainfrom
kaiyi/investigate-empty-thinking-error

Conversation

@RealKai42

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue. The problem was reproduced from exported sessions that could no longer continue after an empty reasoning step.

Problem

Kimi preserved thinking requires reasoning_content on historical assistant messages. Older sessions can contain assistant messages without a ThinkPart because an explicitly empty reasoning step was previously dropped. With thinking.keep set to all, replaying that history repeatedly fails the request instead of allowing the session to continue.

What changed

  • At Kimi request serialization only, backfill reasoning_content: "" for assistant history that lacks a ThinkPart when thinking.keep is all and thinking is not disabled.
  • Preserve existing empty and non-empty reasoning verbatim, and leave inactive keep modes and non-assistant messages unchanged.
  • Keep canonical history untouched so other providers never receive synthesized thinking.
  • Mirror the behavior in the v1 and v2 provider paths, including coverage for legacy tool-call and text history, existing reasoning, inactive modes, disabled thinking, and provider-role boundaries.

Validation

  • pnpm exec vitest run packages/kosong/test — 49 files, 1220 tests passed.
  • pnpm --filter @moonshot-ai/agent-core-v2 test — 237 files, 3361 tests passed.
  • Type checks passed for @moonshot-ai/kosong and @moonshot-ai/agent-core-v2.
  • pnpm --filter @moonshot-ai/agent-core-v2 run lint:domain passed for 855 files.
  • Type-aware lint passed for all changed TypeScript files.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1043041

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@RealKai42
RealKai42 marked this pull request as ready for review July 14, 2026 08:06
@pkg-pr-new

pkg-pr-new Bot commented Jul 14, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@1043041
npx https://pkg.pr.new/@moonshot-ai/kimi-code@1043041

commit: 1043041

@RealKai42
RealKai42 merged commit e417ee7 into main Jul 14, 2026
16 checks passed
@RealKai42
RealKai42 deleted the kaiyi/investigate-empty-thinking-error branch July 14, 2026 08:17
@github-actions github-actions Bot mentioned this pull request Jul 14, 2026
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.

1 participant