From 5f2ade067c4a22286fd4c6c1b7dc3eeb2983e7f0 Mon Sep 17 00:00:00 2001 From: xintaofei Date: Wed, 11 Mar 2026 13:41:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=9A=E4=BC=9A=E8=AF=9D?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E8=BF=9B=E8=A1=8C=E6=97=B6=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E9=83=A8=E5=88=86Agent=E5=93=8D=E5=BA=94?= =?UTF-8?q?=E7=BB=93=E6=9D=9F=E5=90=8E=E6=B6=88=E6=81=AF=E4=B8=8D=E5=8F=AF?= =?UTF-8?q?=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/contexts/conversation-runtime-context.tsx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/contexts/conversation-runtime-context.tsx b/src/contexts/conversation-runtime-context.tsx index 245be44..61aaff4 100644 --- a/src/contexts/conversation-runtime-context.tsx +++ b/src/contexts/conversation-runtime-context.tsx @@ -223,7 +223,6 @@ function reduceHydrateDetail( const acceptSnapshot = shouldAcceptPersistedSnapshot(current, detail) const prevPersistedTurnCount = current?.persistedTurns.length ?? 0 const prevPersistedMessageCount = current?.persistedMessageCount ?? 0 - const prevPersistedUpdatedAt = current?.persistedUpdatedAt ?? null const optimisticTurns = current?.optimisticTurns ?? [] const persistedTurns = acceptSnapshot ? detail.turns @@ -237,21 +236,23 @@ function reduceHydrateDetail( const shouldDropOptimistic = optimisticTurns.length > 0 && persistedTurns.length >= (current?.persistedTurns.length ?? 0) + 1 - const nextUpdatedAt = detail.summary.updated_at ?? null - const hasPersistedAdvance = + // Content advance: actual turns or messages grew — safe to clear + // liveMessage because persisted data now covers the streamed content. + const hasContentAdvance = acceptSnapshot && (detail.turns.length > prevPersistedTurnCount || - detail.summary.message_count > prevPersistedMessageCount || - (nextUpdatedAt !== null && - (prevPersistedUpdatedAt === null || - nextUpdatedAt > prevPersistedUpdatedAt))) + detail.summary.message_count > prevPersistedMessageCount) + // Note: updated_at changes (e.g. status update bumping the timestamp) + // are NOT treated as content advance. Only actual turns / message_count + // growth should clear liveMessage, because a metadata-only bump could + // arrive before the session file is flushed to disk. const nextSession: ConversationRuntimeSession = { ...(current ?? createEmptySession(conversationId)), externalId: nextExternalId, persistedTurns, liveMessage: - hasPersistedAdvance && current?.syncState !== "awaiting_persist" + hasContentAdvance && current?.syncState !== "awaiting_persist" ? null : (current?.liveMessage ?? null), optimisticTurns: shouldDropOptimistic ? [] : optimisticTurns,