← Back to PRs

#18460: fix(telegram): send fallback when streamMode partial drops all messages (#18195)

by BinHPdev open 2026-02-16 18:27 View on GitHub →
channel: mattermost channel: telegram size: S
## Summary Fixes #18195 - prevents silent delivery failures when `streamMode: "partial"` is enabled but no streaming text is generated in tool-heavy runs. ## Root Cause When `streamMode: "partial"` is set: 1. A draft stream is created for preview messages 2. In tool-heavy runs without streaming text, `onPartialReply` is never called 3. `draftStream.messageId()` stays `undefined` (no preview sent) 4. If the final reply is empty or normalized away, zero messages are delivered 5. The typing indicator continues running past completion, then times out This happens because: - Draft stream exists but is never used - Final reply may be empty or skipped during normalization - No fallback mechanism triggered for this specific case ## Changes 1. **Track final delivery attempts**: Added `deliveryState.finalAttempted` flag 2. **Detect unused draft streams**: Check if `draftStream` created but `hasStreamedMessage=false` 3. **Enhanced fallback logic**: Send `EMPTY_RESPONSE_FALLBACK` when: - Nothing was delivered AND - (Something skipped non-silent OR no final attempted OR draft stream unused) 4. **Diagnostic logging**: Added verbose logs for troubleshooting delivery flow ## Testing - Added test case for streamMode=partial with no streaming and no delivery - All 441 Telegram tests pass - Test confirms fallback message is sent when draft stream created but unused ## Behavior **Before**: Long tool-heavy run completes → zero messages → typing indicator times out → user confused **After**: Long tool-heavy run completes → fallback message sent → "No response generated. Please try again." → user can retry ## Notes - Preserves existing fallback behavior for other skip scenarios - Adds minimal overhead (one boolean flag, one boolean check) - Diagnostic logs help identify similar issues in the future - Does not change behavior when streamMode="off" or when streaming succeeds 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- greptile_comment --> <h3>Greptile Summary</h3> Adds fallback message delivery for tool-heavy runs when `streamMode: "partial"` is enabled but no streaming text is generated. The fix tracks whether a draft stream was created but unused (via `draftStreamCreatedButUnused` check) and sends `EMPTY_RESPONSE_FALLBACK` to prevent silent delivery failures. Includes comprehensive test coverage and diagnostic logging. <h3>Confidence Score: 5/5</h3> - Safe to merge - minimal, well-tested fix with clear diagnostic logging - Targeted fix with a single boolean flag and check that addresses a specific edge case. Test coverage validates the scenario. The change preserves all existing behavior and only adds a new fallback condition. Diagnostic logging aids future debugging. - No files require special attention <sub>Last reviewed commit: 3faaa91</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs