fix(gateway): dedupe pending voice transcript echoes - #67248
Merged
kshitijk4poor merged 6 commits intoJul 19, 2026
Conversation
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
enabled auto-merge (rebase)
July 19, 2026 01:54
4 tasks
This was referenced Aug 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_sentso all 6 dispatch paths (busy/priority/monitor/backup×2/drain) share one transcription and one echo per voice messagefix(gateway): preserve pending voice media semantics— new_event_media_is_stt_inputpredicate excludes AUDIO/DOCUMENT from STT (audio file attachments keep file semantics)test(gateway): use compression helper in voice regressionFollow-up commits (review findings):
refactor: delete dead _dequeue_pending_with_transcription— function was never called since its introduction in d55304c; verified viagit log -Sand search_filesfix(gateway): invalidate pending STT cache when media merges into event—merge_pending_message_eventextendsmedia_urlsin 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_UNSETsentinel to distinguish "no metadata passed" (rich fallback) from "None passed" (simple thread_id dict)Validation
Closes #61455
Based on #61519 by @yu-xin-c — cherry-picked with authorship preserved.