Skip to content

fix(frontend): refresh thread run list after stream so older history loads on active page#3094

Open
64johnlee wants to merge 1 commit into
bytedance:mainfrom
64johnlee:fix/thread-history-runs-refresh-after-stream
Open

fix(frontend): refresh thread run list after stream so older history loads on active page#3094
64johnlee wants to merge 1 commit into
bytedance:mainfrom
64johnlee:fix/thread-history-runs-refresh-after-stream

Conversation

@64johnlee
Copy link
Copy Markdown
Contributor

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

useThreadHistory relies on useThreadRuns (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:

  1. onFinish invalidates ["threads", "search"] (sidebar list) but not the per-thread run list
  2. useThreadRuns returns only the initial (empty or single) run list
  3. findLatestUnloadedRunIndex sees all known runs as loaded → returns -1
  4. hasMore = false → scroll-to-top trigger is hidden
  5. Older runs produced before/during summarization are unreachable until page reload

Fix

In onFinish inside useThreadStream, add one invalidateQueries call for ["thread", threadId]:

if (threadIdRef.current) {
  void queryClient.invalidateQueries({ queryKey: ["thread", threadIdRef.current] });
}

After the stream ends, useThreadRuns refetches the complete run list. useThreadHistory detects unloaded older runs, sets hasMore correctly, and the user can scroll-to-top to load them — matching the behaviour when re-opening an existing conversation.

Validation

  • pnpm typecheck — clean
  • pnpm lint — clean
  • Normal (no-summarization) sessions: one extra runs-list refetch on stream end, negligible overhead
  • Mock sessions: not affected (mock sessions don't trigger onFinish with real thread IDs)

…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>
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.

新对话页发生上下文压缩后继续聊天,顶部无法继续加载更早历史消息

1 participant