Skip to content

feat(kap-server): link tool_call items to the task they run as - #4789

Merged
wbxl2000 merged 2 commits into
mainfrom
feat/tool-call-task-id
Nov 10, 2026
Merged

wbxl2000 merged 2 commits into
mainfrom
feat/tool-call-task-id

Conversation

@wbxl2000

@wbxl2000 wbxl2000 commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

工具调用条目(tool_call)不带它对应的任务 id。任务这边有 parent_tool_call_id 指回工具调用,但只对还在 task.list 里的任务有用。后台任务比启动它的工具调用活得更久:它结束后,或者在服务端崩溃后失联(lost),重新订阅时就不在 task.list 里了。工具卡片找不到它的 task_id,也就没法发 task.watch 查最终状态和输出。

客户端现在只能用正则从工具输出文本里抠 task_id:(code-app useKimiWebClient.ts 的 bashTaskIdOf),这依赖输出文案,很脆弱。

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

 toolCallItemSchema
+  task_id?: string

 ConversationFeed RECORD_EVENTS
+  TaskStarted                       # durable, so both live updates and history replay see it

 conversation fold
+  'task.started' → find the tool call by info.parentToolCallId (shell, subagent)
+                   or info.toolCallId (background question), set item.task_id
  • 引擎只为后台任务写 task.started:一开始就在后台启动的任务,或者前台任务被转到后台的那一刻。这正好就是需要靠工具调用找回任务的情况。前台运行中的工具,客户端照旧通过 task.list 里任务的 parent_tool_call_id 找到它;用户把它转到后台时,task_id 就会出现在工具调用上。让引擎也持久化前台任务,会改变会话恢复和失联提醒的语义,这次不做。
  • task.started 是持久化的记录,所以历史读取和实时推送走同一条路径。实时推送时,正在运行的工具调用会收到 item.updated { set: { task_id } };如果工具调用已经结束,会随 item.ended 一起带上。
  • 找不到对应工具调用的任务(例如不是由工具启动的任务)直接忽略。
  • server-api.md(中英)的 tool_call 字段说明补上 task_id。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
工作以后台任务运行的工具调用(后台启动的 Bash / Agent / 提问,或被转到后台的前台调用) 没有 task_id 带 task_id 无。现有客户端忽略未知字段,code-app 已经优先读 item.task_id,读不到才退回输出文本 不需要
一直在前台运行的工具调用 没有 task_id 不变,运行中通过 task.list 的 parent_tool_call_id 关联 — —
运行中的工具调用启动任务时的实时推送 无 多一条 item.updated,只含 task_id 无 —
其他工具调用 — 不变 — —

受影响模块:packages/kap-server 的对话协议、对话 feed 与 fold。apiSurface 快照没有变化。

测试(test/services/conversation.test.ts):

  • fold:后台 shell、后台子 agent、后台提问三类任务都关联到各自的工具调用;对应不上的任务被忽略。
  • feed:工具运行中派发 TaskStarted,订阅方收到 item.updated { task_id }。

code-app bump 子模块后,可以删掉客户端从输出文本里找 task_id 的兜底。

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

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: f65c4e9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 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-10T10:34:06.195242Z f65c4e9 New commits
ℹ️ 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 10, 2026 •

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

commit: f65c4e9

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

ℹ️ 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. Nice work!

Reviewed commit: 7dd1daa9bd

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

sailist
sailist previously approved these changes Nov 10, 2026
sailist
sailist previously approved these changes Nov 10, 2026
@wbxl2000
wbxl2000 merged commit 1424092 into main Nov 10, 2026
16 checks passed
@wbxl2000
wbxl2000 deleted the feat/tool-call-task-id branch November 10, 2026 10:34
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