Repository navigation
Conversation
Greptile SummaryThis PR fixes a multi-mode bug where empty or whitespace-only agent replies caused a spurious "No response generated. Please try again." error in Telegram chats, covering five distinct failure paths (Modes A–E) across the bot delivery and programmatic send layers. Key changes:
Minor observations:
Confidence Score: 4/5
Last reviewed commit: f2dab2d |
|
|
||
| const EMPTY_TEXT_ERR_RE = /message text is empty|text must be non-empty/i; | ||
|
|
||
| function isTelegramHtmlParseError(err: unknown): boolean { | ||
| return PARSE_ERR_RE.test(formatErrorMessage(err)); |
There was a problem hiding this comment.
Duplicated EMPTY_TEXT_ERR_RE definition
EMPTY_TEXT_ERR_RE is now defined in both src/telegram/send.ts (here) and src/telegram/bot/delivery.send.ts. If Telegram ever introduces a third empty-text error wording, both definitions would need to be updated independently. Consider extracting the shared regex (alongside the existing PARSE_ERR_RE imports) into a shared constant, e.g., in network-errors.ts or a new telegram-errors.ts helper, so the two modules import from a single source of truth.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/telegram/send.ts
Line: 257-261
Comment:
**Duplicated `EMPTY_TEXT_ERR_RE` definition**
`EMPTY_TEXT_ERR_RE` is now defined in both `src/telegram/send.ts` (here) and `src/telegram/bot/delivery.send.ts`. If Telegram ever introduces a third empty-text error wording, both definitions would need to be updated independently. Consider extracting the shared regex (alongside the existing `PARSE_ERR_RE` imports) into a shared constant, e.g., in `network-errors.ts` or a new `telegram-errors.ts` helper, so the two modules import from a single source of truth.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Implemented in commit 773f674d2 — EMPTY_TEXT_ERR_RE moved to src/telegram/network-errors.ts (exported), local definitions removed from both delivery.send.ts and send.ts, both now import from the shared location.
| for (let i = 0; i < chunks.length; i += 1) { | ||
| const chunk = chunks[i]; | ||
| if (!chunk.html?.trim() && !chunk.text?.trim()) { | ||
| logVerbose("telegram: skipping empty chunk in sendPendingFollowUpText"); | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Missing null guard on chunk before empty-check in sendPendingFollowUpText
deliverTextReply (and the pre-existing code it evolved from) defends against a potentially falsy array element with if (!chunk) { continue; } before the new if (!chunk.html?.trim() && !chunk.text?.trim()) guard. sendPendingFollowUpText (and sendTelegramVoiceFallbackText) received the empty-chunk guard in this PR but not the null guard.
If chunkText() were ever to return a sparse/null element, chunk.html would throw a TypeError here because the optional-chain ?. only protects against chunk.html being null, not chunk itself being null.
While the markdownToTelegramChunks return type excludes null, adding the defensive if (!chunk) { continue; } line (matching deliverTextReply) would keep the three functions consistent:
| for (let i = 0; i < chunks.length; i += 1) { | |
| const chunk = chunks[i]; | |
| if (!chunk.html?.trim() && !chunk.text?.trim()) { | |
| logVerbose("telegram: skipping empty chunk in sendPendingFollowUpText"); | |
| continue; | |
| } | |
| if (!chunk || (!chunk.html?.trim() && !chunk.text?.trim())) { | |
| logVerbose("telegram: skipping empty chunk in sendPendingFollowUpText"); | |
| continue; | |
| } |
The same applies to sendTelegramVoiceFallbackText at line 235.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/telegram/bot/delivery.replies.ts
Line: 171-176
Comment:
**Missing null guard on `chunk` before empty-check in `sendPendingFollowUpText`**
`deliverTextReply` (and the pre-existing code it evolved from) defends against a potentially falsy array element with `if (!chunk) { continue; }` before the new `if (!chunk.html?.trim() && !chunk.text?.trim())` guard. `sendPendingFollowUpText` (and `sendTelegramVoiceFallbackText`) received the empty-chunk guard in this PR but not the null guard.
If `chunkText()` were ever to return a sparse/null element, `chunk.html` would throw a `TypeError` here because the optional-chain `?.` only protects against `chunk.html` being null, not `chunk` itself being null.
While the `markdownToTelegramChunks` return type excludes null, adding the defensive `if (!chunk) { continue; }` line (matching `deliverTextReply`) would keep the three functions consistent:
```suggestion
if (!chunk || (!chunk.html?.trim() && !chunk.text?.trim())) {
logVerbose("telegram: skipping empty chunk in sendPendingFollowUpText");
continue;
}
```
The same applies to `sendTelegramVoiceFallbackText` at line 235.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Fixed in commit 773f674d2 — added !chunk || null guard in both sendPendingFollowUpText and sendTelegramVoiceFallbackText, matching the pattern already in deliverTextReply.
There was a problem hiding this comment.
Pull request overview
This PR updates the Telegram delivery and send paths to treat empty/whitespace-only message bodies as a silent no-op (instead of throwing and triggering user-visible fallback errors), and broadens empty-text error detection to cover Telegram’s newer wording.
Changes:
- Make
sendTelegramTextreturnundefined(and log verbosely) when both formatted text and plain fallback are empty, or when Telegram rejects empty text and no fallback exists. - Add guards in delivery chunking/sending to skip empty chunks and ensure “replyToMode=first”/buttons attach to the first actually sent chunk.
- Extend HTML→plain fallback logic in
src/telegram/send.tsto also retry on Telegram empty-text errors, with tests covering both old/new error strings.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/telegram/bot/delivery.send.ts | Skip empty sends instead of throwing; recognize newer Telegram empty-text error wording. |
| src/telegram/bot/delivery.replies.ts | Skip empty chunks; adjust “first” semantics to apply to first sent chunk; avoid progress updates on skipped sends. |
| src/telegram/send.ts | Treat empty-text API errors like HTML-parse errors for HTML→plain fallback in tool send path. |
| src/telegram/bot/delivery.test.ts | Add/adjust tests for silent-skip behavior, threading semantics, and empty-text fallback. |
| src/telegram/send.test.ts | Add test ensuring HTML→plain fallback also triggers on empty-text API errors. |
| // Only apply reply reference, quote text, and buttons to the first sent chunk. | ||
| const replyToForChunk = !sentAnyChunk ? opts.replyToId : undefined; | ||
| const messageId = await sendTelegramText(opts.bot, opts.chatId, chunk.html, opts.runtime, { | ||
| replyToMessageId: replyToForChunk, | ||
| replyQuoteText: !appliedReplyTo ? opts.replyQuoteText : undefined, | ||
| replyQuoteText: !sentAnyChunk ? opts.replyQuoteText : undefined, |
There was a problem hiding this comment.
The comment says reply reference, quote text, and buttons are only applied to the first sent chunk, but sendTelegramText does not use opts.replyQuoteText at all (it only sets reply_to_message_id). Either remove/adjust the comment + replyQuoteText plumbing here, or implement quote support in sendTelegramText (e.g. via Telegram reply_parameters.quote) so this logic is meaningful.
There was a problem hiding this comment.
Fixed in commit 773f674d2 — comment updated to 'reply reference and buttons are only applied to the first sent chunk' (removed 'quote text' since replyQuoteText is not passed through to sendTelegramText).
| // Force two chunks where the first renders to empty HTML. | ||
| // Use a small textLimit and text that will produce an empty first chunk. | ||
| await deliverReplies({ |
There was a problem hiding this comment.
This test claims to cover the case where the first chunk is empty and buttons attach to the next chunk, but the setup (textLimit: 4000, text: "real content here") is unlikely to produce multiple chunks or an empty first chunk. As written it mainly asserts reply_markup on the first call, so it may not exercise the intended behavior; consider forcing chunking (small textLimit + input that yields an empty first HTML chunk) and asserting reply_markup on the correct send call.
There was a problem hiding this comment.
Fixed in commit 773f674d2 — test now uses textLimit: 20 with input that produces a whitespace-only first chunk followed by two real chunks. Asserts reply_markup is on the first actual sendMessage call (second chunk) and absent from subsequent calls.
f2dab2d to
773f674
Compare
|
All review feedback addressed in commit 773f674d2:
|
|
Note for reviewers: The |
773f674 to
a3a3718
Compare
a3a3718 to
82db7df
Compare
- Move EMPTY_TEXT_ERR_RE to network-errors.ts, import in both consumers - Add null guard on chunk in sendPendingFollowUpText + sendTelegramVoiceFallbackText - Fix misleading replyQuoteText comment in delivery.replies.ts - Fix sentAnyChunk test to actually force multi-chunk scenario
82db7df to
d589217
Compare
d589217 to
07cad96
Compare
07cad96 to
4e133e4
Compare
Restructured to correct paths + addressed all review commentsThe previous commits placed files under Changes applied (extensions/telegram/src/)
CI statusAll 893 telegram extension tests pass locally. Format check clean. No |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8370de1e14
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (messageId != null) { | ||
| if (firstDeliveredMessageId == null) { | ||
| firstDeliveredMessageId = messageId; | ||
| } | ||
| sentAnyChunk = true; |
There was a problem hiding this comment.
Avoid marking voice fallback as delivered when no chunk is sent
In the VOICE_MESSAGES_FORBIDDEN path, sendTelegramVoiceFallbackText can now return undefined when Telegram rejects a chunk as empty and plainText is also empty/whitespace (for example formatting-only fallback text that trims non-empty before chunking but yields whitespace chunk text). Because deliverMediaReply still unconditionally calls markDelivered/markReplyApplied after this helper returns, the reply is reported as successfully delivered and reply threading advances even though no Telegram message was actually sent.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 54152dbe. markReplyApplied/markDelivered are now only called when sendTelegramVoiceFallbackText returns a non-null messageId. If all voice fallback chunks are empty (skipped), no delivery is marked.
|
Re: comments #2936194807 & #2937611198 1. Empty-text retry with plain-text fallback (#2936194807): Already handled — the initial commit on this branch added 2. Voice fallback delivery marking (#2937611198): Fixed in 3ca4fc5. |
54152db to
853e128
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 853e128b1b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (!chunk.html?.trim() && !chunk.text?.trim()) { | ||
| logVerbose("telegram: skipping empty chunk in deliverTextReply"); | ||
| return; |
There was a problem hiding this comment.
Prevent skipped chunks from advancing delivery state
Returning early from this new empty-chunk guard does not actually skip delivery bookkeeping: sendChunkedTelegramReplyText still runs markReplyApplied and markDelivered after sendChunk resolves, so an unsent chunk is counted as delivered and can consume the reply target. This is reproducible whenever chunking yields an empty html+text chunk (the exact case this guard handles), and it can make deliverReplies report success with no Telegram message sent while also dropping reply_to_message_id/buttons for later chunks in replyToMode="first".
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed: changed sendChunk callback to return false for empty chunks, and updated sendChunkedTelegramReplyText to skip markReplyApplied/markDelivered when sendChunk returns false. This ensures empty chunks are fully skipped including all post-send bookkeeping — no more consuming the reply target or inflating deliveredCount. Also restored the missing sendChunkedTelegramReplyText import that was dropped during the branch rebase.
587e7e6 to
efefce2
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: efefce2fac
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (!chunk.html?.trim() && !chunk.text?.trim()) { | ||
| logVerbose("telegram: skipping empty chunk in deliverTextReply"); | ||
| return false; |
There was a problem hiding this comment.
Treat post-send empty-text skips as unsent chunks
sendChunk only returns false for pre-send !chunk.html && !chunk.text, but sendTelegramText can now no-op later by returning undefined when Telegram rejects HTML as empty and plainText is blank (delivery.send.ts catch path). In that case this callback returns void, so sendChunkedTelegramReplyText still runs delivery bookkeeping and can mark a reply as delivered/consumed even though no Telegram message was sent (same pattern also appears in sendPendingFollowUpText). This is reproducible with formatting-only chunks that survive as non-empty HTML but trim to empty plain text.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed: updated sendChunk callbacks in both deliverTextReply and sendPendingFollowUpText to explicitly check sendTelegramText's return — when it returns undefined (e.g. Telegram rejected empty content in the catch path), the callback now returns false, so the existing sent === false guard in sendChunkedTelegramReplyText correctly skips delivery bookkeeping. Previously, the void return fell through and advanced bookkeeping despite nothing being sent.
c8c6cfe to
cb5ba6f
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cb5ba6f97e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const sent = await params.sendChunk({ | ||
| chunk, | ||
| isFirstChunk, | ||
| replyToMessageId, | ||
| replyMarkup: isFirstChunk ? params.replyMarkup : undefined, |
There was a problem hiding this comment.
Track first sent chunk before assigning reply markup
Now that sendChunk can return false to skip unsent chunks, this loop still keys replyMarkup off isFirstChunk (i === 0) rather than the first chunk that was actually delivered. If chunk 0 is skipped (for example, a leading whitespace-only/newline chunk), subsequent chunks can send successfully but never receive buttons, so the reply loses its inline keyboard despite being delivered. This path was introduced by the new skip behavior and should use a "first sent chunk" flag for first-chunk-only metadata.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed: introduced a firstSentChunk flag that is set on the first successful send. replyMarkup is now applied to the first actually-delivered chunk rather than i===0, so buttons are not lost when leading chunks are skipped.
3882b02 to
c28312c
Compare
c28312c to
1780816
Compare
1780816 to
4699ac8
Compare
- Move EMPTY_TEXT_ERR_RE to network-errors.ts, import in both consumers - Add null guard on chunk in sendPendingFollowUpText + sendTelegramVoiceFallbackText - Fix misleading replyQuoteText comment in delivery.replies.ts - Fix sentAnyChunk test to actually force multi-chunk scenario
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
4699ac8 to
1e4a314
Compare
|
Superseded by #49391 (clean rebase, properly targets extensions/telegram/ instead of stale src/telegram/) |
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).
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, causing it to fall through tothrow errinstead of attempting the plain-text fallback. 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 (post-Mode C fix) but no fallback text was available, the code threw instead of returning undefined — inconsistent with the Mode A pre-send path. Changed to
logVerbose + return undefined.Mode E — send.ts HTML-parse fallback didn't handle empty-text errors
withTelegramHtmlParseFallbackinsend.ts(programmatic message tool path) only 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 ETest results
3987ca409and59895f9c5; fixed in fix(telegram): restore retry behaviour for 429 rate-limit and failed-after network errors #40383)Related
#40383 fixes the pre-existing retry regressions noted in the test results above.