Skip to content

fix(telegram): improve 403 bot not member/blocked error messages and regex grouping#51537

Closed
w-sss wants to merge 4 commits intoopenclaw:mainfrom
w-sss:pr-48650-fix
Closed

fix(telegram): improve 403 bot not member/blocked error messages and regex grouping#51537
w-sss wants to merge 4 commits intoopenclaw:mainfrom
w-sss:pr-48650-fix

Conversation

@w-sss
Copy link
Copy Markdown
Contributor

@w-sss w-sss commented Mar 21, 2026

Fixes #48273

Issues Fixed

  1. Regex alternation precedence - second alternative lacked 403 requirement
  2. Misleading error message for "bot was blocked" scenario

Changes

  • Fix regex grouping: /403.*(bot.*not.*member|bot.*blocked)/i
  • Improve error message to cover both scenarios:
    • "bot is not a member" → Add bot to channel/group
    • "bot was blocked" → Ask user to unblock

Error 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.

@openclaw-barnacle openclaw-barnacle bot added channel: telegram Channel integration: telegram agents Agent runtime and tooling size: S labels Mar 21, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 21, 2026

Greptile Summary

This PR has two distinct concerns: (1) a Telegram-specific fix that corrects a regex alternation-precedence bug in wrapTelegramChatNotFoundError and improves the error message for 403 "bot not member / bot blocked" scenarios, and (2) a new maxAnnounceChars feature that lets callers cap the length of sub-agent completion announcements (motivated by Telegram's 4096-char message limit).

What's good

  • The regex fix /403.*(bot.*not.*member|bot.*blocked)/i correctly requires 403 before both alternatives, resolving the original bug.
  • The improved error message is clear and actionable for both failure modes.
  • The maxAnnounceChars parameter is validated and normalized consistently across the call chain.

Issues found

  • In subagent-announce.ts, the truncation appends "\n\n[truncated — full output in transcript]" (~41 chars) after slicing to maxAnnounceChars, so the final string is maxAnnounceChars + 41 characters long. When the feature is used specifically to stay within Telegram's 4096-char hard limit, this overflow could still trigger a "message too long" API error. The slice boundary should be maxAnnounceChars - TRUNCATION_MARKER.length.

Confidence Score: 4/5

  • Safe to merge after fixing the off-by-marker-length truncation bug in maxAnnounceChars.
  • The primary goal of the PR (regex fix + better error message) is correct and well-implemented. The maxAnnounceChars feature is architecturally sound but has one concrete off-by-N bug: the truncation marker is appended outside the character budget, meaning the output can exceed maxAnnounceChars by ~41 chars, undermining the feature's stated purpose for hard platform limits like Telegram's 4096-char cap. A one-line fix resolves it.
  • src/agents/subagent-announce.ts — truncation logic in the maxAnnounceChars branch.
Prompt To Fix All With AI
This 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..."

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

w-sss added a commit to w-sss/openclaw that referenced this pull request Mar 22, 2026
- 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)
w-sss added a commit to w-sss/openclaw that referenced this pull request Mar 23, 2026
- 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)
w-sss added a commit to w-sss/openclaw that referenced this pull request Mar 23, 2026
- 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)
@w-sss
Copy link
Copy Markdown
Contributor Author

w-sss commented Mar 23, 2026

✅ CI 验证通过

  • ✅ check 通过
  • ✅ test:extensions 通过(271 文件,2464 测试)
  • ⚠️ test:channels 有 2 个失败,但是仓库已有问题,非本 PR 引入

建议:可以直接合并

Contributor and others added 4 commits March 24, 2026 00:04
- 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling channel: telegram Channel integration: telegram size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Telegram outbound sendMessage fails with "403 bot is not a member" despite working bot token and inbound messages working

1 participant