Skip to content

fix(moderation): retry muting a new member when Telegram can't be reached - #26

Merged
scarletkc merged 1 commit into
mainfrom
fix/verify-restrict-retry
Nov 10, 2026
Merged

scarletkc merged 1 commit into
mainfrom
fix/verify-restrict-retry

Conversation

@scarletkc

Copy link
Copy Markdown
Member

What happened

On 2026-11-10 a new member joined a group with verification on. The bot's restrict_chat_member call failed on a single TLS handshake to the Bot API (NetworkError: httpx.ConnectError, log ref ERR-203F9EE0). The notice that followed went through fine, so the network was back within a second.

Because muting failed, the handler skipped the member entirely: no welcome, no verification, no timeout. They could post freely. The group saw "无法限制成员 …,请检查机器人的管理员权限与网络", which made it look like a permission problem.

What changed

  • Muting is retried. It now goes through the existing retry_telegram_send: network errors, timeouts and flood waits are retried up to 3 times (0.5s, then 1s; a flood wait sleeps as long as Telegram asks). BadRequest and Forbidden are not retried.
  • The notice names the cause. If muting still fails:
    • missing rights: "机器人没有限制成员的权限…请在管理员设置里给机器人打开「封禁用户」权限"
    • still unreachable: "暂时连不上 Telegram,重试后仍没能禁言 新成员,该成员未经验证就能发言,请管理员留意"
  • Both notices use the neutral 新成员 mention link instead of the raw user ID, so admins can tap through to the member.
  • Other failures, such as an admin joining, stay silent as before.
  • If the notice itself can't be sent, it is logged and the remaining new members in the same join message are still handled. Before, that exception escaped the handler.

For the reviewer

  • A member can still get in unverified if all attempts fail. This makes that rarer and tells admins; it doesn't close it.
  • The handler can now take longer. A sustained outage holds the join handler for up to 3 connect timeouts plus backoff. A flood wait holds it for as long as Telegram asks. concurrent_updates is on (bounded), so other updates keep flowing, but each waiting join occupies a slot.
  • 「封禁用户」 is meant to match the label of the Telegram client toggle for can_restrict_members. check_bot_permissions in the same file calls it 「限制成员」.

Testing

uv run pytest -q tests/ -k "verify or moderation or telegram_utils": 72 passed, including 4 new tests: a single network blip retried and verification proceeds; a lasting failure retried 3 times then announced; missing rights announced after one attempt; an admin joining not announced. ruff check passes on the changed files. The full suite and the MySQL integration suite were not run.

…ched

A single failed TLS handshake to the Bot API (httpx.ConnectError) made
restrict_chat_member fail. The new member was never muted, got no welcome
or verification, and could post freely. The group saw one notice asking
admins to check both the bot's rights and the network, which could not tell
the two causes apart.

Muting now goes through retry_telegram_send: network errors, timeouts and
flood waits are retried up to 3 times. BadRequest and Forbidden are not.

When muting still fails, the group notice names the actual cause:

- missing rights: asks admins to give the bot the 「封禁用户」 right
- still unreachable: says the member got in without verification

Both notices mention the member with the neutral link instead of the raw
ID. Other failures, such as an admin joining, stay silent as before. If the
notice itself cannot be sent, it is logged and the remaining new members in
the same join message are still handled.
@scarletkc

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T15:16:23.731956Z 2f68767 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 2f6876793c

ℹ️ 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".

@scarletkc
scarletkc added this pull request to the merge queue Nov 10, 2026
Merged via the queue into main with commit 727c10e Nov 10, 2026
5 checks passed
@scarletkc
scarletkc deleted the fix/verify-restrict-retry branch November 10, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant