Repository navigation
Conversation
Move changes to correct paths (extensions/telegram/src/ not src/telegram/). Modes A–E all applied to the real source files: A. deliverTextReply: inline loop with empty-chunk skip (sentAnyChunk flag), replacing sendChunkedTelegramReplyText. Buttons attach to first sent chunk (not first iteration index), guarded by messageId != null. B. sendPendingFollowUpText + sendTelegramVoiceFallbackText: same inline loop pattern with null-chunk guard and empty-HTML+text guard. C. EMPTY_TEXT_ERR_RE exported from network-errors.ts, matching both 'message text is empty' and 'text must be non-empty'. Local definitions removed from delivery.send.ts; send.ts imports from same shared source. D. sendTelegramText (delivery.send.ts): return undefined instead of throw when empty-text has no plain fallback; logVerbose both skip paths. Return type widened to Promise<number | undefined>. E. withTelegramHtmlParseFallback (send.ts): also catches empty-text errors (isTelegramEmptyTextError) and retries with plain text, matching parse-error fallback behavior. isTelegramEmptyTextError added. Inline resolveReplyToForSend + markReplyApplied replacing reply-threading import that was removed. DeliveryProgress now self-contained. Tests: update 'throws when empty' → 'silently skips'; add: - 'attaches buttons only to first sent chunk' (multi-chunk, sentAnyChunk) - 'falls back to plain text on text must be non-empty' (Mode C, delivery) - 'retries with plain text on text must be non-empty' (Mode E, send.ts) - 'retries with plain text on message text is empty' (Mode E, send.ts) Closes openclaw#37278.
sendTelegramVoiceFallbackText can return undefined when all chunks are empty (e.g. formatting-only fallback text that trims to whitespace). Previously, markReplyApplied and markDelivered were called unconditionally after the voice fallback, reporting the reply as delivered and advancing reply threading even though no Telegram message was actually sent. Fix: only call markReplyApplied/markDelivered when fallbackMessageId is non-null, indicating at least one chunk was successfully sent. Fixes #2937611198
Greptile SummaryThis PR comprehensively fixes a multi-mode bug where empty or whitespace-only agent replies triggered a spurious "No response generated" error message to Telegram users instead of silently no-op'ing. The fix covers five independent failure paths (Modes A–E) spanning pre-send checks, in-flight chunk delivery guards, an outdated regex for Telegram's newer error wording, a missing plain-text fallback path, and the HTML parse fallback in Key changes:
One inconsistency remains in Confidence Score: 5/5
|
| }) => Promise<boolean | void>; | ||
| }): Promise<void> { | ||
| const applyDelivered = params.markDelivered ?? markDelivered; | ||
| let firstSentChunk = false; |
There was a problem hiding this comment.
firstSentChunk reads like a reference to the first sent chunk (an object or ID), but it's actually a boolean flag meaning "has any chunk been sent yet?" The equivalent variable in delivery.replies.ts was named sentAnyChunk, which is much clearer.
| let firstSentChunk = false; | |
| let sentAnyChunk = false; |
(And correspondingly update const isFirstSentChunk = !sentAnyChunk; and sentAnyChunk = true; below.)
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/telegram/src/bot/reply-threading.ts
Line: 57
Comment:
**Confusing boolean flag name**
`firstSentChunk` reads like a reference to the first sent chunk (an object or ID), but it's actually a boolean flag meaning "has any chunk been sent yet?" The equivalent variable in `delivery.replies.ts` was named `sentAnyChunk`, which is much clearer.
```suggestion
let sentAnyChunk = false;
```
(And correspondingly update `const isFirstSentChunk = !sentAnyChunk;` and `sentAnyChunk = true;` below.)
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Pull request overview
This PR updates the Telegram delivery stack to treat empty/whitespace-only outbound text as a silent no-op (or a plain-text retry when appropriate), preventing user-visible fallback errors and avoiding Telegram API 400s for empty text.
Changes:
- Make
sendTelegramTextskip (returnundefined) when both formatted HTML and plain-text fallback are empty, and expand empty-text error matching to include Telegram’s newer wording. - Add pre-send empty-chunk guards in reply delivery paths and ensure reply markup (“first chunk”) attaches to the first actually sent chunk.
- Extend
withTelegramHtmlParseFallbackto also treat empty-text errors as retryable-with-plain-text, and add targeted tests for these cases.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| extensions/telegram/src/bot/delivery.send.ts | Skip/return undefined on empty-text conditions; use shared empty-text regex; adjust return type. |
| extensions/telegram/src/bot/delivery.replies.ts | Guard against empty chunks; ensure reply markup/reply-to bookkeeping doesn’t advance on skipped sends. |
| extensions/telegram/src/bot/reply-threading.ts | Allow sendChunk to signal “not sent” and attach markup to first sent chunk. |
| extensions/telegram/src/send.ts | Treat empty-text errors like HTML-parse errors for plain-text retry in tool/send path. |
| extensions/telegram/src/bot/delivery.test.ts | Add/adjust tests for empty skips, markup threading, and updated empty-text wording. |
| extensions/telegram/src/send.test.ts | Add tests covering both “text must be non-empty” and “message text is empty” retry behavior. |
| extensions/telegram/src/network-errors.ts | Introduce shared EMPTY_TEXT_ERR_RE for consistent empty-text detection. |
| .gitignore | Add ignore entry for subagent-resume-worktree. |
| function markReplyApplied(progress: DeliveryProgress, replyToId?: number): void { | ||
| if (replyToId && !progress.hasReplied) { | ||
| progress.hasReplied = true; | ||
| } | ||
| } |
There was a problem hiding this comment.
markReplyApplied() is reimplemented here even though the same helper exists (and is exported) from bot/reply-threading.ts. Reusing the shared helper would reduce duplication and help keep reply-threading semantics consistent across text and media delivery paths.
| let firstSentChunk = false; | ||
| for (let i = 0; i < params.chunks.length; i += 1) { |
There was a problem hiding this comment.
Variable naming is a bit misleading: firstSentChunk is used as a "sent any chunk yet" flag, not as "the first sent chunk". Renaming it (e.g. to sentAnyChunk/hasSentChunk) would make the isFirstSentChunk logic easier to follow and reduce the chance of future mistakes.
| if (!isTelegramHtmlParseError(err) && !isTelegramEmptyTextError(err)) { | ||
| throw err; | ||
| } | ||
| if (params.verbose) { | ||
| const errorKind = isTelegramEmptyTextError(err) ? "empty text" : "HTML parse"; |
There was a problem hiding this comment.
In this catch block, formatErrorMessage(err) is computed multiple times via isTelegramHtmlParseError/isTelegramEmptyTextError (and then again for logging). Consider formatting the error message once and reusing it for both the regex checks and the log to avoid repeated parsing/normalization work.
| if (!isTelegramHtmlParseError(err) && !isTelegramEmptyTextError(err)) { | |
| throw err; | |
| } | |
| if (params.verbose) { | |
| const errorKind = isTelegramEmptyTextError(err) ? "empty text" : "HTML parse"; | |
| const isHtmlParseError = isTelegramHtmlParseError(err); | |
| const isEmptyTextError = isTelegramEmptyTextError(err); | |
| if (!isHtmlParseError && !isEmptyTextError) { | |
| throw err; | |
| } | |
| if (params.verbose) { | |
| const errorKind = isEmptyTextError ? "empty text" : "HTML parse"; |
| function resolveReplyToForSend(params: { | ||
| replyToId?: number; | ||
| replyToMode: ReplyToMode; | ||
| progress: DeliveryProgress; | ||
| }): number | undefined { |
There was a problem hiding this comment.
The newly added resolveReplyToForSend() duplicates the exported helper in bot/reply-threading.ts. Consider importing and reusing reply-threading's resolveReplyToForSend to avoid logic drift (especially since reply-threading.ts is already a dependency via sendChunkedTelegramReplyText).
|
Closing this PR because the author has more than 10 active PRs in this repo. Please reduce the active PR queue and reopen or resubmit once it is back under the limit. You can close your own PRs to get back under the limit. |
Problem
When an agent reply normalizes to empty or whitespace-only text, the following chain fires and sends a spurious fallback message to the user:
sendTelegramTextthrows (pre-send check) OR Telegram rejects the API call with400: text must be non-empty/400: message text is emptyonErrorinbot-message-dispatch.tsmarkNonSilentFailure()fires → sends "No response generated. Please try again."This produces a confusing user-visible error for something that should silently no-op.
Fixes #37278. Supersedes #37294 (incomplete fix). Replaces accidentally-closed #40384.
Root causes fixed
Mode A — pre-send empty check threw instead of skipping
sendTelegramTextthrew"empty formatted text and empty plain fallback"when htmlText and plainText were both empty. Changed tologVerbose + return undefined.Mode B — empty chunks reached sendTelegramText in delivery functions
deliverTextReply,sendPendingFollowUpText,sendTelegramVoiceFallbackTextpassed chunks with empty html AND empty text tosendTelegramText. Added pre-send guards. Also fixedreplyToMode="first"threading to attach to the first actually sent chunk viasentAnyChunkflag (was using chunk index 0).Mode C — EMPTY_TEXT_ERR_RE regex didn't match Telegram's newer error wording
Telegram has two variants:
"message text is empty"(old) and"text must be non-empty"(new). The catch block only matched the old form. Updated regex:/message text is empty|text must be non-empty/iMode D — catch block threw instead of returning undefined when no fallback
When the empty-text error was caught but no fallback text was available, the code threw instead of returning undefined. Changed to
logVerbose + return undefined.Mode E — send.ts HTML-parse fallback didn't handle empty-text errors
withTelegramHtmlParseFallbackinsend.tsonly caught HTML parse errors. Added empty-text error handling alongside it.Files changed
src/telegram/bot/delivery.send.ts— Modes A, C, Dsrc/telegram/bot/delivery.replies.ts— Mode B + sentAnyChunk fixsrc/telegram/send.ts— Mode Esrc/telegram/bot/delivery.test.ts— new tests for A, B, C, Dsrc/telegram/send.test.ts— new test for Mode E