Skip to content

fix(agent-core-v2): keep the output of stopped tool calls - #4854

Merged
wbxl2000 merged 1 commit into
release/2026-11-12from
fix/stopped-tool-output
Nov 12, 2026
Merged

wbxl2000 merged 1 commit into
release/2026-11-12from
fix/stopped-tool-output

Conversation

@wbxl2000

Copy link
Copy Markdown
Collaborator

Requirement or Bug

停止一轮对话时,正在运行的工具(例如一个还在输出的 Bash 命令)结束后,Web / 桌面端的工具卡片和 CLI 里只剩一段固定的中断说明(The user manually interrupted "Bash" …),命令在停止前已经打出来的输出看不到了。2.5.3 会显示「已有输出 + Interrupted by user」。这个 PR 让被停止的工具重新显示它实际产生的结果。

Bug Reproduction Steps

  1. 在任一客户端让 agent 运行一个持续输出的 Bash 命令,例如 echo line-1; sleep 60。
  2. 在 line-1 出现后点停止。
  3. 展开工具卡片:只看到固定的中断说明,没有 line-1。

Root Cause

#4630 移植 agent loop 时,turnProjection 在投影 tool.ended 事件时,只要工具结局是 aborted,就把发往 wire 的 tool.result.output 换成 abortedToolOutput(...) 生成的固定文本,丢掉了工具 handler 的真实结果。

实际上被停止的 Bash 仍会返回「已有输出 + Interrupted by user」,模型上下文里的工具消息(event.outcome.entry)也正是这段内容;只有发给客户端的那一份被替换了,所以界面和模型看到的内容不一致。属于根本修复。

Code Changes

 case 'tool.ended':
   result = handler 的执行结果(若有)
-  output = outcome 是 aborted ? abortedToolOutput(toolName, reason) : result?.output ?? entry.content
+  output = result?.output ?? entry.content

entry.content 就是写进模型上下文的工具消息:

  • 工具在停止时给出了结果,例如 Bash,这里就是它的真实输出;
  • 还没开始就被停止、或执行中直接抛出中止的工具,entry 本来就由 abortedToolOutcome 生成,内容仍是原来的固定说明。

所以去掉这个分支后,界面始终和模型看到的内容一致。不再需要的 toolName 计算和 abortedToolOutput import 一并删除。

文档同步:server-api-conversation.md(中英文)里工具调用条目的 output / media / error 原本写着「有 error 时 outcome 必为 failed」,和实现不符。现在改为:

  • output / media 只在正常完成时出现;
  • error 在失败或被停止时承载结果文本;
  • 轮次结束时仍没有结果的调用标为 interrupted,且不带 error。

Behavior Changes and Affected Users

行为 之前 之后 谁依赖旧行为 退路
被停止且已返回结果的工具,wire tool.result.output 与会话条目 error 固定中断说明 工具真实结果(Bash 为已有输出 + Interrupted by user) 无(这段固定说明是 #4630 新引入的,未进入正式版) 不需要
未开始或直接抛出中止的工具 固定中断说明 不变 — —
模型上下文 工具真实结果 不变 — —

受影响的客户端:desktop 与 web(会话条目里的工具卡片)、TUI 与 print 模式(tool.result 事件)。

测试覆盖:loop.test.ts 新增一条用例,同一轮里两个工具被停止:一个在中止时返回部分输出,断言 wire 上是它的真实输出;另一个直接抛出中止,断言仍是固定说明。去掉修复后,这条用例失败。

验证
  • packages/agent-core-v2 的 test/agent:87 个文件、2234 条测试通过
  • packages/kap-server 全量:1377 条通过,1 条跳过
  • apps/kimi-code 的 test/tui:3654 条通过
  • agent-core-v2 typecheck 通过
  • 桌面端 E2E 里在停止时记录了 turnProjection 的输入:handler 结果和模型上下文都是 stop-line-1\nInterrupted by user,wire 上却是固定说明

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 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 77259ac

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 11, 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-11T17:12:35.037800Z 77259ac 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 11, 2026

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

commit: 77259ac

@wbxl2000
wbxl2000 merged commit 265783c into release/2026-11-12 Nov 12, 2026
15 checks passed
@wbxl2000
wbxl2000 deleted the fix/stopped-tool-output branch November 12, 2026 04:45
@github-actions github-actions Bot mentioned this pull request Nov 12, 2026
Grapedge added a commit that referenced this pull request Nov 12, 2026
* fix(agent-core-v2): truncate oversized skill content (#4834)

* fix(kap-server): bind the main agent when a session is created (#4839)

* fix(kap-server): bind the main agent when a session is created

* fix(kap-server): reject a profile on prompt submissions

* fix(kap-server): reject a profile change through the session profile

* fix(kap-server): wait for model configuration before binding a new session

* fix(agent-core-v2): deduplicate restored task notifications (#4836)

* fix(agent-core-v2): deduplicate restored task notifications

* chore: add notification replay fix changeset

* fix(agent-core-v2): preserve task notifications after prompt-only crashes

* fix(agent-core-v2): complete prompts before ending turns

* test: align lifecycle snapshots with prompt completion order

* fix(agent-core-v2): settle all prompts during turn finalization

* fix(kap-server): drop reserved metadata keys from session profile updates (#4842)

* fix(kap-server): drop reserved metadata keys from session profile updates

* fix(kap-server): keep stored reserved metadata keys on profile updates

* docs: split and rewrite the server API reference (#4841)

* docs: split and rewrite the server API reference

* docs: redirect old server API anchors to the split pages

* docs: describe profile metadata as a replacement

* docs: mark question responses as answered-only

* fix(kap-server): avoid heartbeat timeout after scheduling stalls (#4823)

* fix(kap-server): avoid heartbeat timeout reaping after stalls or clock jumps

* fix(kap-server): grace heartbeat window for short scheduling stalls

* fix(kap-server): treat only clearly late heartbeats as scheduling stalls

* fix(kap-server): time heartbeats on a monotonic clock and drain queued input before reaping

---------

Co-authored-by: Kimi Code (Grok Bot) <[email protected]>

* fix(kap-server): undo a turn only once when requests race (#4846)

* docs: describe heartbeat stall handling (#4849)

* docs: describe heartbeat stall handling

* docs: explain the monotonic clock in the heartbeat notes

* fix(agent-core-v2): acquire session lock before loop restoration (#4848)

* fix(agent-core-v2): acquire session lock before loop restoration

* chore: add session lock lifecycle changeset

* fix(agent-core-v2): hold session lock through loop restoration

- add an operation-scoped lease to the session run gate
- hold it across loop initialization, reset, and pending drains
- cover idle timeout and release ordering

* fix(agent-core-v2): keep the output of stopped tool calls (#4854)

* fix(kap-server): drop the partial reply of a retried step (#4855)

* fix(agent-core-v2): dedupe historical tool schemas (#4862)

* fix(agent-core-v2): dedupe historical tool schemas

* chore: add duplicate tool schema changeset

* fix(agent-core-v2): preserve first tool schema declaration

* fix(agent-core-v2): remind on changed tool schemas

* fix(agent-core-v2): block stale tool schema calls

* fix(agent-core-v2): normalize registry schemas in pending checks

* fix(agent-core-v2): import registry tool metadata type

* fix(agent-core-v2): preserve abort handling during validation

* fix(agent-core-v2): refine validation hook preparation

* fix(agent-core-v2): make validation hooks synchronous

* fix(agent-core-v2): preserve tool result notes on fork (#4867)

* fix(agent-core-v2): preserve tool result notes on fork

* chore: add fork tool result note changeset

* fix(agent-core-v2): scope tool result note restoration to forks

* fix(agent-core-v2): normalize inherited tool result notes

* fix(agent-core-v2): isolate fork note restoration

* feat(tui): sweep running titles toward text and add KIMI_CODE_TUI_ANIMATION_FPS (#4843) (#4870)

* chore: sync web dist from code-app (#4871)

code-app: 8ab17294e031323186d357d121c5360b8353900e

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

* ci: release packages (#4835)

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

* chore: sync web dist from code-app

code-app: 5835391dac3a2b9e0c65ffbd418f0d6042a7adb2

---------

Co-authored-by: Haozhe <[email protected]>
Co-authored-by: qer <[email protected]>
Co-authored-by: Kimi Code (Grok Bot) <[email protected]>
Co-authored-by: grapedge <[email protected]>
Co-authored-by: kimi-agent-bot <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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