Skip to content

feat: sync running tasks over WebSocket and drop the REST task API - #4535

Merged
wbxl2000 merged 19 commits into
mainfrom
qer/task-live
Nov 2, 2026
Merged

wbxl2000 merged 19 commits into
mainfrom
qer/task-live

Conversation

@wbxl2000

@wbxl2000 wbxl2000 commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

任务改为只同步正在跑的:每个 agent 的运行中任务通过 WebSocket task.list / task 帧同步,状态直接来自引擎的任务服务;停止任务和转后台改为 WebSocket 请求 task.stop / task.background;REST 任务接口删除。已结束任务的结果留在会话历史里(工具结果和完成通知),不再作为任务列表推送。

取代 #4362(随后关闭)。客户端配套:MoonshotAI/kimi-code-app#1057。

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

核心思路

  • 任务只存在于它运行的时候。 实时视图里只有正在跑的任务;任务结束时推送它的最后一帧,之后不再出现在 task.list 里。结果交给等它的一方:前台任务的结果是工具结果,后台任务的结果是完成通知,两者都在会话历史里。
  • 前台和后台只看一件事:发起它的工具调用还在不在等它。 这就是 detached。前台 bash、前台 subagent、swarm 成员都是 detached: false 的任务,也都推送 task 帧;转后台就是把 detached 变成 true。
  • 状态由引擎直接给出。 feat(kap-server): send tasks as task events and stream task output #4362 在 kap-server 里用 SessionTasks 把引擎事件和 wire 记录折叠成任务状态,现在改为订阅引擎任务服务的变化事件,SessionTasks 删掉。swarm 成员在创建时就登记为任务,不再由服务端从 subagent.* 事件拼出来。

源码(不含测试和文档)+1036 / −1198:agent-core-v2 +326 / −25,transcript +23 / −346,kap-server +687 / −827(其中删掉 REST 任务路由 341 行、coreEventMap 的任务投影 319 行)。

协议

server → client  { type: "task.list", session_id, agent_id, tasks: TaskState[] }
server → client  { type: "task", session_id, agent_id, event_created_at, ...TaskState }
client → server  { type: "task.stop" | "task.background", request_id, session_id, agent_id, task_id }
client → server  { type: "task.watch", request_id, session_id, agent_id, task_id, since_offset?, tail_bytes? }
client → server  { type: "task.unwatch", request_id, session_id, agent_id, task_id }
server → client  { type: "response", request_id, code, msg?, task?: TaskState }
server → client  { type: "task.output", session_id, agent_id, task_id, offset, text }

TaskState = { task_id, kind: "shell" | "subagent" | "other", status: "running" | "ended",
              outcome?, phase?, detached, description?, child_agent_id?, parent_tool_call_id?,
              swarm_index?, command?, started_at?, ended_at?, result_summary?, error?,
              state_reason?, model?, thinking? }

和 #4362 相比:去掉 usage,加 swarm_index;已结束任务不再补发;新增 task.list、task.stop、task.background,以及应答里的 task。

  • task.list:连接开始接收某个 agent 时发一次(subscribe_v2 里该 agent 的粒度从 off 或未订阅变为非 off),内容是该 agent 此刻正在跑的全部任务,客户端用它整份替换本地列表。之后加入会话的 agent 直接从 task 帧开始。
  • task:任务每次变化发一帧完整状态,发给所有对该 agent 粒度不为 off 的连接。
  • 应答里的 task:task.watch 成功、task.stop / task.background 成功时带上任务当前状态。需要已结束任务的最终状态(例如重启后恢复一个输出面板)时,对它发 task.watch 即可。
  • task.stop / task.background 和 task.watch / task.unwatch 走同一个按任务排队的处理器:同一任务的请求按到达顺序执行,不同任务互不等待。会话不存在回 40401,该 agent 下没有这个任务回 40406,内部错误回 50001;停止或转后台一个已结束的任务回 0 并带上它的最终状态。发起方没法不再等它的任务(目前是 AgentSwarm 的成员)不能转后台,task.background 回 40933(TASK_NOT_DETACHABLE),应答带未变的状态。
  • 应用退出时还在跑的后台任务,恢复时结束为 outcome: "lost"。写给模型的失联提醒和 main 上一样是隐藏的注入消息,不进转录;客户端需要这类任务的最终状态时,对它发 task.watch。

结构

agent-core-v2
  IAgentTaskService
+   onDidChangeTask: Event<AgentTaskInfo>     # register / track / detach / settle / reconcile marks lost
+   refresh(taskId)                           # re-publish a running task after its own state changed
  SessionSwarmService.run
+   SwarmMemberTasks                          # one foreground task per member, registered at birth
+     AgentRunBatch.onStarted / onSettled     # started → agent id; suspended → refresh; settled → outcome
+     each member runs on its own signal that follows the swarm signal   # task.stop on a member stops only that member
+     registered as not detachable            # task.background on a member replies 40933

