Skip to content

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

Merged
liruifengv merged 6 commits into
release/2026-11-20from
fix/draft-thinking-profile-race-release
Nov 20, 2026
Merged

liruifengv merged 6 commits into
release/2026-11-20from
fix/draft-thinking-profile-race-release

Conversation

@liruifengv

@liruifengv liruifengv commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

Desktop 和 Web 用户在新会话草稿中显式选择 Max 思考强度后,发送第一条消息时会看到选择跳回模型默认的 High。本 PR 修复草稿初始设置写入和模型 ID 规范化过程中的状态回退,同时不改变已有会话的模型回退逻辑和跨客户端状态同步行为。

Bug Reproduction Steps

  1. 打开新会话草稿,选择一个支持多档思考强度的模型。
  2. 将思考强度从默认 High 改为 Max。
  3. 输入并发送第一条消息,创建新会话。
  4. 首次 profile 写入 Max 后,后续模型规范化再次写入 High,输入框跟随默认 agent 帧跳回 High。

Root Cause

草稿创建过程中的两个状态转换会与默认 agent 帧相互影响:

  1. 新会话的初始 agent 帧通常携带 High。草稿 profile 写入期间,pending 标记保护本地 Max;HTTP 请求完成后,客户端清除 pending 并重新应用缓存帧。如果新的 agent 帧尚未到达,缓存中的 High 就会覆盖 Max。
  2. 服务端可能返回上游模型名或旧模型别名,而不是草稿选择的目录模型 ID。此前客户端通过 setSessionModel 规范化 ID,把这一转换当作用户主动切换模型,从而选择目标模型的默认思考强度并再次写入 High。

本次只修复显式草稿思考强度选择遇到的问题,不改变已有会话的模型回退语义、普通 profile 写入或跨客户端状态协调。

Code Changes

修复范围原则: 在拥有该状态的最小路径上修复已复现的问题,默认保持相邻行为不变。针对性 bugfix 不应扩展成通用模型回退或跨客户端同步改造;更广泛的改进应独立处理,并单独做行为分析和回归覆盖。如果 review 评论只针对过度扩大后引入的行为,应撤掉扩大的部分,而不是继续叠加边界修复。

 createDraftSession
   写入显式选择的草稿思考强度
+  初始设置写入完成时保留该选择
+  如果服务端返回了不同的模型 ID
+    规范化 ID,同时保留草稿思考强度

 writeSessionProfile
   确认 pending 写入
-  成功后总是重新应用缓存的 agent 状态
+  普通写入的成功和失败协调逻辑保持不变
+  只有显式草稿思考强度写入成功时才跳过旧缓存帧回放

 已有会话的 settleSessionSettings
   setSessionModel(保持不变)

新增的 normalizeDraftSessionModel 只在草稿具有显式思考强度选择时调用。已有会话和未显式选择思考强度的草稿,仍走原来的 setSessionModel 行为。

回归测试通过真实 client 流程覆盖:草稿选择 Max → 初始写入期间收到缓存 High 帧 → HTTP 响应完成 → 仍保持 Max;随后收到 Low 帧时仍正常跟随。另有测试覆盖模型 ID 规范化和既有首发流程。

现有 kimi-code-app 和 @moonshot-ai/kimi-code 两条 patch changeset 保持不变,CLI 条目继续以 Web: 标记同一修复。

Behavior Changes and Affected Users

行为 修改前 修改后 受影响人群 退路
显式草稿思考强度写入成功,但对应的新 agent 帧尚未到达 缓存中的默认 High 可能覆盖已选择的 Max 保留显式草稿选择,后续 agent 帧仍正常生效 在新会话草稿中显式选择思考强度的 Desktop/Web 用户 不需要配置或开关,后续权威帧的行为不变
创建草稿会话时,服务端返回上游模型名或旧别名 模型规范化复用主动切模型逻辑,可能写入默认 High 仅在草稿路径规范化模型 ID 时保留显式思考强度 服务端会规范化所选模型 ID 的 Desktop/Web 用户 已有会话规范化和主动切模型行为不变
普通 profile 写入、失败的草稿写入、未显式选择 effort 的草稿、已有会话模型回退 使用既有缓存状态协调和目标模型默认值 保持不变 Desktop/Web 已有会话、多客户端同步,以及未显式选择草稿思考强度的用户 不涉及,这些路径保留原实现

受影响的生产代码是 Desktop 与 Web 共用的 packages/app-client 草稿创建、模型状态和 profile 写入路径。packages/app-core 的 API 类型和响应映射不再包含在本次改动中。

验证详情
  • pnpm exec vitest run --reporter=agent packages/app-client/test/agentStateFrames.test.ts packages/app-client/test/modelThinking.test.ts packages/app-client/test/startSessionAndActivateSkill.test.ts packages/app-client/test/workspace-state.test.ts:4 个文件、336 个测试全部通过。
  • pnpm --filter kimi-code-app run typecheck:通过。
  • 对 8 个改动的 TypeScript 文件运行 oxlint --type-aware:0 warnings,0 errors。
  • node scripts/checks/ratchet.mjs:通过,无新增违规。
  • 最终收窄版本通过真实 client 集成测试验证。定位原始问题时使用过 Electron 实测,但最终收窄后未重新运行 Electron。

Checklist

  • I have read the CONTRIBUTING document.
  • 无关联 issue;本 PR 已包含完整问题背景与复现步骤(外部 PR 仍需维护者批准)。
  • I have added tests that prove my feature works.
  • 上方行为变化表已完整覆盖本次改动;没有需要额外声明的默认行为翻转或删除行为。
  • 已检查 gen-changesets 规则;现有 Desktop 和 CLI patch 条目仍准确描述本次修复。
  • 无需更新用户文档,因为本 PR 恢复的是既有的选择行为。

@changeset-bot

changeset-bot Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5f5aecc

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-20T05:04:14.782209Z 5f5aecc Manual request
ℹ️ 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@5f5aecc
npx https://pkg.pr.new/@moonshot-ai/kimi-code@5f5aecc

commit: 5f5aecc

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

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex review

@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: 72429e30d8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 5f5aeccec8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@liruifengv
liruifengv merged commit c2bec3f into release/2026-11-20 Nov 20, 2026
19 checks passed
@liruifengv
liruifengv deleted the fix/draft-thinking-profile-race-release branch November 20, 2026 05:06
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.

1 participant