fix: prevent config overwrite, session history race, and streaming message loss (#663)
Co-authored-by: zuolingxuan <zuolingxuan@bytedance.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
8c3a6a5f7a
commit
83858fdf73
@@ -1141,6 +1141,10 @@ export const useChatStore = create<ChatState>((set, get) => ({
|
||||
|
||||
switchSession: (key: string) => {
|
||||
if (key === get().currentSessionKey) return;
|
||||
// Stop any background polling for the old session before switching.
|
||||
// This prevents the poll timer from firing after the switch and loading
|
||||
// the wrong session's history into the new session's view.
|
||||
clearHistoryPoll();
|
||||
set((s) => buildSessionSwitchPatch(s, key));
|
||||
get().loadHistory();
|
||||
},
|
||||
@@ -1303,6 +1307,11 @@ export const useChatStore = create<ChatState>((set, get) => ({
|
||||
|
||||
const loadPromise = (async () => {
|
||||
const applyLoadedMessages = (rawMessages: RawMessage[], thinkingLevel: string | null) => {
|
||||
// Guard: if the user switched sessions while this async load was in
|
||||
// flight, discard the result to prevent overwriting the new session's
|
||||
// messages with stale data from the old session.
|
||||
if (get().currentSessionKey !== currentSessionKey) return;
|
||||
|
||||
// Before filtering: attach images/files from tool_result messages to the next assistant message
|
||||
const messagesWithToolImages = enrichWithToolResultFiles(rawMessages);
|
||||
const filteredMessages = messagesWithToolImages.filter((msg) => !isToolResultRole(msg.role));
|
||||
|
||||
Reference in New Issue
Block a user