Skip to content

fix(frontend): paginate run history messages#3161

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

fix(frontend): paginate run history messages#3161
LittleChenLiya wants to merge 1 commit into
bytedance:mainfrom
LittleChenLiya:fix/issue-3052-history-order

Conversation

@LittleChenLiya
Copy link
Copy Markdown
Contributor

@LittleChenLiya LittleChenLiya commented May 22, 2026

问题原因

聊天历史加载按 run 逐个请求消息,但前端每个 run 只读取默认第一页。后端返回的是该 run 最新一页消息,并通过 has_more 表示还有更早消息;前端没有识别这个字段,也没有带 before_seq 继续加载同一个 run,导致长对话加载更多时会遗漏同一 run 内更早的消息,后续再拼接其他 run 时表现为历史缺失或顺序错位。

修改内容

  • 为 run 历史加载增加同一 run 内的 before_seq 游标。
  • 正确识别后端返回的 has_more 字段,只有当前 run 全部分页加载完成后才切换到更早的 run。
  • 补充单元测试覆盖 has_more 识别和下一页 cursor 计算。

关联 issue

关联 #3052

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 missing/misordered chat history in the frontend by correctly paginating messages within a single run. It aligns the frontend with the backend run-messages API contract (has_more + before_seq) so “load more” continues paging the same run until exhausted before moving to older runs.

Changes:

  • Add run-internal pagination support via before_seq cursor tracking per run_id.
  • Correctly interpret backend pagination flag (has_more), while keeping compatibility with the previous hasMore.
  • Add unit tests for has_more handling and next-page cursor computation.

Reviewed changes

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

File Description
frontend/src/core/threads/hooks.ts Implements has_more detection and per-run before_seq cursor tracking to paginate run messages correctly.
frontend/src/core/threads/types.ts Extends RunMessage with optional seq used for cursor pagination.
frontend/tests/unit/core/threads/message-merge.test.ts Adds unit tests covering has_more compatibility and cursor (seq) selection logic.

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