Repository navigation
feat: sync running tasks over WebSocket and drop the REST task API - #4535
Conversation
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 detectedLatest commit: 94113e0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
There was a problem hiding this comment.
💡 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.
|
CI 说明:剩下的失败只有 |
There was a problem hiding this comment.
💡 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
There was a problem hiding this comment.
💡 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.
|
@codex review
|
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
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
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
🟡 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
冷会话恢复后为已订阅 agent 补发任务基线 · New 切换为 off 时清除已关闭 agent 的 listed 标记 · New 保留显式停止的 killed 状态 · New
3 files not reviewed
apps/kimi-code/dist-web/assets/channel-DaJqmihc.js: Generated fileapps/kimi-code/dist-web/assets/classDiagram-OUVF2IWQ-CMTPMXFA.js: Generated fileapps/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)); |
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.
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.
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.
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.
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.
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.
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.


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。SessionTasks把引擎事件和 wire 记录折叠成任务状态,现在改为订阅引擎任务服务的变化事件,SessionTasks删掉。swarm 成员在创建时就登记为任务,不再由服务端从subagent.*事件拼出来。源码(不含测试和文档)+1036 / −1198:agent-core-v2 +326 / −25,transcript +23 / −346,kap-server +687 / −827(其中删掉 REST 任务路由 341 行、
coreEventMap的任务投影 319 行)。协议
和 #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。结构
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 也没有消费它的地方。task.watch修复都保留:连接关闭后跳过排队中的 watch;建立推送出错时回 50001 并释放 watch;首段准备好之后才回复成功;尾部读取遇到写到一半的字符时把这段留给下一段。提交
feat(agent-core):任务变化事件,swarm 成员登记为任务。refactor(transcript):任务从转录里去掉(来自 feat(kap-server): send tasks as task events and stream task output #4362)。feat(kap-server):实时任务帧、task.stop/task.background,删除 REST 任务接口和SessionTasks,更新 API 文档。chore(agent-core):按新的任务字段重新生成docs/state-manifest.d.ts。chore:三条 changeset(实时任务帧、输出与任务请求、删除 REST 任务接口),均为 patch。fix(agent-core):swarm 成员逐个停止(各自的取消信号),不可转后台,并带上模型和思考强度。fix(kap-server):对仍留在前台的任务,task.background回 40933。fix(agent-core):排队中的 swarm 成员被停止时立即结束;并发配置在登记成员之前校验。refactor(transcript):失联提醒和其他注入消息一样保持隐藏,撤掉中途加过的 warning notice 和lostTasks,API 文档里的说明一并删掉。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 重新生成后与合并结果一致。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
snapshot.tasks、taskref、task.upsert等 op)GET /sessions/{id}/tasks、GET …/tasks/{task_id}、…:cancel、…:detachtask.list/task帧和task.stop/task.background。changeset 写明了接口删除,版本级别为 patchtranscript.ops里task.list+task帧task.list里task.watch的应答带最终状态task帧(detached: false)apps/kimi-code/dist-web)kimi web用户lost)lost映射为failed),desktop / web 任务栏的「全部」「最近」会列出它task.watch,应答带outcome: "lost"task.terminatedwire 记录的outputTail(docs/wire-manifest.d.ts)wire.jsonl的外部工具tasks/<id>/output.log,后台任务的完成通知带输出摘要docs/state-manifest.d.ts里的SubagentTaskInfoswarmIndex、stateReason、resultSummarytask.stop/task.background作用于 swarm 成员TaskListTaskList时能看到运行中的成员TaskList才会看到受影响的模块与测试:
taskManager.test.ts(注册、刷新、转后台、结束都发布变化,前台任务也发布);sessionSwarm.test.ts(每个成员登记为调用方的前台任务,跟随挂起和完成);合入 main 后,task、swarm、tools 相关测试 22 个文件 527 条通过。layers.test.ts、store.test.ts去掉任务相关的用例;118 条通过。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。pnpm typecheck、pnpm lint(0 error)通过。端到端在 code-app 配套分支上跑:desktop e2e 的后台 bash、后台 subagent、任务与待办三个流程在本地连续两次全部通过,帧序列(前台任务帧 →task.background→ 带状态的应答 →task.watch→ 输出 → 结束帧)在 trace 里核对过。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.(只有 server API 参考文档受影响,已手动更新中英两份;CLI 用户文档里的后台任务描述没有变化)