Skip to content

fix(kap-server): end tool calls cut short by a stop as interrupted - #4772

Merged
wbxl2000 merged 2 commits into
mainfrom
fix/tool-call-interrupted-on-stop
Nov 10, 2026
Merged

wbxl2000 merged 2 commits into
mainfrom
fix/tool-call-interrupted-on-stop

Conversation

@wbxl2000

@wbxl2000 wbxl2000 commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

用户在 desktop / web 里按停止后,正在执行的工具卡片会变成红色的失败状态,卡片里显示的是写给模型的提示语(「The user manually interrupted … Do not retry automatically …」)。这些工具是用户停掉的,不是自己失败的。

Bug Reproduction Steps

  1. 让 agent 运行一个耗时较长的工具,例如 sleep 60。
  2. 工具运行期间点停止。
  3. 工具卡片显示为失败,内容是 Interrupted by user,或者引擎补写的那段给模型的提示语。

Root Cause

停止一轮时,引擎先写 turn.cancel,再中止正在运行的工具。被中止的工具会返回 isError: true 的结果:Bash 返回 Interrupted by user,还没返回结果的工具由循环补写一条给模型的提示语。kap-server 的 fold 只看 isError,所以这些工具都以 outcome: failed 结束,客户端就显示成报错。

fold 在收到 turn.cancel 时已经给这一轮记了临时结局 interrupted(provisionalEnds),只是没有用在工具结果上。这是根本修复。

Code Changes

 finishToolCall(state, found, output, isError)
-  endToolCall(item, output, isError)
+  outcome = !isError ? completed
+          : provisionalEnds[turn] is interrupted ? interrupted
+          : failed
+  endToolCall(item, output, outcome)
  • endToolCall 改为直接接收结局。interrupted 和 failed 一样,把结果文本放在 error 里、不带 output 和 media。客户端对 interrupted 只读 output,所以写给模型的提示语不会显示出来,数据仍然保留在 wire 上。
  • 只有结果是错误、并且这一轮已经被停止时,才记为 interrupted。停止前已经返回的结果不变;步骤因错误中断(turn.step.interrupted 的 reason 为 error)时,工具错误仍是 failed。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
用户停止一轮后,被中止的工具调用的 outcome failed,error 为工具返回的文本 interrupted,error 文本保留 无。desktop / web 把 interrupted 显示为「已取消」 不需要
停止前已经返回结果的工具调用 按 isError 记为 completed / failed 不变 — —
步骤因错误中断时的工具错误 failed 不变 — —
agent 被销毁(服务端退出)时补写的工具结果 failed 不变:这条路径不写 turn.cancel,这次不覆盖 — —

受影响模块:packages/kap-server/src/services/conversation/conversationFold.ts、conversationItems.ts。实时推送和历史读取都经过同一个 fold。

测试:test/services/conversation.test.ts 新增两个用例。一个覆盖停止前已完成、停止前已失败、停止后被中止、停止后补写四种工具结果;另一个钉住步骤出错时工具错误仍是 failed。在改动前的代码上,第一个用例会失败。

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 9, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4aaee6f

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 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-10T08:35:59.075957Z 4aaee6f 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 9, 2026 •

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

commit: 4aaee6f

@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: 41a454d162

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

@wbxl2000

Copy link
Copy Markdown
Collaborator Author

@codex review
评审约定:

  1. 只审本 PR 相对 base 的 diff;base 存量问题请单列为 note,不作阻塞意见。
  2. 同类问题请一次性列出 diff 内全部位置,不逐轮分批提出。
  3. 纯风格/个人偏好意见不发;每条意见标注严重度(P0 阻断 / P1 应修 / P2 建议)。
  4. 已 resolve 的主题代表我们的判断取舍与当前代码现状,请勿重复提出。

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 4aaee6fbc1

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

@wbxl2000
wbxl2000 merged commit aa12538 into main Nov 10, 2026
17 checks passed
@wbxl2000
wbxl2000 deleted the fix/tool-call-interrupted-on-stop branch November 10, 2026 10:04
This was referenced Nov 11, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 15, 2026
…th 2.6.0

MoonshotAI#4772: end tool calls cut short by a stop as interrupted, and keep a tool error failed when the step itself failed.

MoonshotAI#4826: drop the deprecated turn_id alias from the file-history queries; a turn_id-only query now fails validation with 40001.

MoonshotAI#4730: a streamed item no longer ends early from the feed clock. The source shape is in place; the remaining live-feed gap is recorded in the ledger row.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 18, 2026
MoonshotAI#4663 and MoonshotAI#4789 now describe the recorded-event fold that serves the pinned
bundle: task links come from persisted TaskStarted records, and the feed no
longer rebuilds from the model-context view. MoonshotAI#4730 moves from partial to
ported (record-driven items seal once, with the recorded reasoning duration),
and MoonshotAI#4772's probe follows the feed suite it now lives in.

MoonshotAI#4893 is unblocked: `kap.conversation` stages its replay, publishes once after
rehydration, and gates live dispatch only while a mutable participant
restores. The PLAYBOOK note on the release-branch commits carries the
correction for MoonshotAI#4888 for the same reason.
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