Skip to content

feat(kap-server): stream agent conversations as turns and items - #4663

Merged
wbxl2000 merged 74 commits into
mainfrom
qer/turn-item-events
Nov 6, 2026
Merged

wbxl2000 merged 74 commits into
mainfrom
qer/turn-item-events

Conversation

@wbxl2000

@wbxl2000 wbxl2000 commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

desktop / web 的对话视图以前建立在 transcript 层上:服务端用两套投影生成转录(live 吃总线事件,冷读吃 wire 记录),再靠回填、overlay、轮结束后 heal、撤销后 reset 把两边对齐,经 transcript.ops 增量推给客户端;客户端为此维护 seq、缺口检测、空 reset 重试,以及按文本和时间配对本地气泡。本 PR 按 KAP 草案把 agent 的对话改成"轮 / 条目":服务端对 agent 的持久化记录只做一次折叠,实时、重启后恢复、撤销、冷读共用这一个函数,页和事件都经同一个投影输出草案里的形态;WebSocket 按 agent 推送 turns 页和 turn.* / item.* 事件;整个 transcript 包删除。

客户端配套:MoonshotAI/kimi-code-app#1130。连接层的信封改名(subscribe / request_id / response)和 prompt 提交接口不在本 PR,留给下一组。

Bug Reproduction Steps

N/A(协议替换)。

Root Cause

N/A

Code Changes

核心思路

  • 一个折叠,一套表示:applyConversationRecord(state, record) 输入 agent 的 durable wire 记录,直接产出协议形态的轮和条目(ConversationTurn / ConversationItem),作为可撤销 participant 挂在 agent 的 event dispatcher 上;会话评分也经同一个回放读取。每个协议字段在决定它的记录到达时算好,conversationItems.ts 只放这些字段的构造函数;状态里除了轮,只有安排后续记录用的簿记:未结束的步骤、工具与交互的关联、撤销锚点。页直接从轮里切,事件直接比较协议对象,只在分页时把 blobref: 媒体换成加载后的地址。
  • feed 跟着 dispatcher 的回放走:引擎给 durable participant 加了两个钩子:重新回放前调 onWillReplay(),每次回放(首次恢复、撤销、重跑)结束后调 onDidReplay(state, { ok })。feed 据此在重跑期间暂停出页,GET .../turns 和订阅页都等回放结束再返回;回放结束时把 agent 已经不在运行的轮收尾为 interrupted / aborted,再拿结果和已推送的状态做差分:消失的轮用 turns.removed 推送,保留下来的轮只推有变化的部分;首次回放失败时 feed 的 ready 失败,订阅方收到 turns.failed;重跑回放失败时保留回放前的历史。之前靠 restoring 标记、ContextUndone 事件和 isActive 判断拼出来的恢复流程全部删除。
  • feed 的生命周期归 ConversationService 管:每个 agent scope 一创建(restore 之前)就挂上 feed,agent 关闭时销毁,会话 scope 销毁时整体清掉;新 feed 会通知 broadcaster,由它给订阅了这个 agent 的连接重新挂接并下发一页 turns。所以 agent 不论经哪条路径被恢复(Agent 工具、直接 prompt、任务请求、调试接口),订阅都不会失效。
  • 订阅只记在 broadcaster 一处:每个连接订阅了哪些 (会话, agent) 只存在 broadcaster 里,连接对象不再镜像一份,订阅进行中关闭连接也不会残留。subscribe_v2 是追加:新加入的 agent 先收到一页 turns(或 turns.failed),之后是 turn.* / item.* / notice。会话被接受时立即回 ack,页随后到达;会话打不开时 ack 带真实错误码(40401 同时列进 not_found,40930、40931 等说明原因),什么都不订阅。
  • 删除轮:撤销和清空上下文之后,服务端用 turns.removed { turn_ids } 推送被删的轮(按 ordinal 升序),客户端按 id 删除;turns 页只在开始订阅(包括重连、agent 重新加载)时发送。撤销按整轮进行:POST :undo { turn_id, agent_id? } 删除这一轮及之后的轮,响应 { removed_turn_ids } 与推送的帧一致。
  • 开轮规则:只有消费了匹配 turn.prompt 的用户消息、带轮号的 loop 事件、紧跟 turn.prompt 的老格式 assistant 消息(导入的会话)和 full_compaction.begin 会开出运行中的轮。其他开场(例如 CLI 的 ! 命令和输出、hook 的结果、被 UserPromptSubmit hook 拦下的输入)收不到 turn.ended,现在生成一个立即以 completed 结束的轮,不再隐式结束正在进行的轮;被拦下的输入随后改为 failed / blocked。! 命令在草案的 shell 轮上线前按原始文本显示,origin 为 system。轮结束时一并丢掉同一轮还挂着的 turn.prompt。提交后没能开始轮的 prompt,状态报 failed,之前显示成 queued。
  • 条目形态:
    • user_message:prompt_ids 只给客户端提交的来源(用户输入、技能激活、插件命令),系统触发为空数组。text、attachments、skills、origin 在折叠时生成:和 prompt 列表一样用引擎的 stripBundledSkillBlocks、isUserPromptSubmitHookPart 去掉打包技能的说明块和 hook 块,origin 按 kind 白名单只保留展示字段,服务端路径不下发。
    • tool_call:运行中带 stage(input / awaiting_approval / executing),等待审批时带 interaction_id;审批和提问的卡片只来自 interaction 帧,条目里不再嵌交互对象。ExitPlanMode 的 display 是折叠根据交互请求和回应算出的 plan_review,所以本 PR 早先加的 /plans 路由删除了。
    • notification:服务端把引擎的任务通知解析成结构化字段(标题、正文、级别、类型、来源、任务、agent、输出预览;提问任务的内联回答也算输出),客户端不再解析通知文本。
    • system:完成的压缩是 compaction 条目,轮中压缩放在本轮,空闲压缩单独成 system 轮;被取消或失败的压缩不留条目,改发一条 notice。分叉出来的 agent(侧边对话、fork)以一个带 fork_boundary 的 system 轮开头,继承来的记录不显示。
  • 轮的状态:outcome 之外用 end_reason 说明结束原因(用户停止为 user_cancelled,回放结束时收尾的为 aborted,此外还有 max_steps、error、filtered、blocked);请求重试的状态挂在运行中的轮上(turn.updated { retry });压缩期间 agent 帧的 status 是 compacting。
  • 正在生成的内容:feed 订阅总线增量,按"步骤 uuid + 块号"在内存里攒运行中的条目。块号由引擎给出、与落盘的 content.part 一致,所以运行中条目和最终条目是同一个 id。文本增量经 item.delta { field } 推送,工具的阶段、进度等变化经 item.updated { set } 只推改动的字段。同一步里下一段内容开始时,前面运行中的文本 / 思考条目立即结束;请求重试重置这一步时,运行中的条目用 item.removed 移除。
  • 思考时长:引擎在 content.part 上记下这一块第一个增量的时间和流式时长,reasoning 条目据此给出 started_at / duration_ms;没有这两个字段的老记录用"步骤开始 → 记录写入"兜底,content.part 写在工具执行之前,所以兜底值也不含审批等待和工具耗时。
  • prompt id:打包技能的提交可以带 prompt_id,/skills/{name}:activate 新增 prompt_id,和普通提交一样预留防重;客户端因此对所有气泡都按 prompt_ids 配对。
  • 搜索:限定会话的搜索也统一走持久索引,响应去掉 source。

