Skip to content

fix: resolve and synchronize thinking effort - #1625

Merged
sailist merged 9 commits into
mainfrom
fix-reasoning-effort
Jul 14, 2026
Merged

fix: resolve and synchronize thinking effort#1625
sailist merged 9 commits into
mainfrom
fix-reasoning-effort

Conversation

@RealKai42

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue. This PR fixes inconsistent thinking-effort handling when model capabilities differ or when a provider accepts values that Kimi models do not advertise.

Problem

Thinking effort was partially interpreted at the provider boundary. For Kimi models, an effort outside support_efforts could be silently omitted from the request while the core state and UI still retained the stale requested value. This was especially visible after switching from a model that supports values such as ultra to a model that supports only low, medium, and high.

At the same time, provider-side allow-list filtering could rewrite or drop concrete effort values for non-Kimi providers before the upstream API had a chance to validate them.

What changed

  • Resolve the effective thinking effort in agent-core v1 and v2 from the target model's Kimi capability metadata.
  • Preserve supported Kimi effort values.
  • Fall back inherited or configured unsupported Kimi efforts to the target model's resolved default.
  • Map enabled thinking to on for Kimi models that support thinking but do not expose an effort list.
  • Reject an explicitly selected unsupported Kimi effort with a model configuration error instead of silently dropping it.
  • Preserve concrete non-Kimi effort values and leave validation to the upstream provider.
  • Record, replay, emit, and display the effective effort so core state, status events, and the TUI remain synchronized.
  • Remove provider-boundary supportEfforts filtering while preserving the Kimi Anthropic request shape.
  • Document the fallback semantics in the English and Chinese configuration references.
  • Add a patch changeset for @moonshot-ai/kimi-code.

Checklist

  • I have read CONTRIBUTING.md.
  • I have linked the related issue or explained the problem above.
  • I have added or updated tests for the change.
  • I have run the gen-changesets workflow and added the required changeset.
  • I have run the gen-docs workflow and updated the affected user documentation.

Validation

  • pnpm --filter @moonshot-ai/agent-core-v2 test (236 files, 3199 tests)
  • pnpm --filter @moonshot-ai/agent-core test (3762 passed; existing expected failures/skips unchanged)
  • pnpm --filter @moonshot-ai/kosong test (49 files, 1191 tests)
  • pnpm --filter @moonshot-ai/kimi-code test -- test/tui/kimi-tui-message-flow.test.ts (144 tests)
  • Type checks for agent-core, agent-core-v2, kosong, protocol, and kimi-code
  • pnpm --filter @moonshot-ai/agent-core-v2 lint:domain (842 files)

@changeset-bot

changeset-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6b092b8

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 13, 2026 13:56
@pkg-pr-new

pkg-pr-new Bot commented Jul 13, 2026

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

commit: 6b092b8

@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: 495d07db56

ℹ️ 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".

Comment thread packages/agent-core-v2/src/agent/profile/profileService.ts

@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: ab12dc435e

ℹ️ 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".

Comment thread packages/agent-core-v2/src/app/model/modelResolverService.ts Outdated

@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: 02bbcbb17c

ℹ️ 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".

Comment thread packages/agent-core/src/agent/config/index.ts Outdated

@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: 58d5197b73

ℹ️ 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".

Comment thread packages/agent-core-v2/src/agent/profile/profileService.ts

@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: 5f4ad40473

ℹ️ 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".

Comment thread packages/agent-core-v2/src/app/sessionLegacy/sessionLegacyService.ts Outdated

@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: 6ce4b2cf2f

ℹ️ 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".

Comment on lines 75 to +77
this.agent.records.logRecord({
type: 'config.update',
...changed,
...effectiveChanged,

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 Keep env-forced Kimi effort out of replay records

When KIMI_MODEL_THINKING_EFFORT is set, effectiveChanged contains the forced provider value, and this record path now persists that value as config.update. Live state still keeps _unforcedThinkingEffort as the user's base value, but after resume records.replay feeds the persisted record back through agent.config.update(input), so the forced value becomes the new unforced value; switching from a Kimi model to a non-Kimi model after resume can therefore carry max/the env override into the non-Kimi provider. The fresh issue here is that the forced value is now written to replay records, not just reflected in status.

Useful? React with 👍 / 👎.

if (persist) {
try {
persisted = await persistModelSelection(host, alias, effort);
persisted = await persistModelSelection(host, effectiveAlias, effectiveEffort);

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 Persist the selected effort, not env-forced status

In an active session with KIMI_MODEL_THINKING_EFFORT set, session.getStatus() returns the provider-effective effort, including the env-only forced value. Passing effectiveEffort into persistModelSelection makes /model save that env override into config.toml when the user chooses to persist the selection, so a temporary shell override such as max becomes the permanent default even if the user selected a different supported effort. Keep using the effective value for display/state, but persist the selected/base effort with Kimi fallback applied before env forcing.

Useful? React with 👍 / 👎.

# Conflicts:
#	packages/agent-core-v2/src/agent/profile/profile.ts
#	packages/agent-core-v2/src/app/llmProtocol/providers/anthropic.ts
#	packages/agent-core-v2/src/app/llmProtocol/providers/openai-common.ts
#	packages/agent-core-v2/src/app/model/modelInstance.ts
#	packages/agent-core-v2/src/app/model/modelResolverService.ts
#	packages/agent-core-v2/src/app/model/thinking.ts
#	packages/agent-core-v2/test/agent/fullCompaction/fullCompaction.test.ts
#	packages/agent-core-v2/test/agent/profile/thinking.test.ts
#	packages/agent-core-v2/test/app/config/config.test.ts
@sailist
sailist merged commit d158e0a into main Jul 14, 2026
14 checks passed
@sailist
sailist deleted the fix-reasoning-effort branch July 14, 2026 08:37
@github-actions github-actions Bot mentioned this pull request Jul 14, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Jul 15, 2026
* fix: preserve provider thinking effort values

* fix: resolve Kimi thinking effort fallbacks

* fix: use resolved Kimi effort in v2 requests

* fix: align Kimi effort resolution paths

* fix: synchronize forced Kimi effort state

* fix: synchronize forced Kimi effort in v2 state

* fix: tolerate unresolved models in v2 status
7723qqq added a commit to 7723qqq/kimi-code that referenced this pull request Jul 15, 2026
…oonshotAI#1676 MoonshotAI#1625 MoonshotAI#1746 MoonshotAI#1753 MoonshotAI#1757)

Critical fixes cherry-picked from upstream v0.24.x:
- fix(agent-core-v2): align rate-limit retries with v1 (MoonshotAI#1598)
- fix: preserve empty reasoning across providers (MoonshotAI#1676)
- fix: resolve and synchronize thinking effort (MoonshotAI#1625)
- fix: align Anthropic-compatible model capabilities (MoonshotAI#1746)
- fix(kap-server): close auth bypass via percent-encoded API paths (MoonshotAI#1753)
- fix: preserve the crash error in diagnostic logs on unexpected exit (MoonshotAI#1757)
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