Skip to content

Commit a071872

Browse files
author
jet
committed
fix: clear cross-run messaging-tool sent-text state after every compaction
When a run completes and the session compacts, the arrays tracking texts sent via messaging tools (message(action=send), sessions_send, etc.) were only cleared on compaction retries (willRetry=true). On normal compaction (willRetry=false), stale entries survived into the next run, where isMessagingToolDuplicateNormalized() could false-positive on the new run's final reply text — silently dropping legitimate block replies. Clear messagingToolSentTexts, messagingToolSentTextsNormalized, messagingToolSentTargets, and messagingToolSentMediaUrls unconditionally at every compaction_end so the next run always starts with a clean slate. Co-Authored-By: Cha <[email protected]> via OpenClaw
1 parent 800a0d3 commit a071872

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/agents/pi-embedded-subscribe.handlers.compaction.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ function createCompactionContext(params: {
3636
state: {
3737
compactionInFlight: true,
3838
pendingCompactionRetry: 0,
39+
messagingToolSentTexts: [],
40+
messagingToolSentTextsNormalized: [],
41+
messagingToolSentTargets: [],
42+
messagingToolSentMediaUrls: [],
3943
} as never,
4044
log: {
4145
debug: vi.fn(),

src/agents/pi-embedded-subscribe.handlers.compaction.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ export function handleCompactionEnd(ctx: EmbeddedPiSubscribeContext, evt: Compac
8181
const reason = normalizeCompactionReason(evt.reason);
8282
const kind = compactionLogKind(reason);
8383
ctx.state.compactionInFlight = false;
84+
// After every compaction (retry or not), discard messaging-tool sent-text
85+
// tracking from the completed run. Without this, stale entries survive
86+
// into the next run and cause `isMessagingToolDuplicateNormalized` to
87+
// false-positive on block-reply dedup — silently dropping legitimate
88+
// final replies when a previous run called `message(action=send)` or
89+
// `sessions_send` and the new text shares a normalized substring.
90+
ctx.state.messagingToolSentTexts.length = 0;
91+
ctx.state.messagingToolSentTextsNormalized.length = 0;
92+
ctx.state.messagingToolSentTargets.length = 0;
93+
ctx.state.messagingToolSentMediaUrls.length = 0;
8494
const willRetry = Boolean(evt.willRetry);
8595
// Increment counter whenever compaction actually produced a result,
8696
// regardless of willRetry. Overflow-triggered compaction sets willRetry=true

0 commit comments

Comments
 (0)