-
-
Notifications
You must be signed in to change notification settings - Fork 80.7k
session-memory hook duplicates assistant messages when thinking is stripped #92563
Copy link
Copy link
Closed
Closed
Copy link
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.ClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Description
Metadata
Metadata
Assignees
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.ClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Type
Fields
Priority
None yet
Bug Description
When using a model with thinking/reasoning enabled, the session JSONL saves two copies of every assistant response:
parentpointing to the first message)The
session-memoryhook then reads both messages viagetRecentSessionContent()→extractTextMessageContent(), which extracts the same text from each. This results in every assistant line appearing twice in memory files.Root Cause
In the
message_endevent handler, when an assistant response contains thinking content, two messages are persisted:{ role: "assistant", content: [{ type: "thinking", ... }, { type: "text", ... }] }(raw){ role: "assistant", content: [{ type: "text", ... }] }(cleaned, parent=first)The
session-memoryhooksextractTextMessageContent()treats both as valid text messages, producing duplicateassistant: ...lines.Steps to Reproduce
/newor/resetto trigger session-memory saveExpected Behavior
Each unique assistant message should appear only once in the memory file.
Environment
Suggested Fix
The cleanest fix is at the storage layer — the
message_endhandler should not persist both the raw and cleaned versions. Only one should be saved.As a temporary workaround, the
session-memoryhooksgetRecentSessionContent()can be patched to skip consecutive assistant messages with identical text:But this is a band-aid — the real fix should prevent duplicate storage.