Fix stale references shown while streaming and empty final reply in Go mode (#17146)

This commit is contained in:
euvre
2026-07-21 14:53:40 +08:00
committed by GitHub
parent bb6b43b5c9
commit f7a5629487
4 changed files with 33 additions and 6 deletions

View File

@@ -40,9 +40,20 @@ export const buildMessageItemReference = (
const referenceIndex = assistantMessages.findIndex(
(x) => x.id === message.id,
);
// An assistant message that has not received any content yet is still
// being generated. Never resolve its reference from the conversation
// reference list — the indices only align with completed answers, so the
// lookup would surface a stale reference from a previous turn (or from a
// previously opened conversation) while the answer is streaming.
const isPendingAnswer =
message.role === MessageType.Assistant &&
!message.content &&
isEmpty(message?.reference);
const reference = !isEmpty(message?.reference)
? message?.reference
: (conversation?.reference ?? [])[referenceIndex];
: isPendingAnswer
? undefined
: (conversation?.reference ?? [])[referenceIndex];
return reference ?? { doc_aggs: [], chunks: [], total: 0 };
};