Skip to content

fix(client): keep config-derived draft thinking effort after sending - #5191

Merged
liruifengv merged 1 commit into
release/2026-11-20-2from
chengluyu-fix-draft-thinking-max
Nov 20, 2026
Merged

liruifengv merged 1 commit into
release/2026-11-20-2from
chengluyu-fix-draft-thinking-max

Conversation

@chengluyu

Copy link
Copy Markdown
Collaborator

Requirement or Bug

#5170 修复了在草稿里手动选择思考强度后,发送时被改回模型默认值的问题,但只覆盖了 draftThinkingExplicit=true 的情况。当草稿显示的 effort 来自全局思考配置(例如全局配置为 max),用户没有在草稿里重新点选时,发送后仍会被改回模型默认值(例如订阅模型 k3 的默认 high)。这个 PR 修复该情况,目标是 hotfix 进 release/2026-11-20-2。

Bug Reproduction Steps

  1. 全局思考配置设为 max,默认模型选一个 supportEfforts=[low, high, max]、defaultEffort=high 的模型。
  2. 新建草稿,草稿界面显示 Max(来自全局配置,不重新点选)。
  3. 发送首条消息。
  4. 会话记录里先是 profile.bind = max,随后出现 config.update = high,真实 LLM 请求 thinkingEffort=high。

默认 effort 本来就是 max 的模型不会复现,因为重置后的值恰好也是 Max。

Root Cause

KAP 的 Session 返回体没有 model 字段,toAppSession 会把新会话的 model 设成 ''。发送首条消息前,settleSessionSettings 拿 '' 和可发送模型比较,误判为切换模型,调用 setSessionModel;thinkingLevelForModelSwitch 在切换时会丢弃当前 effort,改用模型默认值,并把 { model, thinking: 'high' } 写回会话。

sequenceDiagram
    participant Client
    participant Server
    Client->>Server: createSession(model=k3),不带 thinking
    Server-->>Client: Session(无 model 字段 → model '')
    Note over Server: profile.bind = max(来自全局配置)
    Client->>Client: settleSessionSettings:'' ≠ k3,判定为切换
    Client->>Server: profile { model: k3, thinking: high }
    Note over Server: config.update = high
Loading

#5170 只在 explicit 分支里改用 normalizeDraftSessionModel 保留 effort,非 explicit 分支仍走旧的 setSessionModel。这是根本修复:新会话的模型从一开始就是已知的(就是创建时传的 draftPick),所以不应把它当作切换。

Code Changes

createDraftSession 把新会话写进 store 前,如果服务端返回的 model 为空,就用创建时传入的 draftPick 填上:

 createDraftSession
   createSessionInWorkspace(ws, draftPick)
-  upsertSessionSorted(session)
+  upsertSessionSorted(session.model === '' && draftPick !== undefined
+    ? { ...session, model: draftPick }
+    : session)

这样 settleSessionSettings 看到的当前模型等于可发送模型,不会再触发 setSessionModel,服务端按全局配置绑定的 effort 得以保留。#5170 的 explicit 分支逻辑不变(它比较的是服务端原始返回值,仍会调用 normalizeDraftSessionModel 并保留草稿 effort)。

Behavior Changes and Affected Users

行为 之前 之后 谁依赖旧行为 退路
草稿 effort 来自全局配置、且与模型默认不同时,发送首条消息后的 effort 被改回模型默认值 保持全局配置的值 无(旧行为是 bug) 不需要
新会话创建后、agent 状态到达前 store 里的 session.model '' 创建时传入的模型 无;agent 状态到达后仍以服务端为准 不需要
新会话首次发送时,是否会额外写一次 profile { model, thinking } 非 explicit 时会写 不再写 无;模型就是创建时传的那个,服务端已绑定 不需要

受影响模块:packages/app-client(desktop 与 web 共用)。测试:startSessionAndActivateSkill.test.ts 新增用例,覆盖非 explicit 草稿、服务端返回空 model 的情况,断言不调用 setSessionModel、不写 thinking;去掉修复时该用例失败。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • 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 Nov 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 695ba86

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

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/kimi-code Patch
kimi-code-app 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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T08:51:15.758634Z 695ba86 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Nov 20, 2026

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

commit: 695ba86

