Repository navigation
fix(tui): consume only root markdown stream events for live content - #613
Merged
AAswordman merged 1 commit intoDec 3, 2026
Merged
Conversation
The markdown projector emits two raw chunk events for text inside a semantic block: the root chunk plus a flattened copy from the block's child projector (parentBlockId set). The TUI content stream state applied every chunk event unconditionally, so every thinking chunk was appended twice and the streaming thinking chain rendered as doubled text, while plain content stayed correct. Ignore child-projector events — the root raw stream is the same authoritative source the plain-content path already uses, mirroring the existing isRootCompletion root/child discrimination. Signed-off-by: h4rm00n <harmoon@qq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更说明
问题:TUI 流式输出时思考链每个 chunk 重复一次(形如「每个每个chunkchunk都被都被」),正文不受影响。
根因(流式链路逐层对比定位):provider 与 core 的传输层思考与正文是同一条管线(reasoning 以
<think>标记进同一 chunk 流),分歧发生在 core 的 Markdown 投影器:语义块(如<think>)的正文会由子投影器展平再发一次原始chunk事件(parentBlockId=Some(块id)),与根投影器的原始chunk事件(parentBlockId=None)并存。投影器输出实测(临时探针,已在提交前移除):TUI 的
apply_content_stream_event对所有chunk事件一律 pushChunk,不区分根/子 → 思考内容被应用两次;持久化数据(core 侧另行落盘)不受影响,只有 TUI 的实时视图重复。Flutter 走块结构事件消费,不受本修复影响、也无需改动。方案:TUI 侧对齐——只消费根级原始流(
parentBlockId == None),与正文同路;代码中已有同款根/子判别范式(MarkdownStreamEvent::isRootCompletion)。子投影器事件是块结构消费者的数据源,core 侧发射保持不变。改动类型
影响范围
apps/cli/src/tui/core/app.rs(内容流事件应用 + 新增谓词与单元测试)验证
隔离环境(假 DeepSeek 风格 SSE 桩:20 段 reasoning_content + 20 段 content)+ tmux 抓帧验证:修复后思考链与正文均为单份(
思0思1…思19、答0答1…);持久化message_parts的 thinking part 始终为单份(证明重复只在 TUI 实时投影层)。说明:本机复现翻倍需要特定时序(多次复验中仅首次复现),但重复事件在投影器输出中的存在与 TUI 无差别消费是代码层确定的,修复消除该重复应用路径。
未运行 Flutter 侧测试:本 PR 未改 Flutter/Dart 代码与 core 发射行为。
截图或日志
复现步骤:以带 reasoning_content 的流式模型回答,展开思考链折叠组观察流式过程。修复前思考文本逐 chunk 双份;修复后单份。
提交者确认
Package parsing检查通过。CLA 签署评论链接:#520 (comment)