Skip to content

fix(kap-server): prune divergent live transcript steps - #4792

Merged
sailist merged 1 commit into
release/2026-11-09from
feat-344-steer-transcript-heal
Nov 10, 2026
Merged

sailist merged 1 commit into
release/2026-11-09from
feat-344-steer-transcript-heal

Conversation

@sailist

@sailist sailist commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

Desktop / Web 用户在模型响应期间连续发送多条 steer 后,turn 完成时可能看到同一组用户消息和 assistant 回复各出现两次。本 PR 是 #4762 的后续修复,让 post-turn Transcript 收敛后只保留一份内容。

Bug Reproduction Steps

  1. 在活动 turn 的 LLM 请求阶段连续 steer 多次,使 live Transcript 产生多个 step。
  2. 等待原 turn 正常完成,并等待 post-turn heal 执行。
  3. 查看消息列表:cold 归并后的 step 与 live 的后续 step 同时存在,用户消息和 assistant 回复重复。

Root Cause

被 steer 中断且没有输出的 step 不会形成独立的 cold context message;cold 重建时会把 steer 用户帧附着到下一个 assistant step,因此 cold 与 live 的 step/frame 结构不同。

原有 post-turn heal 只对 cold 内容执行 upsert,从不删除 live 中 cold 已不包含的 step/frame,导致两套投影同时保留。这是合并收敛逻辑的修复,不是通过文本去重或隐藏客户端消息来绕过问题。

Code Changes

  • 将单轮 live-first 合并提取为统一的 healTurn:保留 live header、附件 ID、较长文本、工具结果以及 display / agentRefs / approvalId。
  • 保留原有 healTurnOps 的 upsert 行为;运行中 backfill 路径不变。
  • 仅当已结束 turn 含有 cold 中不存在的 live step/frame 时,先 reset 到合并后的整轮,再执行原有 heal ops,避免旧结构残留。
  • 在既有 post-turn heal 用例中加入 live t0.2、cold 仅 t0.1 的分叉场景,同时验证附件保留与步骤收敛;测试声明总数不增加。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
已结束 turn 的 cold/live 结构一致 继续逐帧 upsert 行为不变 Desktop / Web Transcript 客户端 不需要
已结束 turn 含有 cold 中不存在的 live step/frame cold 与 live 内容同时保留,可能重复渲染 reset 到 live-first 合并后的 cold 结构 连续 steer 的 Desktop / Web 用户 无;重复内容不是需要保留的行为
运行中 backfill live-first 合并并保留实时输出 行为不变,不进入新增 reset 分支 重连或晚订阅的客户端 不需要
live 中更丰富的字段 保留附件、长文本和工具结果 行为不变 含附件或工具调用的会话 不需要

受影响模块为 kap-server 的 post-turn Transcript heal。packages/kap-server/test/services/transcript.test.ts 覆盖结构收敛、附件、工具结果、backfill 和交互实体;transcriptContract.e2e.test.ts 覆盖 REST / WebSocket 一致性与重连行为。

验证结果
  • packages/kap-server/test/services/transcript.test.ts:111/111 通过。
  • packages/kap-server/test/transcriptContract.e2e.test.ts:13/13 通过。
  • @moonshot-ai/kap-server typecheck:通过。
  • @moonshot-ai/kap-server build:通过。
  • 两个改动文件 oxlint:0 warnings / 0 errors。
  • 修复前,分叉用例实际得到 ['t0.1', 't0.2'];修复后仅保留 ['t0.1']。

Checklist

  • I have read the CONTRIBUTING document.
  • 已补充回归覆盖,并沿用既有用例保持测试声明总数不变。
  • The behavior-change table above is complete;没有默认翻转或需要保留的重复渲染行为。
  • 不新增 changeset;steer 交互沿用现有 calm-pandas-steer.md,本次为同一行为的缺陷修复。
  • 无需文档更新;未修改公开 API、Wire 契约或配置。

- replace ended turns when cold history omits live steps or frames
- preserve live-first headers, longer text, tool outcomes, and attachments
- cover post-turn healing when a steered live turn has an extra step
@changeset-bot

changeset-bot Bot commented Nov 10, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: d748b33

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

This PR includes no changesets

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

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

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T08:03:36.783374Z d748b33 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Nov 10, 2026

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

commit: d748b33

@sailist
sailist merged commit 1b5359d into release/2026-11-09 Nov 10, 2026
16 checks passed
@sailist
sailist deleted the feat-344-steer-transcript-heal branch November 10, 2026 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants