fix(telegram): prevent startup hang and double-log on command sync failures (504/BOT_COMMANDS_TOO_MUCH) - #9
Draft
Secret297-CODER-SOURCE with Copilot wants to merge 9 commits into
Draft
fix(telegram): prevent startup hang and double-log on command sync failures (504/BOT_COMMANDS_TOO_MUCH)#9Secret297-CODER-SOURCE with Copilot wants to merge 9 commits into
Secret297-CODER-SOURCE with Copilot wants to merge 9 commits into
Conversation
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.
…ng on setMyCommands failure Co-authored-by: Secret297-CODER-SOURCE <73541046+Secret297-CODER-SOURCE@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Update gateway configuration for improved security
fix(telegram): prevent BOT_COMMANDS_TOO_MUCH and eliminate double-logging on setMyCommands failure
Mar 12, 2026
… BOT_COMMANDS_TOO_MUCH Co-authored-by: Secret297-CODER-SOURCE <73541046+Secret297-CODER-SOURCE@users.noreply.github.com>
…er in menu module Co-authored-by: Secret297-CODER-SOURCE <73541046+Secret297-CODER-SOURCE@users.noreply.github.com>
…x (504 Gateway Timeout) Co-authored-by: Secret297-CODER-SOURCE <73541046+Secret297-CODER-SOURCE@users.noreply.github.com>
Copilot
AI
changed the title
fix(telegram): prevent BOT_COMMANDS_TOO_MUCH and eliminate double-logging on setMyCommands failure
fix(telegram): prevent BOT_COMMANDS_TOO_MUCH, 504 startup hang, and double-logging on command sync
Mar 12, 2026
Copilot
AI
changed the title
fix(telegram): prevent BOT_COMMANDS_TOO_MUCH, 504 startup hang, and double-logging on command sync
fix(telegram): prevent startup hang and double-log on command sync failures (504/BOT_COMMANDS_TOO_MUCH)
Mar 12, 2026
Secret297-CODER-SOURCE
force-pushed
the
main
branch
from
April 11, 2026 11:11
7985cb9 to
c652340
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two startup-time failures in Telegram command sync: a 504 on
deleteMyCommandscaused execution to fall through tosetMyCommands, doubling the ~2-minute timeout hang; a separateBOT_COMMANDS_TOO_MUCH400 occurred becauseTELEGRAM_MAX_COMMANDS=100hits Telegram's enforced ceiling. Both surfaced a double-log:withTelegramApiErrorLogginglogged the error, then the outersync().catch()logged it again.Summary
syncTelegramMenuCommands: (1)TELEGRAM_MAX_COMMANDS=100triggersBOT_COMMANDS_TOO_MUCH; (2) a 5xx ondeleteMyCommandsdoesn't bail early, sosetMyCommandswaits a full second timeout that will also fail; (3)withTelegramApiErrorLoggingrethrows after logging, and the outervoid sync().catch()logged the same error again.isTelegramServerError()to detect HTTP 5xx by GrammyError'serror_codefield;deleteMyCommandscatch now sets adeleteServerErrorflag on 5xx and skipssetMyCommands; inner.catch()onsetMyCommandsabsorbs the rethrow so the outer catch never double-logs.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
Security Impact (required)
Repro + Verification
Environment
Steps
Expected
setMyCommandsafterdeleteMyCommandsalready timed out.BOT_COMMANDS_TOO_MUCHfor bots with up to 99 commands.Actual (before)
Evidence
Key tests (all 9 pass in
bot-native-command-menu.test.ts):skips setMyCommands when deleteMyCommands fails with a 5xx server error—setMyCommandsnot called on 504still calls setMyCommands when deleteMyCommands fails with a 4xx client error— fallthrough preserved for non-5xxlogs setMyCommands failure once without rethrowing—runtimeErrorcalled exactly onceHuman Verification (required)
deleteMyCommandsabsent from bot API; 500 vs 599 range; 4xx codes do not bail; exactly-99-command bots.Compatibility / Migration
Failure Recovery (if this breaks)
src/telegram/bot-native-command-menu.ts.channels.telegram.commands.native: false; if skip-on-5xx is too aggressive, remove thedeleteServerErrorflag and restore.catch(() => {}).Risks and Mitigations
setMyCommandseven if onlydeleteMyCommandsendpoint is overloaded andsetMyCommandswould have succeeded.🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.