Skip to content

fix(tui): consume only root markdown stream events for live content - #613

Merged
AAswordman merged 1 commit into
AAswordman:mainfrom
h4rm00n:fix/tui-thinking-chunk-double-apply
Dec 3, 2026
Merged

AAswordman merged 1 commit into
AAswordman:mainfrom
h4rm00n:fix/tui-thinking-chunk-double-apply

Conversation

@h4rm00n

@h4rm00n h4rm00n commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

变更说明

问题:TUI 流式输出时思考链每个 chunk 重复一次(形如「每个每个chunkchunk都被都被」),正文不受影响。

根因(流式链路逐层对比定位):provider 与 core 的传输层思考与正文是同一条管线(reasoning 以 <think> 标记进同一 chunk 流),分歧发生在 core 的 Markdown 投影器:语义块(如 <think>)的正文会由子投影器展平再发一次原始 chunk 事件(parentBlockId=Some(块id)),与根投影器的原始 chunk 事件(parentBlockId=None)并存。投影器输出实测(临时探针,已在提交前移除):

"chunk" parent=None  value="思0"   ← 根投影器
"chunk" parent=Some(1) value="思0" ← 子投影器(重复)
...
"chunk" parent=None  value="答0"   ← 正文只有一条

TUI 的 apply_content_stream_event 对所有 chunk 事件一律 pushChunk,不区分根/子 → 思考内容被应用两次;持久化数据(core 侧另行落盘)不受影响,只有 TUI 的实时视图重复。Flutter 走块结构事件消费,不受本修复影响、也无需改动。

方案:TUI 侧对齐——只消费根级原始流(parentBlockId == None),与正文同路;代码中已有同款根/子判别范式(MarkdownStreamEvent::isRootCompletion)。子投影器事件是块结构消费者的数据源,core 侧发射保持不变。

改动类型

  • Bug 修复

影响范围

  • 平台:桌面 CLI / TUI
  • 模块:apps/cli/src/tui/core/app.rs(内容流事件应用 + 新增谓词与单元测试)
  • 用户流程:流式回答中的思考链展示

验证

cargo test --manifest-path apps/cli/Cargo.toml -j 4 --lib -- --test-threads=1
# → 161 passed; 0 failed; 3 ignored(含新增 thinking_child_events_do_not_double_stream_content;
#   首轮出现一次 terminal bootstrap 偶发失败,复跑即过,与本 PR 改动面无关)

python plugins/tools/sync_plugin_packages.py --source runtime --no-hot-reload
# → Done. source=runtime, copied=18, packed=40, plugin_parse_gate 通过

隔离环境(假 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 双份;修复后单份。

提交者确认

  • 全部内置及官方扩展包通过生产解析器和注册引擎校验,PR 的 Package parsing 检查通过。
  • 我已阅读 CONTRIBUTING.md。
  • 我已按 CLA.md 的流程签署协议,或提供了覆盖本次贡献的既有签署记录;所有共同贡献者均有相应签署记录。
  • 我拥有本次提交内容的版权或必要授权。
  • 我已保留第三方代码、资源及其许可证和版权声明。
  • 我没有提交密钥、令牌、个人数据或本地构建产物。
  • 我已更新受影响的文档和测试,或在上文说明了原因。

CLA 签署评论链接:#520 (comment)

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>
@AAswordman
AAswordman merged commit 36ec355 into AAswordman:main Dec 3, 2026
1 check passed
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