fix(frontend): avoid duplicate optimistic user message#3002
Open
LittleChenLiya wants to merge 1 commit into
Open
fix(frontend): avoid duplicate optimistic user message#3002LittleChenLiya wants to merge 1 commit into
LittleChenLiya wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
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
getVisibleOptimisticMessagesto 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. |
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.
问题原因
首轮发送后,服务端返回的 human 消息和本地 optimistic human 消息会在 effect 清理 optimistic 状态前短暂同时进入消息合并结果,导致界面上看起来用户 prompt 重复出现。
修改内容
在消息合并前根据 human 消息数量变化过滤已经由服务端确认的 optimistic human 消息,并补充首轮、后续轮次和上传 optimistic 组合的单元测试。
关联 issue
关联 #2995