Skip to content

Commit 28cbe00

Browse files
committed
fix(session-memory): reset mirror dedupe on command turns
Signed-off-by: sallyom <[email protected]>
1 parent b92f5b7 commit 28cbe00

2 files changed

Lines changed: 41 additions & 4 deletions

File tree

src/hooks/bundled/session-memory/handler.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,4 +942,40 @@ describe("session-memory hook", () => {
942942
"assistant: Your number is 123-4567",
943943
]);
944944
});
945+
946+
it("preserves delivery-mirror after an omitted slash-command user turn", async () => {
947+
const sessionContent = [
948+
JSON.stringify({
949+
type: "message",
950+
message: { role: "assistant", content: "Done" },
951+
}),
952+
JSON.stringify({
953+
type: "message",
954+
message: {
955+
role: "assistant",
956+
provider: "openclaw",
957+
model: "delivery-mirror",
958+
content: [{ type: "text", text: "Done" }],
959+
},
960+
}),
961+
JSON.stringify({
962+
type: "message",
963+
message: { role: "user", content: "/new" },
964+
}),
965+
JSON.stringify({
966+
type: "message",
967+
message: {
968+
role: "assistant",
969+
provider: "openclaw",
970+
model: "delivery-mirror",
971+
content: [{ type: "text", text: "Done" }],
972+
},
973+
}),
974+
].join("\n");
975+
976+
const memoryContent = await readSessionTranscript({ sessionContent });
977+
const lines = memoryContent!.split("\n").filter((l) => l.startsWith("assistant:"));
978+
expect(lines).toEqual(["assistant: Done", "assistant: Done"]);
979+
expect(memoryContent).not.toContain("user: /new");
980+
});
945981
});

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ export async function getRecentSessionContent(
8080
if (role === "user" && hasInterSessionUserProvenance(msg)) {
8181
continue;
8282
}
83+
if (role === "user") {
84+
// New turn: reset even when slash commands are omitted from
85+
// memory, so later standalone delivery mirrors are preserved.
86+
lastAssistantText = undefined;
87+
}
8388
const text = extractTextMessageContent(msg.content);
8489
const sanitized = text ? sanitizeSessionMemoryTranscriptText(text) : null;
8590
// Skip delivery-mirror rows only when they duplicate the preceding
@@ -94,10 +99,6 @@ export async function getRecentSessionContent(
9499
allMessages.push(`${role}: ${sanitized}`);
95100
if (role === "assistant") {
96101
lastAssistantText = sanitized;
97-
} else if (role === "user") {
98-
// New turn: reset so a delivery-mirror echoing the previous
99-
// turn's assistant text isn't silently filtered.
100-
lastAssistantText = undefined;
101102
}
102103
}
103104
}

0 commit comments

Comments
 (0)