kap-server
- services/transcript/sessionTasks.ts         # folding engine events + wire records into task state
- routes/tasks.ts, protocol/rest-task.ts, protocol/task.ts
+ transport/ws/v1/sessionTaskFeed.ts          # per live session: watch every agent's onDidChangeTask
+ transport/ws/v1/taskState.ts                # AgentTaskInfo → TaskState
  transport/ws/v1/sessionEventBroadcaster.ts
+   per connection: the agents it already got a task.list for
+   subscribe / grade change / reattach → task.list for newly received agents
+   task change → task frame to every target whose grade for that agent is not off
  transport/ws/v1/taskRequests.ts             # watch / unwatch / stop / background, one queue per task

transcript
- TranscriptTask, taskref items, task ops, snapshot.tasks   # from #4362
  • 每个连接记录它已经收到过 task.list 的 agent,和 transcript 的 seeded 状态无关。所以再次订阅(例如调高某个 subagent 的粒度)只给新收到的 agent 发 task.list,其他 agent 的 task 帧照常流动,不会丢也不会重复。
  • 落盘格式不变:wire.jsonl 仍只追加,后台任务仍写 tasks/<id>.json 和 tasks/<id>/output.log;前台任务仍不落盘,所以 swarm 成员的结果摘要只在内存里,不会把长文本写进任务文件。
  • /init(CLI 生成 AGENTS.md)起的 subagent 没有登记为任务:它的 parentToolCallId 是占位值 generate-agents-md,会话评分依赖这个值;desktop / web 也没有消费它的地方。
  • 从 feat(kap-server): send tasks as task events and stream task output #4362 带过来的 task.watch 修复都保留:连接关闭后跳过排队中的 watch;建立推送出错时回 50001 并释放 watch;首段准备好之后才回复成功;尾部读取遇到写到一半的字符时把这段留给下一段。

