Skip to content

fix(frontend): avoid duplicate optimistic user message#3002

Open
LittleChenLiya wants to merge 1 commit into
bytedance:mainfrom
LittleChenLiya:fix/issue-2995-duplicate-first-message
Open

fix(frontend): avoid duplicate optimistic user message#3002
LittleChenLiya wants to merge 1 commit into
bytedance:mainfrom
LittleChenLiya:fix/issue-2995-duplicate-first-message

Conversation

@LittleChenLiya
Copy link
Copy Markdown
Contributor

问题原因

首轮发送后,服务端返回的 human 消息和本地 optimistic human 消息会在 effect 清理 optimistic 状态前短暂同时进入消息合并结果,导致界面上看起来用户 prompt 重复出现。

修改内容

在消息合并前根据 human 消息数量变化过滤已经由服务端确认的 optimistic human 消息,并补充首轮、后续轮次和上传 optimistic 组合的单元测试。

关联 issue

关联 #2995

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a frontend chat UI race where an optimistic user message and the server-confirmed human message could briefly render together before optimistic state cleanup runs.

Changes:

  • Adds getVisibleOptimisticMessages to suppress optimistic human messages as soon as the server human count advances.
  • Uses the filtered optimistic messages when merging history, live stream messages, and optimistic UI messages.
  • Adds unit coverage for first-turn, later-turn, and upload optimistic-message cases.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
frontend/src/core/threads/hooks.ts Filters optimistic messages before merge to avoid transient duplicate user prompts.
frontend/tests/unit/core/threads/message-merge.test.ts Adds tests for optimistic-message visibility and merge behavior.

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