← Back to PRs

#13501: fix: extend assistant text dedup across message boundaries

by shakir-abdo open 2026-02-10 16:06 View on GitHub →
agents stale
## Summary - Remove the message-scope guard in `shouldSkipAssistantText` so dedup works across all messages within the same agent run - When a model produces text + `tool_use` in one turn and repeats the identical text after the tool result, the duplicate was being delivered to the channel because dedup state was reset between messages ### Root cause `shouldSkipAssistantText` had an early return: ```ts if (state.lastAssistantTextMessageIndex !== state.assistantMessageIndex) { return false; } ``` This meant dedup only worked within a single assistant message. Between messages (after `resetAssistantMessageState`), the guard allowed the same text through again. ### Reproduction 1. Configure an agent that calls a tool after every text response (e.g., state tracking via `exec`) 2. The model produces: `text + tool_use` → tool executes → model repeats the same text 3. Both copies are delivered to the channel (e.g., Telegram receives the message twice) ### Fix Remove the message-index guard so the trimmed/normalized text comparison works across all messages in the agent run. ## Test plan - [x] Verified on live Telegram bot — duplicates no longer delivered after tool_use round-trips - [ ] Existing `normalizeTextForComparison` and `isMessagingToolDuplicate` tests unaffected <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR changes assistant text deduplication in `src/agents/pi-embedded-subscribe.ts` by removing the message-index guard inside `shouldSkipAssistantText`, with the goal of suppressing identical assistant text that can be repeated after tool round-trips (text + tool_use, then repeated text after tool_result). The intent is to deduplicate repeated assistant output across assistant messages within a single agent run, particularly for messaging-channel delivery (e.g. Telegram). The dedup logic works by tracking the last emitted assistant text (trimmed and normalized) and skipping new text that compares equal. <h3>Confidence Score: 2/5</h3> - This PR likely does not achieve the intended cross-message dedup behavior and leaves behind inconsistent state. - Although the guard removal is straightforward, dedup state (`lastAssistantTextTrimmed/Normalized`) is still cleared on each assistant `message_start`, which would allow identical text in the next assistant message through—the exact scenario the PR description targets. Additionally, `lastAssistantTextMessageIndex` becomes dead state and there’s no automated test covering the tool round-trip duplication case. - src/agents/pi-embedded-subscribe.ts; src/agents/pi-embedded-subscribe.handlers.messages.ts <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs