From af75083b8a4296666eafbc7ecd1f6e59079b3091 Mon Sep 17 00:00:00 2001 From: Hannes Rudolph Date: Sat, 4 Oct 2025 17:29:44 -0600 Subject: [PATCH] fix(condense): tag only summarized messages (window-based); preserve existing tags --- src/core/condense/index.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/core/condense/index.ts b/src/core/condense/index.ts index 16b188a8fe..08e7a3f298 100644 --- a/src/core/condense/index.ts +++ b/src/core/condense/index.ts @@ -196,12 +196,20 @@ export async function summarizeConversation( condenseId: condenseId, } - // Tag all middle messages (between first and tail) with condenseParent - // Middle messages are those that were summarized but not kept - const middleMessages = messages.slice(1, -N_MESSAGES_TO_KEEP).map((msg) => ({ - ...msg, - condenseParent: msg.condenseParent ?? condenseId, - })) + // Tag middle messages from the full middle span, but only set condenseParent + // for those that were actually part of the current summarization window and lack a tag. + const windowTs = new Set( + messagesToSummarize + .slice(1) // skip the preserved first + .map((m) => m.ts) + .filter((ts): ts is number => typeof ts === "number"), + ) + const middleMessages = messages.slice(1, -N_MESSAGES_TO_KEEP).map((msg) => { + if (!msg.isSummary && typeof msg.ts === "number" && windowTs.has(msg.ts)) { + return { ...msg, condenseParent: msg.condenseParent ?? condenseId } + } + return msg + }) // Reconstruct messages: [first message, tagged middle messages, summary, last N messages] // This preserves ALL messages, with middle ones tagged for filtering