fix: load complete paginated run history#3305
Open
Eilen6316 wants to merge 2 commits into
Open
Conversation
Open
Collaborator
|
@Eilen6316 Do you mind resolving the confilct? |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes incomplete restoration of long run histories by paginating through /api/threads/{thread_id}/runs/{run_id}/messages until the backend indicates there are no more pages. It also centralizes backend “limit + 1” sentinel trimming so pagination boundaries remain correct for both forward (after_seq) and backward/latest (before_seq / default) pagination.
Changes:
- Frontend: add run-message pagination cursor support (
seq), helpers to detecthas_more/hasMore, compute the nextbefore_seq, and build message URLs safely. - Frontend: update
useThreadHistoryto repeatedly fetch additional pages for the same run usingbefore_sequntil fully loaded. - Backend: introduce a shared
trim_run_message_page()helper to consistently trim the sentinel row while preserving correct page boundaries; add regression tests for trimming behavior.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/tests/unit/core/threads/message-merge.test.ts | Adds unit tests for new run-message pagination helpers and URL construction. |
| frontend/src/core/threads/types.ts | Extends RunMessage to include optional seq used for pagination cursors. |
| frontend/src/core/threads/hooks.ts | Implements cursor-based multi-page loading per run and adds pagination helper utilities. |
| backend/tests/test_thread_run_messages_pagination.py | Adds boundary regression tests for thread-scoped run message pagination trimming. |
| backend/tests/test_runs_api_endpoints.py | Adds boundary regression tests for run-scoped message pagination trimming. |
| backend/tests/_run_message_pagination_helpers.py | Introduces a shared assertion helper for run-message pagination tests. |
| backend/app/gateway/routers/thread_runs.py | Switches to shared trimming helper for run-message pagination. |
| backend/app/gateway/routers/runs.py | Switches to shared trimming helper for run-message pagination. |
| backend/app/gateway/pagination.py | Adds trim_run_message_page() to correctly trim “limit + 1” pages for both cursor directions. |
Contributor
Author
Sure, I’ve resolved the conflict. Could you please review it again when you get a chance? Thanks! |
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.
Summary
Fixes #3290.
This PR fixes incomplete chat history restoration for long runs where a single run has more message events than the first
/messagespage returns. Previously the frontend loaded only one page per run, so older messages could disappear after reopening/restarting the app, and exports based on the loaded message list could miss the same older context even though token usage still reflected the full run.Changes
/api/threads/{thread_id}/runs/{run_id}/messagespages for the same run while the backend returnshas_more.seqas the nextbefore_seqcursor, so long runs are restored page by page instead of being marked loaded after the first page.seqto the frontendRunMessagetype and helper functions for pagination cursor handling / URL construction.has_moreand the older camelCasehasMoreresponse field.trim_run_message_page()helper so both run-message endpoints trim the extralimit + 1sentinel row consistently.before_seqpages keep the newest side and drop the older sentinel row;after_seqpages keep the oldest side and drop the newer sentinel row.Risk / scope
The change is limited to run-message history pagination. It does not alter run creation, streaming, model invocation, or message persistence. The backend behavior keeps the existing
limit + 1contract and only centralizes which sentinel row is trimmed.Tests
Backend pagination tests:
Result:
27 passed, 1 warningFrontend unit tests:
Result:
20 passed,128 passedBackend lint / format:
Result: passed
Frontend format:
Result: passed