Skip to content

fix(frontend): preserve streamed message prefix on reconnect#3318

Open
LittleChenLiya wants to merge 1 commit into
bytedance:mainfrom
LittleChenLiya:fix/issue-3279-stream-history
Open

fix(frontend): preserve streamed message prefix on reconnect#3318
LittleChenLiya wants to merge 1 commit into
bytedance:mainfrom
LittleChenLiya:fix/issue-3279-stream-history

Conversation

@LittleChenLiya
Copy link
Copy Markdown
Collaborator

@LittleChenLiya LittleChenLiya commented May 29, 2026

问题原因

流式回答过程中切换到其他对话再返回时,前端会同时合并已持久化的历史消息和重连后的 live stream 消息。对于同一个 AI 消息 ID,现有合并逻辑总是让 live stream 消息覆盖历史消息;如果重连后的流只包含后续增量文本,已显示并持久化的前缀就会在流式过程中从页面上消失。

修改内容

  • 在流式状态下,仅对带有 stream metadata 的同 ID AI 消息合并历史前缀和 live 增量。
  • 保留 live 消息的其他字段,避免影响元数据、工具调用等运行时信息。
  • 补充消息合并单元测试,覆盖重连增量、中文无重叠增量、重复尾部去重、完整 live 内容以及无 stream metadata 的替换场景。

关联 issue

Closes #3279

Problem Cause

When users leave a chat during streaming and then return, the frontend merges persisted history messages with the reconnected live stream messages. For the same AI message ID, the previous merge logic always let the live stream message replace the history message. If the reconnected stream only contains later delta text, the already rendered and persisted prefix disappears from the page while streaming continues.

Changes

  • During active streaming, merge the persisted history prefix with the live delta only for same-ID AI messages that carry stream metadata.
  • Preserve the live message object fields so metadata, tool calls, and other runtime information continue to come from the live stream message.
  • Added message merge unit coverage for reconnect deltas, Chinese text without overlap, repeated suffix dedupe, full live content, and replacement updates without stream metadata.

Related Issue

Closes #3279

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.

流式输出过程中切换页面再返回,已输出的内容丢失,只显示后续新内容

1 participant