#18460: fix(telegram): send fallback when streamMode partial drops all messages (#18195)
channel: mattermost
channel: telegram
size: S
Cluster:
Telegram Message Handling Fixes
## 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
#17953: fix(telegram): prevent silent message loss and duplicate messages i...
by zuyan9 · 2026-02-16
82.7%
#18678: fix(telegram): preserve draft message when all final payloads are e...
by julianubico · 2026-02-16
80.9%
#19479: fix(telegram): skip redundant final edit in partial streaming mode
by v8hid · 2026-02-17
80.9%
#19673: fix(telegram): avoid starting streaming replies with only 1-2 words
by emanuelst · 2026-02-18
80.0%
#20274: fix: add fallback delivery when stopSlackStream fails
by nova-openclaw-cgk · 2026-02-18
79.0%
#20842: fix(telegram): preserve preview when only error payloads are delivered
by marcodelpin · 2026-02-19
79.0%
#14977: fix(telegram): remove ack reaction after block-streamed replies
by Diaspar4u · 2026-02-12
78.4%
#20623: fix(slack): duplicate replies and missing streaming recipient params
by rahulsub-be · 2026-02-19
78.1%
#5764: fix(telegram): enable streaming in private chats without topics
by garnetlyx · 2026-01-31
76.9%
#21276: fix(telegram): stabilize partial finalization and MEDIA dedupe (AI-...
by HOYALIM · 2026-02-19
76.8%