fix(ui): stabilize streaming text order in TUI#47
Open
townwish4git wants to merge 1 commit intovigo999:refactor-arch-4.31from
Open
fix(ui): stabilize streaming text order in TUI#47townwish4git wants to merge 1 commit intovigo999:refactor-arch-4.31from
townwish4git wants to merge 1 commit intovigo999:refactor-arch-4.31from
Conversation
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.
PR Description
背景 / 问题
当前 TUI 在 agent 流式输出时,文本会出现阶段性乱序/错位;
在输出结束瞬间又会“恢复正确顺序”,影响可读性与信任感。
复现现象:
根因分析
UI 事件订阅存在重复注册路径,导致
eventCh在某些时机可能出现并发 reader,流式
AgentReplyDelta的消费顺序不稳定,进而出现显示错序。同时,interrupt 结束路径缺少统一终止收口,可能放大流式状态残留问题。
方案
1) 消除重复订阅(核心修复)
ui/app.goUpdate(tea.KeyMsg)分支不再强制包装waitForEventhandleEvent()尾部的单一路径持续订阅效果:保证同一时刻仅有一个稳定事件读取循环,流式 delta 顺序不再被并发读取打乱。
2) 中断收口补齐(配套)
internal/app/run.gocontext.Canceled路径显式 emitTaskDoneui/app.goTaskDone时提交当前 streaming agent message(结束流式态)效果:中断后不会把下一轮流式内容接到上一条未封口消息尾部。
测试
新增/更新测试覆盖:
TaskDone,且无ToolErrorTaskDone可触发 queued input 自动派发TaskDone后下一轮流式从新消息开始,不拼接旧消息执行:
go test ./internal/app -run Interruptgo test ./ui -run 'Test(TaskDoneDispatchesQueuedInputWhenTrainNotBusy|KeyUpdateDoesNotForceEventResubscribe| TaskDoneCommitsStreamingAgentBeforeNextTurn|CtrlCSendsInterruptTokenForActiveTask|BusyTrainQueuesInputInBannerInsteadOfChatStream)'go test ./internal/app ./ui/...全部通过。