Skip to content

fix(kap-server): end streamed items once from the recorded step - #4730

Merged
wbxl2000 merged 3 commits into
mainfrom
qer/stream-items-end-once
Nov 6, 2026
Merged

wbxl2000 merged 3 commits into
mainfrom
qer/stream-items-end-once

Conversation

@wbxl2000

@wbxl2000 wbxl2000 commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

Requirement or Bug

每个流式产生的思考条目会收到两次 item.ended,两次只差 duration_ms。界面上的思考时长会在这一步结束时跳一下(例如 4.2s 变 4.1s),而且每个思考块多一帧。

Bug Reproduction Steps

  1. 订阅一个会话,发一条会先思考再回答的输入。
  2. 看 WebSocket 帧:思考条目 …:0 在回复开始时收到一次 item.ended(duration_ms 为 feed 自己算的值),这一步落盘后又收到一次(duration_ms 为引擎记录的值)。

Root Cause

feed 的 endLiveBlocks 在同一步里下一段文本、思考或工具调用开始时,把前面运行中的条目立即标成结束,并用 feed 自己的时钟填 duration_ms(从收到第一个增量到下一段开始)。引擎落盘的 content.part 记的是这一块第一个增量到最后一个增量。两个口径不同,差分发现不一致,就以落盘值再发一次 item.ended。这是根本修复:时长只由引擎决定,feed 不再自己估算。

Code Changes

 onTextDelta / onToolCallDelta
   new block of the step
-    endLiveBlocks(step)        # end earlier running items with the feed's own duration
     item.started

 step persisted (content.part)
   fold writes the authoritative item
     item.ended                 # now the only one, with the engine's duration_ms

删除 endLiveBlocks 和它的两处调用,以及只为它存在的 LiveItem.startedAt。流式条目保持 running,等这一步落盘后由折叠产生的正式条目发唯一一次 item.ended。中英文 server-api.md 里对应的说明同步改了。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
流式思考 / 回复条目的结束时机 下一段内容开始时先结束一次,这一步落盘后再结束一次 只在这一步落盘后结束一次,值以落盘为准 把“前一段 item.ended”当作“这一段输出完毕”的外部客户端 无;desktop / web 本来就只以最后一个块判断是否仍在输出
思考时长标签 回复开始时就出现,步骤结束时可能小幅变化 步骤结束时出现,之后不变 desktop / web 用户(可见差别很小) 无
  • desktop / web 判断是否仍在流式输出只看最后一个块(streamingTailIndex),回复开始后思考块照样显示为“思考过程”并停止计时,这部分不变。
  • 测试:services/conversation.test.ts 新增「ends a streamed item once, from the recorded step, with the duration the engine measured」:先思考再回答,流式期间不发 item.ended,落盘后思考条目只结束一次且 duration_ms 为引擎的值;用 main 的实现该用例失败。kap-server 全部测试通过。

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 feed ended a streaming reasoning or message item as soon as the next block of its step started, filling duration_ms from its own clock, and the persisted item then ended it again with the engine's duration. Streamed items now stay running until the step is recorded and end once.
@changeset-bot

changeset-bot Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 06b9601

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 6, 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-06T07:10:13.995792Z 06b9601 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 6, 2026 •

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

commit: 06b9601

@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: 49d536790f

ℹ️ 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/stream-items-end-once.md Resolved
liruifengv
liruifengv previously approved these changes Nov 6, 2026
@wbxl2000
wbxl2000 force-pushed the qer/stream-items-end-once branch from dd57666 to 5954456 Compare November 6, 2026 07:04
@wbxl2000

wbxl2000 commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 06b9601c73

ℹ️ 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 ce38ebf into main Nov 6, 2026
16 checks passed
@wbxl2000
wbxl2000 deleted the qer/stream-items-end-once branch November 6, 2026 07:13
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 15, 2026
…th 2.6.0

MoonshotAI#4772: end tool calls cut short by a stop as interrupted, and keep a tool error failed when the step itself failed.

MoonshotAI#4826: drop the deprecated turn_id alias from the file-history queries; a turn_id-only query now fails validation with 40001.

MoonshotAI#4730: a streamed item no longer ends early from the feed clock. The source shape is in place; the remaining live-feed gap is recorded in the ledger row.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 15, 2026
…hotAI#4755 evidence

MoonshotAI#4618 is configured through [transcript].tool_call_density and [transcript].thinking, not a [transcript.group] table. The MoonshotAI#4618 probe limitation and the four-file hang noted on MoonshotAI#4755 were fixed in 580b5b5 and 4d88e05. MoonshotAI#4730 was recorded as no longer reconstructing step ids, which the step.begin case still does; the real gap was the live context-memory fold dropping the recorded content-part timing, now fixed in 008fb38. Verdicts are unchanged.
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