Skip to content

Commit ab1ef1c

Browse files
committed
fix(session-memory): deduplicate assistant messages when thinking is stripped
When a model with thinking/reasoning is used, the session JSONL persists two copies of each assistant response: the raw version (with thinking blocks + text) and a cleaned version (text only). The session-memory hook's getRecentSessionContent() treated both as valid, producing duplicate lines in generated memory files. Fix by tracking the last assistant text and skipping consecutive duplicates. This handles the dedup at the consumer level without changing the storage layer. Fixes #92563.
1 parent 59950f7 commit ab1ef1c

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/hooks/bundled/session-memory/transcript.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export async function getRecentSessionContent(
3131
const lines = content.trim().split("\n");
3232

3333
const allMessages: string[] = [];
34+
let lastAssistantText: string | undefined;
3435
for (const line of lines) {
3536
try {
3637
const entry = JSON.parse(line);
@@ -47,7 +48,17 @@ export async function getRecentSessionContent(
4748
}
4849
const text = extractTextMessageContent(msg.content);
4950
if (text && !text.startsWith("/")) {
51+
// Skip consecutive duplicate assistant messages — the session JSONL
52+
// persists both raw (with thinking blocks) and cleaned copies when
53+
// thinking/reasoning is enabled, which would otherwise produce
54+
// duplicate entries in memory files.
55+
if (role === "assistant" && text === lastAssistantText) {
56+
continue;
57+
}
5058
allMessages.push(`${role}: ${text}`);
59+
if (role === "assistant") {
60+
lastAssistantText = text;
61+
}
5162
}
5263
}
5364
}

0 commit comments

Comments
 (0)