Repository navigation
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b2da493c82
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| throw new Error("telegram sendMessage failed: empty formatted text and empty plain fallback"); | ||
| // Silently skip empty messages to avoid Telegram API 400 error | ||
| runtime.log?.("telegram sendMessage skipped: empty content"); | ||
| return 0; |
There was a problem hiding this comment.
Avoid reporting skipped empty Telegram sends as delivered
Returning 0 here makes downstream code treat a skipped message as a successful delivery: deliverTextReply in src/telegram/bot/delivery.replies.ts stores this numeric ID and calls markDelivered, and pinning logic later attempts pinChatMessage with message ID 0 when pin is enabled. In practice, whitespace-only replies are now counted as sent (message_sent success becomes true) even though nothing was sent, and can trigger an invalid pin API call; skip should be represented as a non-delivery state instead of a fake numeric message ID.
Useful? React with 👍 / 👎.
Greptile SummaryThis PR fixes a gateway crash caused by Telegram's 400 "text must be non-empty" error when agents emit empty replies (e.g. Issue: The
The test verifies that no API call is made and the log message appears, but does not assert that delivery state remains unaffected. Confidence Score: 3/5
Last reviewed commit: b2da493 |
| throw new Error("telegram sendMessage failed: empty formatted text and empty plain fallback"); | ||
| // Silently skip empty messages to avoid Telegram API 400 error | ||
| runtime.log?.("telegram sendMessage skipped: empty content"); | ||
| return 0; |
There was a problem hiding this comment.
Returning 0 here propagates back through deliverTextReply in delivery.replies.ts, which calls markDelivered(progress) unconditionally after every sendTelegramText call regardless of the return value. This causes:
progress.hasDeliveredis set totrueeven though nothing was sentprogress.deliveredCountis incremented for skipped messagesdeliverRepliesreturns{ delivered: true }for a fully skipped reply- Any
message_senthooks fire withsuccess: truefor the skipped message (line 631 checksprogress.deliveredCount > deliveredCountBeforeReply) firstDeliveredMessageIdis set to0; ifshouldPinis evertrueon such a reply,maybePinFirstDeliveredMessagewill attemptpinChatMessage(..., 0)(line 482-486)
The test at line 477 verifies the happy-path (no API call, correct log line) but does not assert the return value of deliverReplies or that deliveredCount remains unchanged, leaving this side-effect invisible to CI.
Suggested fix: Change the return type of sendTelegramText to Promise<number | undefined> and return undefined for the skip case, then guard the markDelivered calls in deliverTextReply / sendPendingFollowUpText with if (messageId) checks.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/telegram/bot/delivery.send.ts
Line: 139
Comment:
Returning `0` here propagates back through `deliverTextReply` in `delivery.replies.ts`, which calls `markDelivered(progress)` unconditionally after every `sendTelegramText` call regardless of the return value. This causes:
1. `progress.hasDelivered` is set to `true` even though nothing was sent
2. `progress.deliveredCount` is incremented for skipped messages
3. `deliverReplies` returns `{ delivered: true }` for a fully skipped reply
4. Any `message_sent` hooks fire with `success: true` for the skipped message (line 631 checks `progress.deliveredCount > deliveredCountBeforeReply`)
5. `firstDeliveredMessageId` is set to `0`; if `shouldPin` is ever `true` on such a reply, `maybePinFirstDeliveredMessage` will attempt `pinChatMessage(..., 0)` (line 482-486)
The test at line 477 verifies the happy-path (no API call, correct log line) but does not assert the return value of `deliverReplies` or that `deliveredCount` remains unchanged, leaving this side-effect invisible to CI.
**Suggested fix:** Change the return type of `sendTelegramText` to `Promise<number | undefined>` and return `undefined` for the skip case, then guard the `markDelivered` calls in `deliverTextReply` / `sendPendingFollowUpText` with `if (messageId)` checks.
How can I resolve this? If you propose a fix, please make it concise.- sendTelegramText returns 0 for skipped empty messages (NO_REPLY, heartbeat ack) - Check return value before updating delivery state (markDelivered, markReplyApplied) - Prevents incorrect deliveredCount increment for skipped messages - Fixes message_sent hooks firing with success=true for skipped messages - Fixes firstDeliveredMessageId being set to 0 (invalid for pinning) Fixes openclaw#37294
When sendTelegramText returns 0 (empty content skipped), callers in
delivery.replies.ts were still calling markDelivered() unconditionally,
causing:
- progress.deliveredCount to be incremented for skipped messages
- deliverReplies to return { delivered: true } for skipped replies
- message_sent hooks to fire with success: true for skipped messages
- firstDeliveredMessageId to be set to 0
Now we check messageId !== 0 before tracking delivery.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 19e93b3f42
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Silently skip empty messages to avoid Telegram API 400 error | ||
| runtime.log?.("telegram sendMessage skipped: empty content"); | ||
| return 0; |
There was a problem hiding this comment.
Handle skipped sends in voice fallback before marking delivery
Returning 0 here introduces a sentinel message ID, but only deliverTextReply/sendPendingFollowUpText were updated to treat it as “not delivered”; the voice-forbidden fallback path still treats any numeric ID as a real send (sendTelegramVoiceFallbackText stores messageId directly, and deliverMediaReply then marks delivery and can pin that ID). In the VOICE_MESSAGES_FORBIDDEN path, if a fallback chunk is skipped (for example when chunking yields an empty-content chunk), this can report success and attempt pinning with message 0 even though no text fallback message was actually sent.
Useful? React with 👍 / 👎.
Skip empty chunks before sendTelegramText instead of throwing. Handles all 3 call sites in delivery.replies.ts. Fixes first-chunk button attachment when chunk 0 is empty (use sentAnyChunk flag instead of i === 0). Safety net in sendTelegramText returns undefined instead of throwing, with guarded markDelivered/markReplyApplied. Closes openclaw#37278. More complete than openclaw#37294.
Skip empty chunks before sendTelegramText instead of throwing. Handles all 3 call sites in delivery.replies.ts. Fixes first-chunk button attachment when chunk 0 is empty (use sentAnyChunk flag instead of i === 0). Safety net in sendTelegramText returns undefined instead of throwing, with guarded markDelivered/markReplyApplied. Closes openclaw#37278. More complete than openclaw#37294.
|
Thanks for the review/comments here. Closing this PR as stale. The Telegram delivery path has changed enough since this was opened that this patch is no longer a good fit for the current code structure. The original idea may still be useful, but it should be reintroduced as a fresh PR against current |
Skip empty chunks before sendTelegramText instead of throwing. Handles all 3 call sites in delivery.replies.ts. Fixes first-chunk button attachment when chunk 0 is empty (use sentAnyChunk flag instead of i === 0). Safety net in sendTelegramText returns undefined instead of throwing, with guarded markDelivered/markReplyApplied. Closes openclaw#37278. More complete than openclaw#37294.
Summary
Change Type
Scope
Linked Issue
User-visible / Behavior Changes
Empty agent replies (e.g., NO_REPLY, heartbeat ack) are now silently skipped instead of causing gateway crashes.
Security Impact
Repro + Verification
Steps
Expected
Actual
Evidence
Human Verification
Compatibility / Migration
Failure Recovery
Risks and Mitigations