提交

  1. feat(agent-core):任务变化事件,swarm 成员登记为任务。
  2. refactor(transcript):任务从转录里去掉(来自 feat(kap-server): send tasks as task events and stream task output #4362)。
  3. feat(kap-server):实时任务帧、task.stop / task.background,删除 REST 任务接口和 SessionTasks,更新 API 文档。
  4. chore(agent-core):按新的任务字段重新生成 docs/state-manifest.d.ts。
  5. chore:三条 changeset(实时任务帧、输出与任务请求、删除 REST 任务接口),均为 patch。
  6. fix(agent-core):swarm 成员逐个停止(各自的取消信号),不可转后台,并带上模型和思考强度。
  7. fix(kap-server):对仍留在前台的任务,task.background 回 40933。
  8. fix(agent-core):排队中的 swarm 成员被停止时立即结束;并发配置在登记成员之前校验。
  9. refactor(transcript):失联提醒和其他注入消息一样保持隐藏,撤掉中途加过的 warning notice 和 lostTasks,API 文档里的说明一并删掉。
  10. 合入 main,分两步:先合到 feat: support folder-scoped git status #4527(050faa85e),code-app 的 submodule 指向这一提交,它有本 PR 的全部改动和 code-app main 所用的服务端代码,不含 refactor(agent-core-v2): decouple tool disclosure from execution #4538(desktop 还没适配 refactor(agent-core-v2): decouple tool disclosure from execution #4538 改掉的工具选择接口);再合入其余部分。kap-server/test/tasks.test.ts 只测已删除的 REST 接口,保持删除;生成的 manifest 重新生成后与合并结果一致。
  11. chore: sync web dist from code-app:apps/kimi-code/dist-web 当前由 MoonshotAI/kimi-code-app#1057 在 79a10a70b 构建(它已合入 main 上 chore: sync web dist from code-app #4595 产物所用的 code-app 提交,所以产物同时带着 main 的 web 改动),构建时 submodule 对齐本分支 head,产物注入的 CLI 版本是 2.4.1;之前两次同步的产物都被它覆盖。fix: use session cwd for stdio MCP servers #1057 再有改动时需要重新同步。

Behavior Changes and Affected Users

行为 之前(main) 之后 依赖旧行为的人群 退路
转录里的任务(snapshot.tasks、taskref、task.upsert 等 op) 有 没有 main 上的 desktop / web 客户端;读转录的外部脚本 无。客户端随配套 PR 一起改;desktop 内嵌 server 随包发布
REST GET /sessions/{id}/tasks、GET …/tasks/{task_id}、…:cancel、…:detach 可用 删除(404) main 上的 desktop / web(任务列表、停止、转后台);调用这些接口的外部脚本 无 REST 替代;改用 WebSocket 的 task.list / task 帧和 task.stop / task.background。changeset 写明了接口删除,版本级别为 patch
任务状态推送 混在 transcript.ops 里 独立的 task.list + task 帧 — —
已结束任务 一直留在转录里 只推送最后一帧,之后不在 task.list 里 想在客户端列出历史任务的 UI 会话历史(工具结果、完成通知);task.watch 的应答带最终状态
前台任务(前台 bash、前台 subagent、swarm 成员) 只有 subagent 经转录可见 都有 task 帧(detached: false) — —
内置在 CLI 里的 web 产物(apps/kimi-code/dist-web) 读转录任务和 REST 任务接口 本 PR 一并同步了按新协议构建的产物(来自 MoonshotAI/kimi-code-app#1057):任务栏只列运行中的后台任务,停止 / 转后台走 WebSocket kimi web 用户 不需要:产物与服务端在同一个提交里更新
应用退出时还在跑的后台任务(恢复后为 lost) REST 任务列表里有(lost 映射为 failed),desktop / web 任务栏的「全部」「最近」会列出它 界面上不再出现;写给模型的失联提醒照旧隐藏,模型在用户下一次发消息时看到 main 上的 desktop / web 用户 用户侧没有退路,code-app 的任务栏 changeset 写明了这项损失;客户端仍可对任务发 task.watch,应答带 outcome: "lost"
task.terminated wire 记录的 outputTail(docs/wire-manifest.d.ts) 写入任务结束时的输出末尾 不再写入 main 上唯一的读取方是 kap-server 把任务投影进转录的代码,本 PR 已删除;读 wire.jsonl 的外部工具 旧记录照常回放(非严格 schema 忽略该字段);完整输出在 tasks/<id>/output.log,后台任务的完成通知带输出摘要
docs/state-manifest.d.ts 里的 SubagentTaskInfo 没有这三个字段 新增可选的 swarmIndex、stateReason、resultSummary 读任务 JSON 文件的外部工具 不需要:只有前台 swarm 成员会带这三个字段,前台任务不落盘,磁盘上的任务记录形状不变,旧数据照常可读
task.stop / task.background 作用于 swarm 成员 (新接口) 停止只停这个成员,其余成员继续;转后台回 40933 — —
模型侧的 TaskList 看不到 swarm 成员 swarm 运行期间,并行调用 TaskList 时能看到运行中的成员 很少见:swarm 工具调用阻塞本轮,只有同一步里并行调用 TaskList 才会看到 无,成员结束后不再列出

受影响的模块与测试:

  • agent-core-v2:taskManager.test.ts(注册、刷新、转后台、结束都发布变化,前台任务也发布);sessionSwarm.test.ts(每个成员登记为调用方的前台任务,跟随挂起和完成);合入 main 后,task、swarm、tools 相关测试 22 个文件 527 条通过。
  • transcript:layers.test.ts、store.test.ts 去掉任务相关的用例;118 条通过。
  • kap-server:sessionEventBroadcaster.test.ts(先发 task.list 再发变化;再次订阅只给新 agent 发列表且不打断已有的流;后加入的 agent 直接收到变化);wsConnectionV1.test.ts(watch 应答带状态;stop / background 各自应答,任务不存在回 40406;缺 request_id 以 1008 断开);transcript.test.ts(任务事件不进转录和日志);apiSurface 快照去掉三条任务路由;合入 main 后 72 个文件 1439 条通过。
  • 文档:docs/{en,zh}/reference/server-api.md 删掉 REST 任务一节,补上 task.list、task.stop、task.background 和应答的 task。
  • 合入 main 后,本地根目录 pnpm typecheck、pnpm lint(0 error)通过。端到端在 code-app 配套分支上跑:desktop e2e 的后台 bash、后台 subagent、任务与待办三个流程在本地连续两次全部通过,帧序列(前台任务帧 → task.background → 带状态的应答 → task.watch → 输出 → 结束帧)在 trace 里核对过。

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.(只有 server API 参考文档受影响,已手动更新中英两份;CLI 用户文档里的后台任务描述没有变化)

The task service now publishes onDidChangeTask whenever a task is
registered (foreground tasks included), moved to the background, ended, or
marked lost after a restart, and refresh(taskId) republishes a running
task whose details changed. Clients get live task state straight from the
engine instead of folding wire records.

Each swarm member is registered as a foreground agent task of the caller
when the swarm starts. The task records the member's child agent, spawning
tool call and swarm index, its suspension reason while rate limited, and
its result summary when it settles. Stopping a member stops the whole
swarm, which is the only cancellation the swarm supports. Foreground tasks
are not persisted and send no notifications, so the model and the disk
see nothing new.

Background task output is read by range instead of loading the whole
file, readOutputTail and onDidAppendOutput serve task output streaming,
and task.terminated records no longer carry outputTail.
Tasks are not conversation content, so the transcript no longer models
them: TranscriptTask, taskref items, the task.upsert / taskref.upsert /
task output append ops, AgentTranscriptSnapshot.tasks, the projection of
task / subagent / shell events into task rows, the subagent task seeding on
bind, and the lost marking on cold reads are all removed. The REST
transcript endpoints no longer return tasks.

The one task fact that belongs to the conversation stays visible: the
injected reminder about background tasks lost when the app exited is now
shown as a warning notice marker instead of being hidden with other
injected messages.
…sk API

A connection that starts receiving an agent (its grade in subscribe_v2 is
not off) gets one task.list frame with every task that agent is running
right now, foreground commands and swarm members included, and then a
task frame on every change straight from the engine's task service. Ended
tasks are not resent: the last task frame of a task reports its outcome,
the outcome stays in the session history, and task.watch replies with the
task's state. The per connection list state no longer borrows the
transcript's seeded flag, so a re-subscribe that raises one agent's grade
neither drops nor resends the other agents' tasks.

task.stop and task.background join task.watch / task.unwatch as flat
requests on the same per-task queue, and every reply can carry the task's
current state. They replace the REST task endpoints, which are removed
together with their schemas: list, detail, :cancel and :detach.

task.watch keeps the fixes made during review: queued watches are skipped
after the connection closes, setup errors reply 50001 and release the
watch, success is sent only once the first chunk is ready, and a chunk the
tail read caught mid-write is forwarded instead of dropped.
The notice for background tasks that lost contact when the app exited now carries lostTasks, one { taskId, description, kind } entry per task line of the reminder, so clients can show which tasks were lost without displaying the model-facing reminder text.
@changeset-bot

changeset-bot Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 94113e0

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 Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T04:12:15.145389Z 94113e0 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 Oct 29, 2026 •

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

commit: 94113e0

@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: 90230d2a06

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

…k fields

SubagentTaskInfo gained the optional swarmIndex, stateReason and resultSummary fields; only foreground swarm member tasks set them, and foreground tasks are never written to disk, so stored task records keep their shape.
@wbxl2000

Copy link
Copy Markdown
Collaborator Author

CI 说明:剩下的失败只有 kimi-oauth 的 refreshProviderModels > ignores user-defined aliases when custom-registry metadata is unchanged,main 上最近几次 CI 也失败在这一条,与本 PR 无关。第一轮里的 state-manifest.d.ts 过期已在 15304e5 修复;当时另外失败的任务截止计时器、Tower 并发、remote-control 重连三条在重跑中通过。

@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: 052c927a67

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

…e foreground

Stopping one swarm member's task aborted the controller shared by the whole
swarm, so every active and queued member was cancelled. Each member now runs
on its own signal that follows the swarm's, and the batch takes the swarm
signal from its options instead of from the first task, so a stop cancels
only that member and the batch goes on with the rest.

A swarm member could also be "moved to the background": the AgentSwarm tool
waits for the whole swarm and never observes a member's foreground release,
so the member was marked detached, persisted, and recorded as a background
task while the tool call kept waiting. Members are now registered as not
detachable, and detach leaves such a task in the foreground.

Member tasks also carry the model and thinking effort: from the spawn plan
while queued, and from the child agent's profile once the attempt starts,
which also covers resumed members.
…o the background

task.background replied 0 even when the task could not leave the
foreground, such as an AgentSwarm member. It now replies 40933
(TASK_NOT_DETACHABLE) with the task's unchanged state, and the API
reference lists the code.
Built from MoonshotAI/kimi-code-app#1057, which reads tasks from the task.list / task frames and sends task.stop / task.background, so the bundled web UI matches the task protocol of this change.

code-app: 3be5e316864f3843c2c868ec8ca388d6b99682e5

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

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

A member stopped while it waited for a concurrency slot or for its rate
limit retry kept its place in the queue: the batch only linked a member's
signal once its attempt started, so the member and the AgentSwarm call
stayed open until a slot freed up or the retry timer fired. The batch now
watches every member's own signal and settles a queued member as soon as
it is stopped, telling the launcher to abandon a requeued child. A member
stopped on its own reports "The user stopped this subagent." instead of
the message for interrupting the whole batch.

The swarm concurrency setting is also validated before any member task is
registered, so an invalid KIMI_CODE_AGENT_SWARM_MAX_CONCURRENCY no longer
leaves running member tasks and an in-flight entry that never settle.
@wbxl2000

Copy link
Copy Markdown
Collaborator Author

@codex review
评审约定:

  1. 只审本 PR 相对 base 的 diff;base 存量问题请单列为 note,不作阻塞意见。
  2. 同类问题请一次性列出 diff 内全部位置,不逐轮分批提出。
  3. 纯风格/个人偏好意见不发;每条意见标注严重度(P0 阻断 / P1 应修 / P2 建议)。

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: d109a3da76

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

The reminder about background tasks that lost contact after the app quit
is written for the model, like every other injection, so the transcript
no longer turns it into a notice marker carrying lostTasks; it stays
hidden as it is on main. The API reference drops the notice description.
Rebuilt from MoonshotAI/kimi-code-app#1057 after the timeline stopped rendering the lost-task reminder; the build also carries the swarm card total fix.

code-app: d55d3a3c13dbf6daf48a63406bf8dc94d204a807
Stops before #4538 so the code-app branch can pin a commit that has both
this change and the server code code-app main runs on, without the
tool-select API change that desktop has not adapted to yet.
Rebuilt from MoonshotAI/kimi-code-app#1057 after merging main on both sides, so the bundle reports CLI 2.4.1 and keeps the timeline free of the lost-task reminder.

code-app: 72b42ff14d3ebd5875d5195d0fd8cca2827ddd47
@wbxl2000

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: f3dec62edc

ℹ️ 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 2, 2026
dist-web takes main's sync for now; the next commit rebuilds it from MoonshotAI/kimi-code-app#1057 after that branch merged the code-app commit main's sync came from.
Rebuilt from MoonshotAI/kimi-code-app#1057 after it merged code-app main up to the commit main's latest dist came from, so the bundle keeps main's web changes, reads the task frames, and reports CLI 2.4.1.

code-app: 79a10a70be15b51957ac6eed705a0c5337fe8fa6
Copilot AI balanced review requested due to automatic review settings November 2, 2026 04:08

@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: 94113e050f

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

Comment thread .changeset/web-interaction-polish.md Resolved
@wbxl2000
wbxl2000 merged commit ebc2a9f into main Nov 2, 2026
18 checks passed
@wbxl2000
wbxl2000 deleted the qer/task-live branch November 2, 2026 04:15

Copilot AI 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.

🟡 Changes recommended

Task-list synchronization can omit running tasks or retain stale tasks across subscription changes and cold-session reconnects, while explicitly stopped swarm tasks are incorrectly marked as failed.

3 open issues
3 files not reviewed
  • apps/kimi-code/dist-web/assets/channel-DaJqmihc.js: Generated file
  • apps/kimi-code/dist-web/assets/classDiagram-OUVF2IWQ-CMTPMXFA.js: Generated file
  • apps/kimi-code/dist-web/assets/classDiagram-v2-EOCWNBFH-CMTPMXFA.js: Generated file
What changed in this PR

本 PR 将实时任务状态从转录层移至引擎驱动的 WebSocket 通道,只同步运行中的任务,并以 WebSocket 请求替代 REST 任务接口;同时同步 CLI 内置 Web 产物。

Changes:

  • 新增任务列表、状态、输出订阅及停止/转后台协议。
  • 为 swarm 成员登记独立任务,支持逐个停止并禁止转后台。
  • 移除转录任务模型及 REST 任务接口,同步测试、契约清单和发布说明。
File Description
packages/​transcript/​test/​store.test.ts 移除任务用例,调整条目排序测试。
packages/​transcript/​src/​view/​registry.ts 移除工具视图中的任务字段。
packages/​transcript/​src/​store/​agentTranscript.ts 移除任务访问与快照输出。
packages/​transcript/​src/​ops/​operation.ts 移除任务操作和快照字段。
packages/​transcript/​src/​ops/​apply.ts 移除任务状态归并逻辑。
packages/​transcript/​src/​model/​task.ts 删除转录任务模型。
packages/​transcript/​src/​model/​item.ts 移除任务引用条目。
packages/​transcript/​src/​model/​ids.ts 移除任务引用 ID 类型。
packages/​transcript/​src/​index.ts 移除任务模型导出。
packages/​transcript/​src/​history/​groupTurns.ts 历史快照不再含任务列表。
packages/​transcript/​src/​history/​foldFacts.ts 移除历史任务投影,保留子代理引用。
packages/​transcript/​src/​contract/​schema.ts 移除转录任务相关 schema。
packages/​kap-server/​test/​transcript.test.ts 调整转录条目测试类型。
packages/​kap-server/​test/​sessionEventBroadcaster.test.ts 覆盖任务列表、状态流与重复订阅。
packages/​kap-server/​test/​__snapshots__/​apiSurface.snapshot.test.ts.snap 移除 REST 任务路由快照。
packages/​kap-server/​src/​transport/​ws/​v1/​wsConnectionV1.ts 接入任务请求处理及连接清理。
packages/​kap-server/​src/​transport/​ws/​v1/​taskState.ts 将引擎任务转换为协议状态。
packages/​kap-server/​src/​transport/​ws/​v1/​sessionTaskFeed.ts 订阅各 agent 的任务变化。
packages/​kap-server/​src/​transport/​ws/​v1/​sessionEventBroadcaster.ts 推送任务基线和实时变化。
packages/​kap-server/​src/​transport/​ws/​v1/​registerWsV1.ts 注入任务数据源。
packages/​kap-server/​src/​transport/​ws/​v1/​protocol.ts 新增任务响应构造函数。
packages/​kap-server/​src/​services/​transcript/​transcriptService.ts 移除任务快照与失联状态投影。
packages/​kap-server/​src/​services/​transcript/​coreBinding.ts 移除转录绑定时的任务初始化。
packages/​kap-server/​src/​routes/​transcript.ts 转录响应不再返回任务。
packages/​kap-server/​src/​routes/​registerApiV1Routes.ts 取消 REST 任务路由注册。
packages/​kap-server/​src/​protocol/​ws-task.ts 定义任务 WebSocket 消息。
packages/​kap-server/​src/​protocol/​ws-control.ts 注册任务请求与事件协议。
packages/​kap-server/​src/​protocol/​task.ts 删除旧 REST 任务模型。
packages/​kap-server/​src/​protocol/​rest-task.ts 删除 REST 任务请求与响应定义。
packages/​kap-server/​src/​protocol/​error-codes.ts 新增不可转后台错误码。
packages/​agent-core-v2/​test/​os/​backends/​node-local/​tools/​bash.test.ts 更新任务服务测试替身。
packages/​agent-core-v2/​test/​agent/​task/​tools/​task-tools.test.ts 补齐任务服务新增接口。
packages/​agent-core-v2/​test/​agent/​task/​taskService.test.ts 移除终态输出尾部记录测试。
packages/​agent-core-v2/​test/​agent/​task/​taskOps.test.ts 移除旧 outputTail 持久化测试。
packages/​agent-core-v2/​test/​agent/​task/​taskManager.test.ts 覆盖任务事件、禁止分离及输出限制。
packages/​agent-core-v2/​test/​agent/​task/​output-access.test.ts 覆盖输出事件和字节尾部读取。
packages/​agent-core-v2/​src/​features/​swarm/​session/​swarmMemberTask.ts 将 swarm 成员适配为引擎任务。
packages/​agent-core-v2/​src/​features/​swarm/​session/​sessionSwarmService.ts 登记成员任务并隔离取消信号。
packages/​agent-core-v2/​src/​features/​swarm/​session/​agentRunBatch.ts 新增生命周期回调和排队成员停止处理。
packages/​agent-core-v2/​src/​agent/​tools/​agent/​subagent-task.ts 扩展 swarm 状态与结果字段。
packages/​agent-core-v2/​src/​agent/​task/​taskService.ts 发布任务/输出事件,支持尾部读取。
packages/​agent-core-v2/​src/​agent/​task/​taskOps.ts 移除终态记录的 outputTail。
packages/​agent-core-v2/​src/​agent/​task/​task.ts 扩展任务事件与控制接口。
packages/​agent-core-v2/​src/​agent/​task/​persist.ts 新增持久化输出尾部范围读取。
packages/​agent-core-v2/​docs/​wire-manifest.d.ts 同步终态记录契约。
packages/​agent-core-v2/​docs/​state-manifest.d.ts 同步新增子代理任务字段。
apps/​kimi-code/​dist-web/​index.html 指向新版脚本和样式。
apps/​kimi-code/​dist-web/​assets/​vue.runtime.esm-bundler-BC3TLxRT.js 更新主包引用。
apps/​kimi-code/​dist-web/​assets/​Tooltip-BsQaXxKr.js 更新主包引用。
apps/​kimi-code/​dist-web/​assets/​swimlanesDiagram-G3AALYLV-DXeQacGI.js 删除旧泳道图资源。
apps/​kimi-code/​dist-web/​assets/​swimlanesDiagram-G3AALYLV-CtTVvz00.js 加入新版泳道图资源。
apps/​kimi-code/​dist-web/​assets/​stateDiagram-v2-6OUMAXLB-C9Jkt85o.js 删除旧状态图资源。
apps/​kimi-code/​dist-web/​assets/​stateDiagram-v2-6OUMAXLB-B_Hafhrm.js 加入新版状态图资源。
apps/​kimi-code/​dist-web/​assets/​sizeCapture-X5ZJPWSS-BJqpVaM-.js 更新图表依赖引用。
apps/​kimi-code/​dist-web/​assets/​railroadDiagram-RFXS5EU6-f4taWwi4.js 更新铁路图依赖引用。
apps/​kimi-code/​dist-web/​assets/​pieDiagram-ENE6RG2P-BpHmxJHB.js 更新饼图依赖引用。
apps/​kimi-code/​dist-web/​assets/​pegDiagram-2B236MQR-DJuirOx8.js 更新 PEG 图依赖引用。
apps/​kimi-code/​dist-web/​assets/​infoDiagram-FWYZ7A6U-BLOsSUqW.js 更新信息图依赖引用。
apps/​kimi-code/​dist-web/​assets/​index6-DDmQN49G.js 更新数学渲染模块引用。
apps/​kimi-code/​dist-web/​assets/​index-_mdBonhR.js 更新差异渲染模块引用。
apps/​kimi-code/​dist-web/​assets/​flowDiagram-23GEKE2U-DxjFwvof.js 更新流程图依赖引用。
apps/​kimi-code/​dist-web/​assets/​ebnfDiagram-CCIWWBDH-DCKlz8eX.js 更新 EBNF 图依赖引用。
apps/​kimi-code/​dist-web/​assets/​diagram-OA4YK3LP-35cBR3oE.js 更新树形图依赖引用。
apps/​kimi-code/​dist-web/​assets/​diagram-NH7WQ7WH-BxYPQAuV.js 更新数据包图依赖引用。
apps/​kimi-code/​dist-web/​assets/​CodeBlockNode-BTz7rpgu.js 更新代码块懒加载资源引用。
apps/​kimi-code/​dist-web/​assets/​classDiagram-v2-EOCWNBFH-nQpwphBh.js 删除旧版类图资源。
apps/​kimi-code/​dist-web/​assets/​classDiagram-v2-EOCWNBFH-CMTPMXFA.js 加入新版类图资源。
apps/​kimi-code/​dist-web/​assets/​classDiagram-OUVF2IWQ-nQpwphBh.js 删除旧类图入口。
apps/​kimi-code/​dist-web/​assets/​classDiagram-OUVF2IWQ-CMTPMXFA.js 加入新版类图入口。
apps/​kimi-code/​dist-web/​assets/​chunk-XXDRQBXY-D4IktZ7X.js 更新图表元素模块引用。
apps/​kimi-code/​dist-web/​assets/​chunk-VR4S4FIN-BEk7PY7y.js 更新 SVG 视口模块引用。
apps/​kimi-code/​dist-web/​assets/​chunk-MOJQB5TN-BEVgX4By.js 更新铁路图共享模块引用。
apps/​kimi-code/​dist-web/​assets/​chunk-JWPE2WC7-Dx7wMKfk.js 更新图表公共数据模块引用。
apps/​kimi-code/​dist-web/​assets/​chunk-5VM5RSS4-DXMDfDsc.js 更新图标样式模块引用。
apps/​kimi-code/​dist-web/​assets/​chunk-32BRIVSS-W1R_O9Iv.js 更新图形绘制模块引用。
apps/​kimi-code/​dist-web/​assets/​chunk-2Q5K7J3B-vrnYyEsK.js 更新图表状态模块引用。
apps/​kimi-code/​dist-web/​assets/​channel-DaJqmihc.js 加入新版颜色通道资源。
apps/​kimi-code/​dist-web/​assets/​channel-BX7n6tbe.js 删除旧颜色通道资源。
apps/​kimi-code/​dist-web/​assets/​arc-DFUn5jA9.js 更新圆弧绘制依赖引用。
apps/​kimi-code/​dist-web/​assets/​abnfDiagram-VRR7QNED-B6ExU0Bo.js 更新 ABNF 图依赖引用。
.changeset/​web-interaction-polish.md 添加 Web 更新发布说明。
.changeset/​task-ws-events.md 说明任务状态迁移至 WebSocket。
.changeset/​task-output-watch.md 说明输出订阅与任务控制请求。
.changeset/​remove-rest-task-api.md 说明 REST 任务接口删除及替代方式。

Review effort: Balanced

listed = new Set();
state.listedTaskAgents.set(target, listed);
}
const agentIds = new Set([...feed.agentIds(), ...Object.keys(spec).filter((id) => id !== '*')]);
listed = new Set();
state.listedTaskAgents.set(target, listed);
}
const agentIds = new Set([...feed.agentIds(), ...Object.keys(spec).filter((id) => id !== '*')]);
this.agentId = result.agentId ?? this.agentId;
this.stateReason = undefined;
this.resultSummary = result.result;
await sink.settle(settlementOf(result));
wbxl2000 added a commit that referenced this pull request Nov 2, 2026
Keep the queue frame next to the task frames from #4535. The web dist
is taken from main for now and resynced in the next commit.
@github-actions github-actions Bot mentioned this pull request Nov 3, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
First half of upstream MoonshotAI#4535: the engine now publishes the events the
WebSocket task frames need. `IAgentTaskService` gains
`onDidChangeTask` (fired on registration, foreground detach, terminal
settlement and an explicit `refresh`) and `onDidAppendOutput` (one chunk
per append, carrying the chunk's byte offset), plus a `detachable`
registration option. `AgentTaskPersistence` gains
`readTaskOutputTailBytes`, which returns a byte window and its offset for
callers that stream output rather than render a preview. The subagent
task info also carries `swarmIndex`, `stateReason` and `resultSummary`,
which the task frames project.

Local shape notes: this branch already had a private
`readTaskOutputTail(location, taskId, previewBytes)` returning a decoded
string, so the new byte-window reader is named
`readTaskOutputTailBytes` instead of taking that name. Task output is
otherwise unchanged: `TaskTerminated.outputTail` stays in place until the
second half removes it together with the REST task route.

Also fixes a type error in the MoonshotAI#4544 test port that only `tsc` catches:
`mixed[0]` is `WireRecord | undefined` under `noUncheckedIndexedAccess`.

Gates: agent-core-v2 tsc clean, build passes, task suites 257 pass /
1 skip (task, tools, bash, forkTurnSlice), `check:no-comments` and
`check:no-hardcoded-prose` green, oxlint 0 errors.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
Second step of upstream MoonshotAI#4535. A session subscription now also receives
task state as flat frames: `task.list` carries every task an agent is
running at the moment the connection starts receiving that agent, and
`task` carries the full state of one task on every change, so a client no
longer polls the REST task route for progress. `task.output` and the
`task.watch`/`unwatch`/`stop`/`background` requests are not served yet;
only the two event operations are registered, so no client is offered a
control route that has no handler.

`SessionTaskFeed` watches each live agent's `IAgentTaskService` through
the `onDidChangeTask` event added in the engine half, and `taskState.ts`
projects `AgentTaskInfo` onto the wire shape (including the subagent
fields `swarmIndex`, `stateReason` and `resultSummary`).

Local shape notes: `IAgentTaskService` is not re-exported from the engine
root here, so the feed imports it from `agent/task/task`; the broadcaster
sends through the same dropped-frame logger the interaction frames use, so
no new empty catch enters the tree. The broadcaster test's collecting
target now routes `task`/`task.list` into their own bucket, because a
subscription legitimately delivers one more frame than the envelope
counts those tests assert.

Gates: kap-server tsc clean, sessionEventBroadcaster 99 pass,
wsConnectionV1 38 pass, `check:no-comments`, `check:no-hardcoded-prose`
and `check:strict-request-bodies` green.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
Completes the WebSocket side of upstream MoonshotAI#4535. Connections can now
address one task without a session subscription: `task.watch` streams its
output from a byte offset (first chunk bounded by `tail_bytes`,
`since_offset` resumes), `task.unwatch` stops it, `task.stop` stops the
task, and `task.background` releases the tool call that started it. Each
request answers with a `response` frame carrying the task state, and the
frames are served by `TaskRequests` over a `TaskSource` that resumes the
session and restores the agent on demand.

The engine gains `IAgentTaskService.readOutputTail(taskId, maxBytes)`,
which delegates to the persistence layer's byte-window reader added with
the engine half and falls back to the in-memory snapshot when no log
exists, so a watch works for a task that has not persisted yet.

Local shape notes: `TASK_NOT_DETACHABLE` takes 40941 because this branch
already uses 40933 for `PROMPT_OPTIMIZER_BUSY`; the state manifest is
regenerated because the subagent task fields this row projects are part
of the agent state shape.

Gates: kap-server 1405 pass / 9 skip, agent-core-v2 task suites green,
both packages `tsc` clean, `check:no-comments` and
`check:no-hardcoded-prose` green, structural review unchanged except the
regenerated manifest.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
Completes the removal half of upstream MoonshotAI#4535. `GET /sessions/{id}/tasks`,
`GET /sessions/{id}/tasks/{task_id}` and the `:cancel` / `:detach`
actions are gone; the WebSocket `task`/`task.list` frames plus the
`task.stop` / `task.background` requests replace them, so `routes/tasks.ts`,
`protocol/rest-task.ts` and `protocol/task.ts` are deleted, the route
registration and the `tasks` capability entry are removed, and the route
table snapshot follows.

Local shape notes:

- `rest-snapshot.ts` extended `taskSchema` for its `subagents` array, so
  that schema is inlined with the same fields; the snapshot endpoint keeps
  serving live subagents.
- The one legacy e2e assertion on `GET /tasks` is dropped rather than
  rewritten, because that suite is not part of the default run and the
  task surface it covered now lives in the WebSocket protocol.
- `scripts/check-locale-keys.mjs` still listed kimi-inspect after the app
  was removed, which broke the gate; the entry is deleted.
- `TaskTerminated.outputTail` stays: this branch's transcript projection
  accumulates its own task tail, and untangling that is separate work.

Gates: kap-server 1385 pass / 9 skip (the deleted route suite accounts for
the difference), both packages `tsc` clean, `check:no-comments`,
`check:no-hardcoded-prose`, `check:locale-keys`,
`check:strict-request-bodies` and `check:deep-imports` green.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
Server side is complete: engine task events, the task.list/task frames, the task.watch family with output streaming, the engine readOutputTail, and the REST task API removal. Remaining: dropping TaskTerminated.outputTail with the transcript's own task-tail accumulation, and an end-to-end task-frame test.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
The WebSocket task surface is complete and covered by an end-to-end frame test. The row records the one deliberate divergence: this branch keeps TaskTerminated.outputTail and its transcript task tail, which upstream dropped, because that field is part of the transcript contract here and live output now streams over task.output instead.
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.

3 participants