@liruifengv
liruifengv merged commit 7baee3c into release/2026-11-20-2 Nov 20, 2026
18 checks passed
@liruifengv
liruifengv deleted the chengluyu-fix-draft-thinking-max branch November 20, 2026 08:53
@github-actions github-actions Bot mentioned this pull request Nov 20, 2026
Grapedge added a commit that referenced this pull request Nov 23, 2026
* fix(core): add Claude 5 output token ceilings (#5096)

* fix(core): add Claude 5 output token ceilings

* chore: add Claude 5 output ceiling changeset

* fix(markdown): keep table actions inside clipped containers (#5098)

* fix(markdown): keep table actions inside clipped containers

* fix(markdown): observe table action clipping ancestors

---------

Co-authored-by: kimi-agent-bot <[email protected]>

* fix(hosts): keep project lists usable with SSH hosts (#5102)

* ci: release packages (#5094)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix: preserve first prompt through project creation (#5161)

Co-authored-by: kimi-agent-bot <[email protected]>

* fix(agent-core-v2): align fork slicing with restored turn ids (#5165)

* fix(agent-core-v2): align fork slicing with restored turn ids

* chore: add restored fork fix changeset

* fix(core): prevent AJV diagnostics from polluting TUI input (#5168)

* refactor(core): route AJV logs through utils logger

* chore(core): add AJV logger changeset

* chore(core): clarify AJV logger changeset

* fix: support UUID generation in insecure browser contexts (#5173)

* fix: support UUID generation in insecure browser contexts

* chore: update pnpm deps hash

* fix: resolve crypto bindings in UUID lint rule

---------

Co-authored-by: kimi-agent-bot <[email protected]>

* fix(client): keep draft thinking effort after sending (#5170)

* fix(client): keep draft thinking effort after sending

* chore: add cli changeset for draft thinking fix

* test(client): use function stub for websocket in thinking test

* fix(client): preserve thinking effort during model normalization

* fix(client): reconcile profile updates and model fallbacks

* fix(client): scope draft thinking preservation

* fix(tui): defer queued prompts until the loop drains (#5166)

* fix(tui): defer queued prompts until the loop drains

- add core and v2 drained/idle lifecycle events
- consume reminder-only queues without starting a model turn
- gate TUI queue dispatch and completion notifications on lifecycle state
- document notification-handoff queue behavior and add a CLI patch changeset

* fix(tui): close loop lifecycle races

- emit idle only after the current macro is revalidated
- keep queued input pending through compaction and delayed dispatch
- reject stale idle after new work starts

* fix(loop): correlate lifecycle events by generation

- track macro generations in the core and v2 loop state
- replace TUI macro inference with event-generation correlation
- preserve compaction guards for queued dispatch

* fix(desktop): simplify multi-select folder picker actions (#5174)

* fix(kap-server): report :wait settled only after the session is on disk (#5176)

:wait settled as soon as the turn left the in-memory activity view, but
the engine writes wire records through a batched log that flushes in a
later task. A server killed right after :wait reported idle could lose
the end of the finished turn.

Before it replies with a settled session, :wait now flushes the wire of
every agent in the session and drains pending metadata writes. A failed
write surfaces as an error instead of a settled reply. The KAP guide
states the guarantee. A new test in sessions.test.ts slows down the disk
write of the turn end and checks that the record is on disk when :wait
returns.

(cherry picked from commit fc33c6d)

Co-authored-by: kai <[email protected]>

* ci: release packages (#5163)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix(client): keep config-derived draft thinking effort after sending (#5191)

Co-authored-by: liruifengv <[email protected]>

* ci: release packages (#5192)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix(kap-server): resume sessions with unavailable models (#5212)

* fix(kap-server): resume sessions with unavailable models

* fix: let users replace unavailable session models

* fix: scope unavailable model recovery state

---------

Co-authored-by: kimi-agent-bot <[email protected]>

* fix(plugins): detect MCP OAuth with targeted probes (#5197)

* fix(plugins): detect MCP OAuth with targeted probes

* fix(plugins): use the MCP inspect route

* fix(plugins): preserve OAuth requirements across inspection and disconnect

* fix(chat): show pending MCP browser authorization (#5246)

* fix(chat): show pending MCP browser authorization

* fix(chat): resolve MCP authorization lint findings

* fix(chat): preserve MCP authorization failure details

* fix(mcp): preserve cancellation during OAuth reconnect

* fix(desktop): cache feedback form per host and let reply reasons wrap (#5303)

* ci: release packages (#5232)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* test: port removed-model recovery coverage to testkit

* test: dedupe anthropic output ceiling cases

---------

Co-authored-by: Haozhe <[email protected]>
Co-authored-by: kimi-agent-bot <[email protected]>
Co-authored-by: 7Sageer <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: kimi-agent-bot <[email protected]>
Co-authored-by: liruifengv <[email protected]>
Co-authored-by: qer <[email protected]>
Co-authored-by: kai <[email protected]>
Co-authored-by: Luyu Cheng <[email protected]>
Co-authored-by: grapedge <[email protected]>
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