Skip to content

fix(gateway): dedupe pending voice transcript echoes - #67248

Merged
kshitijk4poor merged 6 commits into
NousResearch:mainfrom
kshitijk4poor:review/61519-pending-voice
Jul 19, 2026
Merged

fix(gateway): dedupe pending voice transcript echoes#67248
kshitijk4poor merged 6 commits into
NousResearch:mainfrom
kshitijk4poor:review/61519-pending-voice

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Summary

Salvages #61519 by @yu-xin-c onto current main (1202 commits behind). Cherry-picked all 3 contributor commits cleanly, then folded 3 follow-up commits addressing review findings.

Fixes #61455 — Telegram voice interrupts posted duplicate 🎙️ transcript messages because the monitor→drain sequence re-transcribed and re-echoed the same voice file.

Changes

Contributor commits (cherry-picked, authorship preserved):

  • fix(gateway): dedupe pending voice transcript echoes — caches STT results on the MessageEvent via _gateway_pending_stt_text/_gateway_pending_stt_transcripts/_gateway_pending_stt_echo_sent so all 6 dispatch paths (busy/priority/monitor/backup×2/drain) share one transcription and one echo per voice message
  • fix(gateway): preserve pending voice media semantics — new _event_media_is_stt_input predicate excludes AUDIO/DOCUMENT from STT (audio file attachments keep file semantics)
  • test(gateway): use compression helper in voice regression

Follow-up commits (review findings):

  • refactor: delete dead _dequeue_pending_with_transcription — function was never called since its introduction in d55304c; verified via git log -S and search_files
  • fix(gateway): invalidate pending STT cache when media merges into eventmerge_pending_message_event extends media_urls in place; added _invalidate_pending_stt_cache() to clear stale cache attrs so the next transcription picks up merged attachments (closes merge-race edge case)
  • refactor: extract 6 copy-paste voice interrupt blocks into one helper_transcribe_and_echo_pending_voice() replaces ~120 lines of near-identical try/except blocks across busy/priority/monitor/backup×2/drain paths; uses _UNSET sentinel to distinguish "no metadata passed" (rich fallback) from "None passed" (simple thread_id dict)

Validation

Before After
Targeted tests duplicate echoes on voice interrupts 71/71 pass, single echo per voice message
Ruff clean
STT calls per voice interrupt 2 (monitor + drain) 1 (cached)

Closes #61455
Based on #61519 by @yu-xin-c — cherry-picked with authorship preserved.

yu-xin-c and others added 6 commits July 19, 2026 06:51
The function was introduced in d55304c but never had a single caller —
verified via git log -S and search_files across the whole repo. The
drain path at _stream_confirmed_final_delivery inlines its logic directly.
Keeping a dead function around that duplicates live logic is a maintenance
hazard: future changes to the live path won't propagate to the dead one.
merge_pending_message_event extends the existing event's media_urls in
place when two media-bearing messages arrive in quick succession (photo
bursts, consecutive voice messages).  The gateway runner caches STT
transcripts on the event via _gateway_pending_stt_text; if the cached
event gains new media after the cache was populated, the stale transcript
was returned instead of transcribing the merged attachments.

Add _invalidate_pending_stt_cache() and call it from both media-merge
branches in merge_pending_message_event so the next transcription call
re-runs against the full merged media list.

Closes the merge-race edge case identified during review of PR NousResearch#61519.
The busy/priority/monitor/backup×2/drain paths each had near-identical
try/except blocks for transcribe+echo with only log_context, adapter,
and metadata varying. Extract into _transcribe_and_echo_pending_voice
which handles the cache lookup, echo dedup, and exception logging in
one place.

Uses a _UNSET sentinel to distinguish 'caller did not pass metadata'
(use the rich _thread_metadata_for_source fallback) from 'caller
explicitly passed None' (monitor/backup/drain paths that use the
simpler thread_id-only dict).

~120 lines of copy-paste collapsed into one 30-line helper.
@kshitijk4poor
kshitijk4poor enabled auto-merge (rebase) July 19, 2026 01:54
@kshitijk4poor
kshitijk4poor merged commit 66ed9d6 into NousResearch:main Jul 19, 2026
31 checks passed
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery tool/tts Text-to-speech and transcription platform/telegram Telegram bot adapter P2 Medium — degraded but workaround exists sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages labels Jul 19, 2026
@kshitijk4poor
kshitijk4poor deleted the review/61519-pending-voice branch August 5, 2026 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages tool/tts Text-to-speech and transcription type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Telegram voice interrupt posts duplicate transcriptions

3 participants