协议

client → server  subscribe_v2   { session_id, agent_ids? }      # adds agents; agent_ids defaults to ["main"]
                 ack: code 0 { accepted: [sid] } | code 40401 { not_found: [sid] } | other code + msg
client → server  unsubscribe_v2 { session_id, agent_ids? }      # without agent_ids drops the session

every conversation frame carries { type, session_id, agent_id, event_created_at }
  turns          { turns, has_more }              # latest 10 turns within 1 MiB, on subscribe; replaces the agent's history
  turns.removed  { turn_ids }                     # turns left after an undo or a context clear, in ordinal order
  turns.failed   { code, msg }                    # the agent's conversation cannot be loaded
  turn.started   { turn }                         # turn header without items
  turn.updated   { turn_id, step?, retry? }       # one ended step, or the retry state (absent retry clears it)
  turn.ended     { turn }
  item.started   { turn_id, item }
  item.delta     { turn_id, item_id, field: "text" | "input_text" | "output", delta }
  item.updated   { turn_id, item_id, set }        # changed tool_call fields
  item.ended     { turn_id, item }
  item.removed   { turn_id, item_id }
  notice         { level: "info" | "warning" | "error", title, detail?, code? }

turn = { turn_id, ordinal, kind: "agent" | "system", status: "running" | "ended",
         outcome?: "completed" | "interrupted" | "failed",
         end_reason?: "user_cancelled" | "aborted" | "max_steps" | "error" | "filtered" | "blocked",
         error?, retry?, turn_number?, started_at, ended_at?, duration_ms?, usage?, steps, items }

item = { item_id, step_index?, status, outcome?, created_at, debug? } plus one of   # debug only with KIMI_CODE_DEBUG=1
  user_message       { prompt_ids, placement: "opener" | "steer", origin, text, attachments, skills, metadata? }
  assistant_message  { text }
  reasoning          { text, started_at, duration_ms? }
  tool_call          { name, stage?, input?, input_text?, display?, output?, media?, error?, progress?,
                       interaction_id?, agent_refs?, started_at, ended_at? }
  notification       { notification_id, title, body, severity, notification_type, source, task_id?, agent_id?, output? }
  system             { kind: "compaction", trigger, ... } | { kind: "fork_boundary", source: "btw" | "fork", forked_from }

agent frame  status: "idle" | "running" | "compacting"

GET  /sessions/{id}/agents/{agent_id}/turns?before_ordinal=&page_size=   → { turns, has_more }   # page_size 1..200, default 50, within 1 MiB
POST /sessions/{id}/prompts                  prompt_id also with skills; a prompt that fails before its turn reports "failed"
POST /sessions/{id}/skills/{name}:activate   + prompt_id
POST /sessions/{id}:undo   { turn_id, agent_id? } → { removed_turn_ids }   # 40421 unknown turn, 40911 not undoable, 40901 busy
POST /search                                 results without source
  • turn_id 形如 t_ 加 12 位十六进制,由 agent、ordinal 和开始时间算出:在会话内唯一,重新回放后不变,不复用。ordinal 是轮在当前历史里的位置,撤销后可能复用;turn_number 是引擎轮号,文件变更、分叉、评分继续用它。条目没有 index,按追加顺序排列。
  • 工具条目结束时,结果是错误的为 failed(带 error,不带 output),没拿到结果就随轮结束的为 interrupted。
  • notice 来自总线上的 warning / error 事件,只实时推送,不进轮。
  • 事件可能重复 turns 页里已有的内容,客户端按替换处理即可。

结构

 packages/agent-core-v2/src/
   human/llm/message.ts, human/agent/turn.ts            # accumulator reports the content block of each streamed part
   agent/loop/machine/engine.ts, turnEvents.ts          # block on deltas, turn.step.stream_reset
   agent/loop/loopService.ts                            # block, startedAt, durationMs on content.part
   state/eventDispatcher.ts, eventDispatcherService.ts  # onUndo, onWillReplay, onDidReplay for durable participants
   features/skill/skillService.ts                       # promptWithSkills and activation take promptId
 packages/kap-server/src/
+  protocol/conversation.ts                             # turn / item / frame schemas
+  services/conversation/conversationFold.ts            # the single fold: wire records straight into protocol turns and items
+  services/conversation/conversationItems.ts           # builders for protocol items and fields from engine data
+  services/conversation/taskNotifications.ts           # engine task notifications to notification items
+  services/conversation/conversationFeed.ts            # per-agent participant, replay lifecycle, running items, events
+  services/conversation/conversationService.ts         # feed per agent scope; rating read
+  routes/conversation.ts                               # GET .../agents/{agent_id}/turns
   services/messages/messageProjection.ts               # user content and origin projection shared with the prompt list
   routes/prompts.ts, routes/skills.ts                  # prompt_id with skills and on activation, failed prompt status
   transport/ws/v1/sessionEventBroadcaster.ts           # the only subscription record; pages, replaced feeds, ack outcomes
   transport/ws/v1/wsConnectionV1.ts                    # agent_ids instead of transcript grades
   transport/ws/v1/agentState.ts                        # status idle / running / compacting
   search/searchService.ts                              # session-scoped search through the index only, no source
-  services/transcript/, routes/transcript.ts
- packages/transcript/
旧路径的功能清单与新位置
旧路径做的事 新位置
live 投影:coreEventMap 把总线事件映射成转录 op 折叠读 durable 记录;流式内容由 feed 按"步骤 + 块号"攒
冷读:groupTurns + foldFacts + readColdSnapshot + wireCache 同一个折叠,由 dispatcher 回放;评分也走回放
1.4 版会话的压缩记录(complete 先于 apply)合成一个压缩 marker 摘要合并进刚完成的压缩条目,仍是一个压缩
懒建 store 时的回填、overlay、轮结束后 heal 不再需要:feed 随 agent scope 创建,回放时就建好状态
撤销后的 reset op 回放结束后差分,被删的轮用 turns.removed 推送
分页 GET /transcript?before GET .../agents/{agent_id}/turns?before_ordinal&page_size
GET /transcript/plan ExitPlanMode 工具条目的 display(plan_review),由折叠根据交互请求和回应算出
GET /transcript/ops、GET /transcript/user-messages 删除,code-app 和本仓都没有调用方
subscribe_v2 的 per-agent grade:决定一个连接收哪些 agent 的转录和 task / agent / usage / goal / todo 帧 agent_ids:同一份"连接收哪些 agent"的记录,只存在 broadcaster 里
首个转录连接时回填技能激活、排队 prompt 的元数据 技能激活信息随 user_message.origin / skills 从记录里读出;排队的 prompt 不进对话(main 上由客户端本地管理队列)
转录里的 prompt 实体(客户端拿来配对回显、判断插话) user_message.prompt_ids;打包技能与 /skill 激活现在也带客户端 prompt id
用户 origin 投影:user / skill_activation 只给展示字段 所有 kind 按白名单投影成草案里的 origin
交互播种(待处理交互写进转录) 工具条目的 stage: awaiting_approval + interaction_id;待处理交互照常在订阅确认后补发
崩溃后留下的未结束轮和交互:冷读时标为取消 回放结束时收尾为 interrupted / aborted,运行中的工具条目随之结束
任务通知:转录带原始通知文本,客户端解析 服务端解析成结构化的 notification 条目;老会话里解析不出通知块的纯文本保留为通知正文
warning / error marker notice 事件
压缩 marker 完成的压缩是 compaction 条目;压缩期间 agent 帧为 compacting;没完成的压缩发 notice
失败信息(客户端从 notice 里找) turn.error 和 end_reason,取自 turn.ended 记录
分叉 agent 的转录带着继承来的历史,客户端自己隐藏 以 fork_boundary 轮开头,继承的记录不显示
轮序号兼作引擎轮号(冲突时 allocateExportTurn 另分配) 不透明的 turn_id、表示位置的 ordinal 与引擎的 turn_number 分开
搜索 live 会话:读 transcript store 的 prompt 和助手正文(含正在流式的文字) 统一读持久索引(维护者决定),流式中的文字在这一步落盘、索引追上后才能搜到
会话级 binding 在每个 agent 创建时(onDidCreate)订阅它,子 agent 被淘汰后再恢复,已有订阅照常收到 ConversationService 在每个 agent scope 创建时挂 feed 并通知 broadcaster
评分:会话未加载时冷读最新主轮,只有轮次对上才加载会话 同样不加载会话,读法换成折叠;完整但损坏的 wire 行直接报错,只容忍末尾半行
#4638 的读取版本检查 历史读取经引擎 restore 检查;评分的未加载读取先校验版本;/turns 和评分返回 40930,订阅的 ack 同样带 40930
main 上的修复:给非主 agent 提交 prompt 前先建好它的转录,侧边对话第一条回答不丢 不需要这一步:feed 在 agent scope 创建时(restore 之前)就挂上;测试改为读 /agents/{agent_id}/turns 验证同一场景
main 上的修复:分叉会话里继承的轮占了第一个引擎轮号时,改写后的轮序号不撞号 不存在这个问题:ordinal 按顺序分配、不随引擎轮号改写,继承的记录不显示;补了轮次唯一且有序的测试

提交

