Skip to content

fix(telegram): eliminate BOT_COMMANDS_TOO_MUCH double-log, cap commands at 99, add network retry - #10

Draft
Secret297-CODER-SOURCE with Copilot wants to merge 12 commits into
mainfrom
copilot/manage-webchat-connections
Draft

Secret297-CODER-SOURCE with Copilot wants to merge 12 commits into
mainfrom
copilot/manage-webchat-connections

Conversation

Copilot AI commented Mar 13, 2026

Copy link
Copy Markdown

On every gateway start, setMyCommands could produce two redundant error lines for the same failure, with no actionable guidance and no retry distinction.

Summary

  • Problem: BOT_COMMANDS_TOO_MUCH (GrammyError 400) double-logged on every startup — once from withTelegramApiErrorLogging (shouldLog fired for all non-network errors) and again from the outer void sync().catch(...). No command count cap existed, so any configuration with ≥100 commands hit this on every run.
  • Why it matters: Noisy duplicate errors, no fix guidance, bot silently loses its command menu.
  • What changed: Cap commands at 99 before calling setMyCommands; suppress withTelegramApiErrorLogging for non-recoverable API errors; detect BOT_COMMANDS_TOO_MUCH explicitly and emit one actionable message then return (no retry, no rethrow). Added exponential-backoff retry for genuine network errors only.
  • What did NOT change: All handler registration, command routing, deleteMyCommands behavior, retry policy shape.

Before:

[telegram] telegram setMyCommands failed: Call to 'setMyCommands' failed! (400: Bad Request: BOT_COMMANDS_TOO_MUCH)
[telegram] command sync failed: GrammyError: Call to 'setMyCommands' failed! (400: Bad Request: BOT_COMMANDS_TOO_MUCH)

After:

[telegram] Telegram command sync failed: too many commands (BOT_COMMANDS_TOO_MUCH). 15 command(s) were sent; if this persists, try disabling native commands with channels.telegram.commands.native: false or reducing plugin/custom commands.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Related #

User-visible / Behavior Changes

  • BOT_COMMANDS_TOO_MUCH now surfaces as a single error with channels.telegram.commands.native: false guidance instead of two raw GrammyError dumps.
  • Configurations with >99 commands now log a warning and register the first 99; previously they would error on every start.
  • Transient network errors on setMyCommands now retry up to 5× with exponential backoff (3s→60s) before failing; previously they surfaced immediately.

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • Integration/channel: Telegram Bot API
  • Relevant config: any channels.telegram config with enough native/plugin/custom commands to reach the cap

Steps

  1. Configure bot with ≥100 commands (or trigger a stale command scope)
  2. openclaw gateway run
  3. Observe logs

Expected

  • Single line with count and actionable config guidance

Actual (before fix)

  • Two raw GrammyError lines, no guidance, no retry distinction

Evidence

  • Failing test/log before + passing after

10 unit tests in bot-native-command-menu.test.ts covering: cap enforcement, single-log path, no-retry for BOT_COMMANDS_TOO_MUCH, abort signal, exhausted network retries, deleteMyCommands suppression.

Human Verification (required)

  • Verified scenarios: BOT_COMMANDS_TOO_MUCH single-log; cap at 99 with overflow warning; no retry on API errors; retry + backoff on network errors; abort signal exits cleanly
  • Edge cases checked: non-BOT_COMMANDS_TOO_MUCH non-network errors still propagate to outer catch; commandsToRegister.length === 0 returns early without calling setMyCommands
  • What you did not verify: live Telegram environment with actual command overflow

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Failure Recovery (if this breaks)

  • Revert src/telegram/bot-native-command-menu.ts and src/telegram/bot-native-commands.ts
  • Known bad symptoms: BOT_COMMANDS_TOO_MUCH silently swallowed with no log — confirm the single actionable line still appears on overflow

Risks and Mitigations

  • Risk: isTelegramBotCommandsTooMuch string-matches .description/.message — future grammY error shape changes could miss detection
    • Mitigation: both fields checked; outer .catch() remains as fallback so undetected shapes still produce "Telegram command sync failed: …"

📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Secret297-CODER-SOURCE and others added 9 commits March 10, 2026 14:43
Introduce scoped WorkspaceTools for Telegram agents (createWorkspaceTools) with explicit readable/writable file lists and Anthropic tool definitions. Add an Anthropic tool-calling loop (runAnthropicWithTools) to AiReplyEngine and accept an optional workspaceTools parameter in aiReply; when ANTHROPIC_API_KEY is present, use the tool-calling path (up to 5 iterations) and otherwise fall back to the existing adapter. Update BotAgent and UserBotAgent to create and pass per-agent workspace tools into aiReply so agents can safely read/write their own workspace files. Also adjust the UI file loader to always reload Telegram agent file contents to avoid showing stale/shared cache entries.
Remove the TG_ID pattern from PII_PATTERNS to avoid treating short numeric Telegram IDs as PII. Improve Telegram agent files loading UX: set agentFilesLoading=true when initiating file load to prevent a flash of the "click to load" callout, auto-load files when returning to an already-active Files panel, and import loadTelegramAgentFiles where needed. Update the Files panel UI to show a "Loading files…" state and replace the static callout with a clickable callout button that invokes the provided onLoadFiles handler.
Import loadTelegramAgentFileContent and, when returning to the Telegram Files panel, clear the shared agentFileContents cache and reload the agent's file list. If an active file is selected, also fetch its content so the Files panel doesn't show stale data left over from the main Agents tab. Adds a clarifying comment about the shared cache behavior.
…dex.ts

- UserBotAgent: add `EntityLike` type import from telegram/define and cast
  the BigInt peer to silence TS2345; gramjs handles native bigint at runtime
- Delete extensions/telegram-manager/src/index.ts — orphaned dead-code file
  that was never imported, had broken module paths, and contained the Cyrillic
  identifier character that caused the historical ReferenceError at load time

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
After a network outage, syncTelegramMenuCommands fires during
reconnect but the network may still be recovering. Previously this
caused alarming error-level log messages for deleteMyCommands and
setMyCommands failures.

- Add retry loop (up to 5 attempts, exponential backoff) in
  syncTelegramMenuCommands for recoverable network errors
- Suppress error-level logging for intermediate retry attempts;
  only log on final failure or non-network errors
- Suppress deleteMyCommands network error logging (errors were
  already swallowed but still emitted at error level)
- Add optional abortSignal parameter to stop retrying on shutdown
- Add 4 new tests covering retry, exhausted retries, deleteMyCommands
  suppression, and abortSignal handling

Co-authored-by: Secret297-CODER-SOURCE <73541046+Secret297-CODER-SOURCE@users.noreply.github.com>
Copilot AI changed the title [WIP] Manage webchat connection states in gateway fix(telegram): retry command sync on recoverable network errors Mar 13, 2026
…, no retry, no double-log

- Add isTelegramBotCommandsTooMuch() helper detecting the 400 GrammyError
- Change setMyCommands shouldLog to only log on final attempt for recoverable
  network errors, preventing double-logging for non-recoverable errors like
  BOT_COMMANDS_TOO_MUCH
- Handle BOT_COMMANDS_TOO_MUCH specifically: emit ONE actionable error message
  with guidance (channels.telegram.commands.native: false) and return cleanly
- Add 2 new tests: single-message handling and no-double-log assertion
- Refactor duplicate test error construction into makeBotCommandsTooMuchError()

Co-authored-by: Secret297-CODER-SOURCE <73541046+Secret297-CODER-SOURCE@users.noreply.github.com>
Copilot AI changed the title fix(telegram): retry command sync on recoverable network errors fix(telegram): handle BOT_COMMANDS_TOO_MUCH with single actionable message, suppress retry and double-log Mar 13, 2026
Copilot AI changed the title fix(telegram): handle BOT_COMMANDS_TOO_MUCH with single actionable message, suppress retry and double-log fix(telegram): eliminate BOT_COMMANDS_TOO_MUCH double-log, emit single actionable error Mar 13, 2026
…review

Co-authored-by: Secret297-CODER-SOURCE <73541046+Secret297-CODER-SOURCE@users.noreply.github.com>
Copilot AI changed the title fix(telegram): eliminate BOT_COMMANDS_TOO_MUCH double-log, emit single actionable error fix(telegram): eliminate BOT_COMMANDS_TOO_MUCH double-log, cap commands at 99, add network retry Mar 13, 2026
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.

2 participants