fix(telegram): improve 403 bot not member/blocked error messages and regex grouping#51537
fix(telegram): improve 403 bot not member/blocked error messages and regex grouping#51537w-sss wants to merge 4 commits intoopenclaw:mainfrom
Conversation
Greptile SummaryThis PR has two distinct concerns: (1) a Telegram-specific fix that corrects a regex alternation-precedence bug in What's good
Issues found
Confidence Score: 4/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/agents/subagent-announce.ts
Line: 1401-1407
Comment:
**Truncation marker pushes output past `maxAnnounceChars`**
The slice is taken at `maxAnnounceChars` characters and then the marker `"\n\n[truncated — full output in transcript]"` (~41 chars) is appended **after** the slice. This means the final string is `maxAnnounceChars + 41` characters long — exceeding the very limit the feature is meant to enforce. For Telegram's hard 4096-char limit this would still produce a ~4137-char string, which could trigger a "message too long" API error.
The marker length should be subtracted from the slice boundary:
```suggestion
const TRUNCATION_MARKER = "\n\n[truncated — full output in transcript]";
const truncatedFindings =
typeof params.maxAnnounceChars === "number" &&
params.maxAnnounceChars >= 1 &&
findings.length > params.maxAnnounceChars
? findings.slice(0, params.maxAnnounceChars - TRUNCATION_MARKER.length) +
TRUNCATION_MARKER
: findings;
```
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: "fix(telegram): impro..." |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 970f0201cd
ℹ️ 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".
- Define TRUNCATION_MARKER constant - Subtract marker length from slice boundary to prevent overflow - Fixes Greptile review comment on PR openclaw#51537 Before: slice(0, maxAnnounceChars) + marker (exceeds limit by ~41 chars) After: slice(0, maxAnnounceChars - marker.length) + marker (stays within limit)
- Define TRUNCATION_MARKER constant - Subtract marker length from slice boundary to prevent overflow - Fixes Greptile review comment on PR openclaw#51537 Before: slice(0, maxAnnounceChars) + marker (exceeds limit by ~41 chars) After: slice(0, maxAnnounceChars - marker.length) + marker (stays within limit)
- Define TRUNCATION_MARKER constant - Subtract marker length from slice boundary to prevent overflow - Fixes Greptile review comment on PR openclaw#51537 Before: slice(0, maxAnnounceChars) + marker (exceeds limit by ~41 chars) After: slice(0, maxAnnounceChars - marker.length) + marker (stays within limit)
✅ CI 验证通过
建议:可以直接合并 |
- Add maxAnnounceChars parameter to sessions_spawn tool schema - Pass parameter through subagent spawn flow to registry - Apply truncation with marker when announce message exceeds limit - Helps prevent message delivery failures on platforms with character limits (e.g., Telegram 4096 chars) Fixes openclaw#46785
- Detect 403 'bot is not a member' and 'bot was blocked' errors - Provide actionable guidance for users to fix the issue - Group regex alternatives correctly: /403.*(bot.*not.*member|bot.*blocked)/i - Fixes openclaw#48273 Addresses Greptile/Codex review feedback on PR openclaw#48650
- Define TRUNCATION_MARKER constant - Subtract marker length from slice boundary to prevent overflow - Fixes Greptile review comment on PR openclaw#51537 Before: slice(0, maxAnnounceChars) + marker (exceeds limit by ~41 chars) After: slice(0, maxAnnounceChars - marker.length) + marker (stays within limit)
Fixes #48273
Issues Fixed
Changes
/403.*(bot.*not.*member|bot.*blocked)/iError Message
Telegram send failed: bot is not a member of the chat or has been blocked (chat_id=${chatId}).
Fix: Add the bot to the channel/group, ensure it has not been removed, or ask the user to unblock the bot.