按主题分组(共 55 个,另有两次合并 main):

  • 引擎:942c1c27f 流式内容块编号并记录时长;9d3628331 可撤销 participant 自己处理撤销;649c08b9b 打包技能提交和技能激活接受调用方的 prompt id;bca13fdf6 durable participant 的回放钩子。
  • 对话改为轮 / 条目:95d616866 主体(删除 transcript 包、服务、路由和 WebSocket grade,feat(agent-core-v2): enforce minimum wire reader version #4638 的版本检查移到新读取路径,更新 apiSurface 快照、flake.nix、AGENTS.md)。
  • 第一轮评审跟进:37530d44c、2eefaa6eb(feed 生命周期归 ConversationService,订阅的明确结局与 turns.failed,共享的用户消息投影),ca16c56ba、924dc959f。
  • 回放生命周期与状态收敛:cefe84704 feed 跟着回放走;455620112 只有拿到 turn.prompt 的开场才开运行中的轮;cb2d96276 订阅只记在 broadcaster;01706ede2、17567441b prompt 的 failed 状态与挂起 prompt 的清理;e9dca2709 首次回放失败的测试;0f489c94e、03a715a21 清空上下文和部分裁剪的撤销都重发整页;9b83fc28f 重跑期间不出页;665058007 提问任务的内联回答;242855ec9 老会话里纯文本的任务消息保留为通知正文;8f5ea06ac 重跑回放失败时保留原有历史;ad5c8bf73 缺字段的老格式 cron 来源给出默认值;0ec35d7dc 分页只为留在页里的轮加载媒体;3dea42677 1.4 版记录顺序的压缩摘要合并进已完成的压缩;36fc42bff CLI 的 ! 命令重新按原始文本显示。
  • 按草案对齐形态:833ebd252 轮和条目;8b62d2d6a 分页参数与 1 MiB 上限;b3502bee8 压缩状态与 agent 帧;0b439d8eb 搜索去掉 source。
  • 合并 main:83358028d 合并了 fix(tui): keep wrapped Grep and Glob glance lines indented #4617、docs(changelog): sync 2.5.0 from apps/kimi-code/CHANGELOG.md #4673、chore: sync release/2026-11-04 back to main #4674。main 在已删除的 transcript 包里有两处修复,在新路径里的对应位置见下方旧路径清单的最后两行;8f088acd2 去掉 prompt 路由里对 transcript 服务的调用并移植它的测试,3c19c91fa 补上分叉轮次唯一且有序的测试。247df07a4 合并了 feat(tui): fold tool calls and thinking into transcript groups in fullscreen #4618、perf(tui): reuse unchanged tool output lines across renders #4665、docs: rewrite remote environment guide for users #4693、chore: sync web dist from code-app #4685,冲突只在 dist-web,保留本分支的产物。
  • 一套表示:6eb08f029 折叠直接产出协议形态,去掉投影层;用本机约 3,600 份 agent 对话记录对比新旧实现,结果一致,只有一份旧引擎在同一步号上跑了两步的记录取舍不同(现在保留后结束的那一步)。fc6e1a282 工具调用 id 跨轮复用时把审批挂到新调用上,是对比时发现的旧问题。b188f087c 文档写明 CLI shell 命令的轮。
  • 精简测试:770751154 删掉本 PR 新增测试中的大部分,只保留核心用例和从 main 改写过来的场景;e64fe5df1 补回上一步误删的 S3(审批)场景;f2ee649e9 保留分叉轮次唯一且有序(对应 main 的修复)和思考时长(对应下表的行为变化)两个用例。
  • 文档:3b6ea1df9、8aa4c9a3a、d86b7d1c7、156419f54(docs/en|zh/reference/server-api.md)。
  • changeset:9c617765a、1a2417190、967a7474a、8562f9c14。
  • 本轮跟进:d354d9039 边界情况对齐文档;cb20c878d、685e2e5ac 附件文件结构化为 file 附件、不含服务端路径;ec4e79795 步骤不再带计时;375f0c364 条目的请求调试信息(仅 KIMI_CODE_DEBUG=1)与撤销后清理工具记录;cddcf11a3 用 turns.removed 取代整页重发,去掉内部 reset;9c9a2330e 撤销按 turn_id 对齐草案。
  • web 产物:拆到 chore: sync web dist from code-app #4700(叠在本 PR 上,由 MoonshotAI/kimi-code-app#1130 构建)。本 PR 早先的九次 dist 同步已由 edf3ab717 还原成 main 上的产物,本 PR 不再改 apps/kimi-code/dist-web。

Behavior Changes and Affected Users

行为 之前(main) 之后 依赖旧行为的人群 退路
subscribe_v2 的 payload transcript(per-agent grade)、transcript_since agent_ids(追加,默认主 agent) main 上的 desktop / web;订阅转录的外部脚本 客户端随配套 PR 一起改;desktop 内嵌 server 随包发布。changeset 写明了删除
订阅失败时的 ack code 0,会话打不开一律 not_found;主 agent 加载失败只记日志 带真实错误码,只有 40401 列进 not_found;主 agent 加载失败也让订阅失败 按 not_found 判断的外部脚本 无;客户端已按错误码处理
ack 的时机 首批转录数据发完后才回 会话被接受时立即回,页随后到达 把"收到 ack"当作"数据已到齐"的外部脚本 无;以 turns 帧为准
某个 agent 的对话加载失败 只记日志,不发任何帧 turns.failed { code, msg } 无 —
WebSocket 对话帧 transcript.* 快照与 op turns、turns.failed、turn.*、item.*、notice,形态见上 同上 同上
撤销、清空上下文后的推送 reset op turns.removed { turn_ids },客户端按 id 删除;重连后重新订阅收到最新一页 turns 同上 同上
POST /sessions/{id}:undo { count, page_size? } → { messages } { turn_id, agent_id? } → { removed_turn_ids };未知轮 40421,开场不是用户输入或跨过压缩 40911 desktop / web(与服务端同步发布,配套 PR 已改);CLI 走 SDK,不用这个接口 无
REST 转录接口 GET /sessions/{id}/transcript、/transcript/ops、/transcript/plan、/transcript/user-messages 删除(404) 调用它们的外部脚本;desktop / web 已在配套 PR 改 GET .../agents/{agent_id}/turns;计划从 ExitPlanMode 工具条目的 display 读
task / agent / usage / goal / todo 帧发给谁 grade 不为 off 的连接 订阅时列在 agent_ids 里的 agent 同上 同上
agent 帧的 status idle / running 压缩期间为 compacting 按 running 判断忙碌的外部脚本:压缩期间不再是 running 无;changeset 写明
提交后没能开始轮的 prompt(例如被 gate 拒绝) prompt 状态显示 queued failed 无 —
打包技能提交带 prompt_id 40001 接受,与普通提交一样防重 无 —
/skills/{name}:activate 无 prompt_id 可选 prompt_id,重复时 40927 无 —
搜索响应的 source live / index 删除,限定会话的搜索也只走索引 读 source 的外部脚本;开启了全局搜索(默认关闭)的用户在流式中的文字落盘前搜不到 无;维护者已确认
用户消息的 origin user / skill_activation 只给展示字段,其余 kind 原样 所有 kind 投影成草案里的 origin,不含服务端路径 读 origin 其他字段的外部脚本 无
重试和系统触发消息的文本 转录不显示 条目 text 为空,origin 标明来源 无 —
CLI 的 ! 命令 转录把命令和输出显示成带 <bash-input> / <bash-stdout> 原始标签的用户消息 同样按原始文本显示为用户消息,每条单独成一个立即结束的轮,origin 为 system,客户端不提供撤销(引擎本来就不把它们算作撤销锚点) 在 desktop / web 里查看 CLI 会话的用户 —
工具调用 id 跨轮复用,且新调用的审批先于调用记录到达 审批挂在上一轮同 id 的已结束调用上,新调用不显示审批 新调用在自己的轮里显示等待审批 无 —
服务重启后上次没结束的轮 没有 turn.ended 的轮不收尾,只有未结束的审批 / 提问冷读时标为取消 回放结束时收尾为 interrupted / aborted,运行中的工具条目随之结束(只在投影里,不写回 wire) 无 —
侧边对话、fork 出来的 agent 转录带着继承来的历史 以 fork_boundary 轮开头,继承的记录不显示 无;desktop / web 本来就隐藏继承的历史 —
被取消或失败的压缩 转录里留一个压缩 marker 不留条目,发 notice { code: "compaction.cancelled" } 无 —
content.part wire 记录 无块号 带 block、startedAt、durationMs 读新会话的旧版本:多出的字段被忽略 —
中途订阅正在流式输出的 agent main 的 transcript 懒建,靠轮结束 heal 补齐 订阅页里直接带上这一步已输出的内容 无 —
思考时长 没有,客户端自己估 reasoning.started_at / duration_ms;老记录用"步骤开始 → 记录写入"兜底 无 —
读已关闭会话的历史(REST) GET /transcript 冷读,不恢复会话 GET .../agents/{agent_id}/turns 恢复会话后再读,与 /messages 相同;desktop / web 读历史时本来就已订阅(订阅会恢复会话),不受影响 直接调 REST 读历史的外部脚本 无;维护者已确认
会话评分 未加载时冷读转录的最新主轮,轮次对上才加载会话 同样不加载会话,读折叠的最新主轮;wire 中完整但损坏的行返回错误 kimi web 的评分 —
内置在 CLI 里的 web 产物(apps/kimi-code/dist-web) 走转录协议 按新协议构建的产物在 #4700 同步,本 PR 不改产物 kimi web 用户:只合入本 PR 时 web 仍是旧产物,和新协议对不上 #4700 紧接着本 PR 合入
旧版本写的会话 groupTurns + foldFacts 冷读 同一个折叠按老格式规则读(没有轮号的 turn.prompt、legacy 撤销、legacy assistant / tool 消息;隐式结束仍记为 completed) 有历史会话的所有用户 —

TUI、print 模式、SDK、ACP 和 VS Code 插件都不读转录,不受影响。契约文件里只有 apiSurface 快照变化(新增 /agents/{agent_id}/turns,删除 4 个 transcript 路由);docs/*-manifest、node-sdk 入口、externalHooks、acp-server、apps/kimi-code/src/cli 都没动。klient 的 promptWithSkills 契约本来就带可选 promptId,现在引擎会采用它,契约本身没改。

受影响的模块与测试(本 PR 新增的测试只保留核心用例;main 上原有的场景按新协议改写后保留):

  • agent-core-v2:turn.test.ts 累加器报块号;loop.test.ts 增量与 content.part 带块号;eventDispatcher.test.ts 带 onUndo 的 participant 自己处理撤销,回放钩子包住每一次恢复(包括失败的);activateSkill.test.ts 打包技能与技能激活采用调用方的 prompt id。
  • kap-server services/conversation.test.ts(26 个):折叠规则(条目按步骤和块排序、用户消息的可见文本 / 技能 / 客户端元数据且不含服务端路径、origin 映射、CLI ! 命令、轮的结局与结束原因、turn_id 稳定、思考时长与兜底、插话放在运行中的轮、任务通知、交互与子 agent 关联、工具调用 id 跨轮复用时审批挂到新调用、计划审阅、压缩、分叉的 fork_boundary 与轮次唯一且有序、无主消息不结束运行中的轮、legacy 撤销与消息),回放结束时收尾悬挂的轮,feed(首次回放失败、重跑回放失败时保留历史、回放与清空上下文推送 turns.removed、先发轮再发条目、工具的各个阶段、1 MiB 分页),以及 wire 中损坏的行。
  • kap-server conversationContract.e2e.test.ts:由 main 的 transcriptContract.e2e.test.ts 改写的 10 个场景(S1–S7、S9、S10 和撤销),本 PR 早先额外加的 8 个场景已删除。
  • kap-server 其他:wsConnectionV1.test.ts ack 的 40401 与 40930、agent_ids 的订阅与退订;sessionEventBroadcaster.test.ts ack 先于内容、每个 feed 只发一页、agent 重建后跟随新的 feed 并报告加载失败;prompts.test.ts、skills.test.ts 打包技能与技能激活的 prompt_id、没开始轮的 prompt 为 failed;sessionRating.test.ts 评分不加载已关闭的会话;searchService.test.ts 删除 live 路径的用例;sessions.test.ts feat(agent-core-v2): enforce minimum wire reader version #4638 的不兼容会话用例补上 /agents/main/turns 和评分返回 40930,以及从 main 移植的"侧边对话的第一个 prompt 早于任何读取时回答不丢";migration-legacy resume.integration.test.ts 改用新折叠。
  • 验证:第一次合并 main 后,根目录 pnpm lint(0 error)、pnpm typecheck 通过,pnpm test 的 5 条失败都在 agent-core-v2 且与本 PR 无关(tool.test.ts 与 tower store.test.ts 各一条在本机稳定失败、撤掉本 PR 的改动后同样失败,另外三条在负载下超时、单独重跑通过)。精简测试和第二次合并 main 之后,pnpm typecheck、check-no-comments 和提交时的 oxlint 通过,改动过的测试文件全部通过(kap-server 4 个文件 141 条,其中契约测试 10 条;agent-core-v2 3 个文件 116 条)。改成一套表示之后:kap-server 全部 70 个测试文件 1306 条通过,tsc、check-no-comments、oxlint 通过;另用本机约 3,600 份 agent 对话记录(共约 177 万条 wire 记录)分别喂给新旧实现,逐份比较最终的轮,并抽样逐条记录比较最后一轮,差异只有上面说的两类。
  • 手动冒烟(本分支 server + 配套客户端分支的 web):工具调用;运行中插话只显示一次;审批经 interaction_id 关联,批准后继续;拒绝后工具显示失败;停止运行中的命令后轮为 interrupted / user_cancelled;撤销后收到 turns.removed,按钮和 /undo 都按 turn_id 撤销;刷新后历史一致;每一轮只结束一次;侧边对话以 fork_boundary 开头,只显示自己的输入。

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.

The turn machine's message accumulator now reports which content block each
streamed part lands in. The block index rides on the turn machine's forwarded
parts, the engine delta, and the assistant.delta and thinking.delta events,
and is written on every content.part record, so streamed blocks and persisted
parts share one identity. Each content.part record also carries when the
block's first delta arrived and how long the block streamed (startedAt and
durationMs), so a reasoning block's duration survives a reload.

The loop's salvage buffer now groups parts by that block index instead of
re-deriving boundaries, which leaves the accumulator as the only place that
decides block boundaries. A request-level attempt retry now resets the step's
stream: the turn machine signals step.stream_reset, and the loop drops its
salvage buffer and publishes turn.step.stream_reset.
Replayable state keys and agent models can declare a custom onUndo; durable
runtime participants could not, so an undoable participant never saw the
undo-anchor user messages (they were swallowed for checkpointing) and had no
way to fold the user's input.

A participant may now pass onUndo: anchors reach its transition like any
other message, and unpaired legacy context.undo records call onUndo instead
of rolling back to a checkpoint. Participants without onUndo keep the
checkpoint behaviour.
An agent's conversation is now one fold over its durable wire records,
attached to the agent's event dispatcher as an undoable participant. The
same fold serves live sessions, replay after a restart, undo (the dispatcher
replays the active branch and the feed reports removed turns), and a cold
read of the wire file for session rating.

The WebSocket subscription takes agent_ids and sends a turns frame with the
latest page, then turn.started/updated/ended, item.started/updated/ended,
item.delta, item.removed, turns.removed and notice frames. Streamed text is
held per step and block, so a running item and its persisted content share
one id. A running text or reasoning item ends as soon as the next block or
tool call of its step starts. Reasoning items carry started_at and
duration_ms from the streamed block timing; records written before block
timing fall back to the step start and the time the part was recorded. The
agent frame now carries the running turn and prompt, compaction and request
retry state.

REST serves GET /sessions/{id}/agents/{agent_id}/turns and .../plans. The
transcript package, its service, routes and WebSocket grades are removed.
code-app: 2c088fdc599a4205ad186ec74fafee1b9462d9d2
@changeset-bot

changeset-bot Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ef90dbd

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 4, 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-06T03:38:40.252381Z ef90dbd 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 4, 2026 •

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

commit: ef90dbd

@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: 9c617765a6

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

…on feeds

User items drop bundled skill instruction blocks with the same filter the
prompt list applies, so a prompt with bundled skills no longer shows the
skill body as the user's text.

An undo that keeps a turn but cuts items from it (a legacy steer anchor)
now sends item.removed and the changed items of that turn, not only the
removed turns.

Search on a live session covers every agent in the session metadata and
reads agents that are not loaded from their wire file, as the transcript
store did through its history backfill.

A conversation subscription follows its agent across eviction and resume:
subscribing again, or a subagent.started event, reattaches the feed when
the agent's handle changed.
code-app: c3f49a097d3b0ed28c3b951b9d837cc9a31652d2

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

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

…take a caller prompt id

promptWithSkills and skill activation accept an optional promptId and
submit the user message under it, the same way a plain prompt does, so a
client can pair its optimistic message with the echo by id. Without a
promptId the loop still mints one.
…ription outcomes explicit

ConversationService now creates a feed for every agent scope as the
scope is created, attached before its restore, disposes it when the agent
closes and drops a session's feeds when the session scope goes away. Each
new feed is announced to the broadcaster, which attaches the connections
subscribed to that agent and sends them a fresh turns page, so an agent
restored by any path keeps streaming to its subscribers, and a subscriber
that joins mid-step sees what the step has already streamed. This replaces
the SubagentStarted reattachment and the per-connection feed comparison.

subscribe_v2 reports the outcome: a session that cannot be opened acks
with the error code (40401 also lists it in not_found) instead of a bare
not_found, a main agent that fails to load fails the subscription, and an
agent whose conversation cannot be loaded gets a turns.failed frame with
the code and message. The turns and plans routes map the same errors.

After an undo the feed resends the latest turns page instead of diffing
the restored turns.

User messages are projected by one function shared with the prompt list:
bundled skill instructions and hook parts are dropped, retries and
internal triggers other than subagent prompts show no text, and origins
keep only display fields, so server paths in attachments and skill paths
no longer reach clients. Interactions still pending when their turn ends,
or when the agent stopped without ending it, are presented as ended.

Bundled skill submissions accept prompt_id and skill activation takes
prompt_id, reserved like a plain prompt.

Session-scoped search goes through the index instead of reading live
conversations. Rating keeps reading a closed session without loading it,
and that read now rejects corrupted complete wire lines while tolerating a
torn last line.
code-app: 4b94754ad85707ef4fea72bb1d941a87e5434cd8

@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: 73cb74b20b

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

…ol outputs

The hydration check only looked for image URLs, so a tool output whose only offloaded media was video or audio reached clients as a raw blob reference. It now checks every media URL that loadParts rewrites.

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

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

@chatgpt-codex-connector

Copy link
Copy Markdown

💡 Codex Review

endTurn(state, previous, state.provisionalOutcomes[previous.turn_id] ?? 'completed', time);

P2 Badge Preserve interrupted outcome when opening the next turn

When a restored session contains a turn without turn.ended—for example, after the process crashes during generation—the snapshot initially presents that turn as ended/interrupted, but submitting the next prompt reaches this fallback and rewrites the same durable turn as completed. REST and WebSocket history therefore change an interrupted response into a successful one; implicitly closing an inactive replayed turn should preserve the interrupted/failed outcome instead.

AGENTS.md reference: AGENTS.md:L125-L127


return projectPromptContentParts(stripBundledSkillBlocks(message).filter((part) => !isUserPromptSubmitHookPart(part)));

P2 Badge Preserve audio parts in projected user messages

For migrated or older sessions whose user message contains an audio_url part, this new shared projection passes the content through projectPromptContentParts, which emits text, images, and videos but silently omits audio. The replaced transcript fold created a sourced audio attachment for the same record, so conversation reloads now lose the clip entirely—and an audio-only prompt is exposed with empty content; add an audio content projection instead.

AGENTS.md reference: AGENTS.md:L125-L127


if (anchor.itemCount > 0) state.turns[anchorIndex]!.items.splice(anchor.itemCount);

P2 Badge Truncate step metadata when undoing an in-turn steer

When undo targets a steer inside an existing turn after one or more later LLM steps have completed, this truncates the turn's items but leaves turn.steps untouched. The replacement page therefore still exposes the undone steps' IDs, finish reasons, usage, and timing through REST and WebSocket, even though their assistant/tool items were removed; record the step boundary at each anchor and truncate the steps together with the item suffix.

AGENTS.md reference: AGENTS.md:L125-L127

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

…items

Undoing a steer that sits inside a turn cut the turn's items after the
steer but kept the steps that produced them, so the replacement page
still carried their ids, finish reasons, usage and timing. The undo
anchor now records the step count next to the item count and both are
truncated together.
…ooks

Durable runtime participants had no explicit signal for when the
dispatcher replays them. A participant can now implement onWillReplay,
called right before a rerun restore resets its state, and onDidReplay,
called once at the end of every replay pass: the first restore, every
rerun restore and the catch-up of a late attach (for the late
participant only). onDidReplay also runs when the pass fails, with
ok: false, so a participant never stays in a replaying state; the state
it returns is committed when it differs. Hook errors are reported and
do not change the outcome of the restore.
…on feeds

A feed inferred a replay from receiving its initial state object and its
end from the context.undone event that the undo service dispatches last.
When anything failed between the restore and that event, the feed stayed
in its restoring state and silently stopped emitting turn and item
events for the agent. The feed now enters restoring in onWillReplay and
leaves it in onDidReplay, which also resolves or rejects the first
restore, so a failed first replay rejects ready.

Turns that are still running when a replay ends are settled in the fold
as interrupted, together with their running items and pending
interactions, unless the loop or a compaction is actually running them;
the cold read used by session rating settles them the same way. A page
therefore no longer rewrites turns from runtime state at read time, and
the next prompt can no longer end such a turn as completed.

The feed serves one page(before, limit) for REST and WebSocket. A blob
that fails to load keeps its stored reference and is logged instead of
failing the page. Pending persistent diffs are flushed before any live
item event or notice, so a client never sees an item of a turn it has
not been told about.
Any user message that was not a steer opened a running turn and
implicitly ended the open one. Openers without an owner never receive a
turn.ended record: CLI shell commands append their input and output as
user messages, and a prompt that a UserPromptSubmit hook blocks appends
the hook result and the blocked message without a turn.prompt. The last
such turn stayed running forever and hid the real outcome of the turn it
had ended.

A running turn is now opened only by a user message that consumes the
matching turn.prompt, by loop events of a numbered turn, by a legacy
assistant message that follows a turn.prompt (imported sessions), or by
full_compaction.begin. Every other opener gets a turn that ends at once
as completed and leaves the open turn alone. A blocked prompt turns its
already ended turn into blocked. Implicit closes still default to
completed for sessions written before turn.ended existed.

Tests that appended a turn's messages without a turn.prompt now record
one first, as live and migrated sessions do.
Subscription membership lived in three places: the connection's
subscriptions set, the broadcaster's targets and the agents whose lists
it had sent, kept in step by isSubscribed. The connection recorded a
session only after the subscribe resolved, so a socket that closed while
the session was opening left its target registered for good. The ack
waited until every agent's page was loaded and sent while control
frames ran one at a time, so one slow session held back later
subscribes and the pages reached the client before the ack. When a
recreated agent's feed failed to restore, nothing was sent and the old
attachment stayed on a disposed feed.

The broadcaster now owns membership: sessionsOf(target) serves the
connections listing and removeTarget(target) runs on close, and a
connection that closed while a subscribe was opening the session removes
its target once the subscribe returns. A subscribe opens the session,
registers the target and calls back so the connection acks at once, then
sends agent lists and attaches conversations without waiting for pages.
One sync(state, target, agentId) serves subscribe, feed creation and
session reattach: it resolves the agent's current feed, attaches it
unless it is already attached and sends its page, or detaches and sends
turns.failed when the feed cannot load; an unsubscribe or a newer sync
wins over one still loading. The conversation service is now required,
and the broadcaster tests drive it through a fake whose loads and pages
they control.
A prompt whose submission gate fails, for example because a prompt hook
throws or an attachment cannot be materialized, ends without starting a
turn, yet its status was projected as queued. The submit route already
waits for idle sessions until the prompt launches or completes, so it
now reports such a prompt as failed; the prompt status enum gains
failed. Every other state keeps its status.
A turn.prompt waits in the fold until a matching user message or the
turn's loop events open its turn. A turn whose opener the fold skips,
such as an injection, can end before any loop event, leaving its prompt
pending; the next opener that consumes a pending prompt, for example the
hook result of a blocked prompt, then opened a running turn that nothing
would end. A turn.ended record now also drops the pending prompt of the
same turn.

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

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

…er undo inside a turn

With KIMI_CODE_DEBUG=1 the last item of each ended step carries the
finish reason, usage and timing of its model request. An undo that cuts
the items after a steer now resets subscribers, and undone turns drop
their tool and interaction bookkeeping so a reused call id starts clean.
@wbxl2000

wbxl2000 commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review only what is not settled below. These points were decided by the maintainer and answered in resolved threads; do not raise them again:

  • No compatibility paths for older servers or clients. Desktop and web ship together with this server, and chore: sync web dist from code-app #4700 carries the matching web bundle.
  • Intentionally not added: UserPromptSubmit hook markers, plan revision markers, indicators for skills the model loads, replay of tool progress, audio parts in user messages, usage on legacy assistant records, and tool ids recovered from nested interaction requests.
  • Missed-cron origin metadata is deferred to the scheduled-task follow-up.
  • Search reads only the persistent index, with no live overlay, and the search response has no source.
  • Conversation endpoints read from the agent's feed, not cold reads. Notices are live-only frames.
  • When the next turn opens without a recorded turn.ended, the previous turn ends as completed (sessions written before turn.ended existed).
  • prompt_id idempotency holds within one server process; deduplication across restarts is a separate follow-up. The attempt cache is trimmed only on insertion.
  • Attached files become file attachments without server paths, and records without origin.attachments are parsed from the notice text.
  • item.debug is sent only when the server runs with KIMI_CODE_DEBUG=1, on the last item of each ended step; steps carry no timing.

@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: 375f0c3643

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

…ns page

A replay or a context clear is now diffed against what subscribers
already have, and turns that left the conversation go out as a
turns.removed frame. The turns page is sent only when a connection
starts receiving an agent, so the internal reset event, the resend path
and its notice buffering race are gone. The in-turn truncation branch is
dropped: live undo removes whole turns through a replay.

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

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

POST /sessions/{id}:undo takes the turn_id and optional agent_id of the
turn to undo and answers with removed_turn_ids, matching the turns.removed
frame. The feed checks that the turn exists (40421) and opens with user
input (40911), then undoes the anchors from that turn on. Action bodies
that fail validation now answer 40001 instead of an internal error.
@wbxl2000

wbxl2000 commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review only what is not settled below. These points were decided by the maintainer and answered in resolved threads; do not raise them again:

  • No compatibility paths for older servers or clients. Desktop and web ship together with this server, and chore: sync web dist from code-app #4700 carries the matching web bundle.
  • Intentionally not added: UserPromptSubmit hook markers, plan revision markers, indicators for skills the model loads, replay of tool progress, audio parts in user messages, usage on legacy assistant records, and tool ids recovered from nested interaction requests.
  • Missed-cron origin metadata is deferred to the scheduled-task follow-up.
  • Search reads only the persistent index, with no live overlay, and the search response has no source.
  • Conversation endpoints read from the agent's feed, not cold reads; rating reads turns through the same replay and may load a session for a stale evaluate. Notices are live-only frames.
  • When the next turn opens without a recorded turn.ended, the previous turn ends as completed (sessions written before turn.ended existed).
  • prompt_id idempotency holds within one server process; deduplication across restarts is a separate follow-up. The attempt cache is trimmed only on insertion. Skill activation keeps its current enqueue boundary.
  • User message item ids are the client prompt ids; collisions with provider tool call ids are not handled. Internal untracked prompts never reach the prompt snapshot.
  • Attached files become file attachments without server paths, and records without origin.attachments are parsed from the notice text.
  • item.debug is sent only when the server runs with KIMI_CODE_DEBUG=1, on the last item of each ended step; steps carry no timing.
  • The turns page is sent only when a connection starts receiving an agent. Undo and context clear are announced with turns.removed; live undo always goes through a replay, which the feed diffs against what it sent.
  • POST :undo takes { turn_id, agent_id? } and returns { removed_turn_ids } as in the KAP draft (40421 unknown turn, 40911 not undoable, 40901 busy).

@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: 9c9a2330ec

ℹ️ 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 session's attempt map is removed once its last attempt fails before enqueueing, and the whole map goes when the session is deleted, so stored responses no longer outlive their session.
@wbxl2000

wbxl2000 commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review only what is not settled below. These points were decided by the maintainer and answered in resolved threads; do not raise them again:

  • No compatibility paths for older servers or clients. Desktop and web ship together with this server, and chore: sync web dist from code-app #4700 carries the matching web bundle.
  • Intentionally not added: UserPromptSubmit hook markers, plan revision markers, indicators for skills the model loads, replay of tool progress, audio parts in user messages, usage on legacy assistant records, and tool ids recovered from nested interaction requests.
  • Missed-cron origin metadata is deferred to the scheduled-task follow-up.
  • Search reads only the persistent index, with no live overlay, and the search response has no source.
  • Conversation endpoints read from the agent's feed, not cold reads; rating reads turns through the same replay and may load a session for a stale evaluate. Notices are live-only frames.
  • When the next turn opens without a recorded turn.ended, the previous turn ends as completed (sessions written before turn.ended existed).
  • prompt_id idempotency holds within one server process; deduplication across restarts is a separate follow-up. The attempt cache is trimmed only on insertion. Skill activation keeps its current enqueue boundary.
  • User message item ids are the client prompt ids; collisions with provider tool call ids are not handled. Internal untracked prompts never reach the prompt snapshot.
  • Attached files become file attachments without server paths, and records without origin.attachments are parsed from the notice text.
  • item.debug is sent only when the server runs with KIMI_CODE_DEBUG=1, on the last item of each ended step; steps carry no timing.
  • The turns page is sent only when a connection starts receiving an agent. Undo and context clear are announced with turns.removed; live undo always goes through a replay, which the feed diffs against what it sent.
  • POST :undo takes { turn_id, agent_id? } and returns { removed_turn_ids } as in the KAP draft (40421 unknown turn, 40911 not undoable, 40901 busy).
  • A legacy context.undo that cuts a retained turn is only applied during a replay and is never announced item by item. The /api/v1/debug RPC keeps marking prompt attempts after dispatch resolves.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: ef90dbd781

ℹ️ 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 1dd5578 into main Nov 6, 2026
16 checks passed
@wbxl2000
wbxl2000 deleted the qer/turn-item-events branch November 6, 2026 06:12
@github-actions github-actions Bot mentioned this pull request Nov 10, 2026
This was referenced Nov 11, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 15, 2026
…obes

B1, B7, B9, B10 and B12 have no open rows; their executable probes pass (B9/B10 carry manual probes only, so verify reports no executable probe), and each batch is marked done. B3 stays open: its MoonshotAI#4427 probe targets test/features/tower/store.test.ts, which bunfig excludes from the default suite, so the probe cannot run without the heavy path override. The MoonshotAI#4663 probe followed applyConversationRecord, which the live feed redesign removed and this branch now deletes; it points at the feed's applyMessage fold instead. The MoonshotAI#4514 probe was malformed (absent: needs <pattern>@<path>) and now checks that package.json no longer lists the removed app.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 15, 2026
Note the rating/undo/prompt-id commits under MoonshotAI#4663 and narrow its remaining items to the /ops and transcript decisions plus the conversation test rewrite and e2e re-point.
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.

3 participants