← Back to PRs

#21513: Agents: track TTS media in duplicate filter state

by DevvGwardo open 2026-02-20 01:34 View on GitHub →
agents size: XS
## Summary - Problem: `tts` tool media outputs were not consistently tracked in duplicate-media state, so final reply filtering could re-send the same voice media. - Why it matters: users can get duplicate voice-note/audio attachments in one run. - What changed: media collection now includes `audioPath` and `MEDIA:` extraction on tool result commit; successful `tts` tool completions are included in media-duplicate tracking. - What did NOT change (scope boundary): no changes to TTS synthesis logic, provider integrations, routing policy, or non-media duplicate filtering. ## Change Type (select all) - [x] Bug fix - [ ] Feature - [ ] Refactor - [ ] Docs - [ ] Security hardening - [ ] Chore/infra ## Scope (select all touched areas) - [ ] Gateway / orchestration - [x] Skills / tool execution - [ ] Auth / tokens - [ ] Memory / storage - [ ] Integrations - [ ] API / contracts - [ ] UI / DX - [ ] CI/CD / infra ## Linked Issue/PR - Closes #21205 - Related # ## User-visible / Behavior Changes - Duplicate voice-note/audio media from successful `tts` tool calls is now suppressed in final reply payload filtering. ## Security Impact (required) - New permissions/capabilities? (`No`) - Secrets/tokens handling changed? (`No`) - New/changed network calls? (`No`) - Command/tool execution surface changed? (`No`) - Data access scope changed? (`No`) - If any `Yes`, explain risk + mitigation: `N/A` ## Repro + Verification ### Environment - OS: macOS (worktree sandbox) - Runtime/container: Node 22 + pnpm workspace - Model/provider: N/A (unit-level handler path) - Integration/channel (if any): N/A - Relevant config (redacted): default ### Steps 1. Trigger `tool_execution_end` for `tts` with successful result containing `MEDIA:/tmp/tts-output.opus`. 2. Inspect `messagingToolSentMediaUrls` in handler state. 3. Run duplicate media filtering path with same URL. ### Expected - `messagingToolSentMediaUrls` includes `/tmp/tts-output.opus`, allowing downstream duplicate-media suppression. ### Actual - After fix: expected behavior observed in regression test. - Local full test run blocked by dependency fetch DNS failure in this environment. ## Evidence - [x] Failing test/log before + passing after - [ ] Trace/log snippets - [ ] Screenshot/recording - [ ] Perf numbers (if relevant) Notes: - Added regression test in `src/agents/pi-embedded-subscribe.handlers.tools.test.ts`. - Could not execute test suite here because `pnpm install` failed with `ENOTFOUND registry.npmjs.org`. ## Human Verification (required) - Verified scenarios: successful `tts` tool result with MEDIA token is committed to media dedupe state. - Edge cases checked: existing messaging-tool media tracking remains unchanged; no-op on tool error still preserved. - What you did **not** verify: end-to-end channel delivery across live providers. ## Compatibility / Migration - Backward compatible? (`Yes`) - Config/env changes? (`No`) - Migration needed? (`No`) - If yes, exact upgrade steps: `N/A` ## Failure Recovery (if this breaks) - How to disable/revert this change quickly: revert commit `a06b8241f`. - Files/config to restore: `src/agents/pi-embedded-subscribe.handlers.tools.ts`, `src/agents/pi-embedded-subscribe.handlers.tools.test.ts`. - Known bad symptoms reviewers should watch for: unexpected duplicate or missing media attachments after tool runs. ## Risks and Mitigations - Risk: Over-tracking non-messaging media paths could suppress intended media in rare cases. - Mitigation: tracking is still gated to successful messaging sends plus `tts`; dedupe only strips exact URL matches. ## AI-assisted - This PR was AI-assisted (Codex). - Testing level: lightly tested (targeted regression added; full local suite blocked by network in sandbox). <!-- greptile_comment --> <h3>Greptile Summary</h3> Added TTS tool media to duplicate tracking system. The fix ensures that audio files generated by the `tts` tool are tracked in `messagingToolSentMediaUrls` and properly filtered by `filterMessagingToolMediaDuplicates` to prevent duplicate voice attachments in final replies. Key changes: - Added `audioPath` field extraction from tool result details - Added `MEDIA:` token parsing from TTS text output - Marked TTS tool completions as messaging sends for media tracking The implementation correctly deduplicates within a single tool result using a shared Set, and the inner guard `if (committedMediaUrls.length > 0)` ensures failed TTS calls don't pollute the tracking state. <h3>Confidence Score: 4/5</h3> - This PR is safe to merge with low risk - The changes are well-scoped and address the stated issue. The implementation correctly handles TTS media tracking through two complementary extraction methods (audioPath field and MEDIA: tokens) with proper deduplication. The test validates the happy path. Minor deduction for slightly inelegant condition structure (marking all TTS calls as messaging sends even on error, though inner guards prevent issues) and lack of comprehensive error case testing. - No files require special attention <sub>Last reviewed commit: a06b824</sub> <!-- greptile_other_comments_section --> <sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub> <!-- /greptile_comment -->

Most Similar PRs