fix(frontend): refresh thread run list after stream so older history loads on active page#3094
Open
64johnlee wants to merge 1 commit into
Open
Conversation
…loads on active page After context summarization fires mid-session, useThreadRuns is never invalidated, so the run list that useThreadHistory uses stays stale. findLatestUnloadedRunIndex returns -1 (all known runs appear loaded), hasMore becomes false, and the scroll-to-top trigger stops working — the user must reload the page to see older runs. Adding a queryClient.invalidateQueries(["thread", threadId]) call in onFinish causes useThreadRuns to refetch after every streaming session. On refetch, useThreadHistory detects unloaded older runs, sets hasMore correctly, and responds to the user scrolling to the top — matching the behaviour when re-opening an existing conversation. Closes bytedance#2965 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Problem
Closes #2965
After context summarization fires mid-session, scrolling to the top of an active chat page no longer loads older history. Reopening the conversation works fine, but staying on the same page leaves the older runs inaccessible.
Root Cause
useThreadHistoryrelies onuseThreadRuns(query key["thread", threadId]) to know which runs exist for the thread. This query is populated once on mount and never invalidated during the session. After a run finishes:onFinishinvalidates["threads", "search"](sidebar list) but not the per-thread run listuseThreadRunsreturns only the initial (empty or single) run listfindLatestUnloadedRunIndexsees all known runs as loaded → returns-1hasMore = false→ scroll-to-top trigger is hiddenFix
In
onFinishinsideuseThreadStream, add oneinvalidateQueriescall for["thread", threadId]:After the stream ends,
useThreadRunsrefetches the complete run list.useThreadHistorydetects unloaded older runs, setshasMorecorrectly, and the user can scroll-to-top to load them — matching the behaviour when re-opening an existing conversation.Validation
pnpm typecheck— cleanpnpm lint— cleanonFinishwith real thread IDs)