fix(bots): avoid Telegram 64-byte callback_data overflow on bots menu#61
Open
gordonkoehn wants to merge 2 commits into
Open
fix(bots): avoid Telegram 64-byte callback_data overflow on bots menu#61gordonkoehn wants to merge 2 commits into
gordonkoehn wants to merge 2 commits into
Conversation
Long bot_names (e.g. hummingbot-deploy's
'pmm-EPIC-USDT-kucoin-v1-<ts>-<ts>' format, 54 chars) plus the
'bots:bot_detail:' prefix (16 bytes) exceed Telegram's 64-byte
InlineKeyboardButton.callback_data cap, producing
telegram.error.BadRequest: Button_data_invalid and rendering /bots
unusable.
Switch the main bots menu to index-based callback_data
(bots:bot_idx:{i}), stashing the ordered bot-name list in
context.chat_data['bots_main_list'] when the menu is built. A new
dispatcher branch resolves the index back to the name and calls
show_bot_detail(). Legacy bots:bot_detail:{name} branch retained for
callers that pass known-short names.
Pattern mirrors the existing ctrl_idx mechanism in the same dispatcher.
There was a problem hiding this comment.
Pull request overview
This PR fixes /bots rendering failures caused by Telegram’s 64-byte InlineKeyboardButton.callback_data limit by switching the bots-menu callbacks to an index-based scheme and resolving indices back to bot names via cached state.
Changes:
- Updated the bots main menu keyboard to use
bots:bot_idx:{i}callback data instead of embeddingbot_name. - Cached the ordered bot list in context state when building the menu so indices can be resolved later.
- Added a new
bot_idxcallback branch in the bots dispatcher while retaining the legacybot_detailbranch.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| handlers/bots/menu.py | Emits index-based callbacks for bot buttons and caches the ordered bot-name list used for resolution. |
| handlers/bots/init.py | Adds dispatcher support for bot_idx callbacks, resolving indices back to bot names and handling stale/missing cache cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… import Addresses three Copilot review comments on hummingbot#61: 1. Use context.user_data (not chat_data) for the cached bot-name list so group-chat users don't overwrite each other's state. Matches the per-user convention used elsewhere in this handler. 2. Prefer the stable name-based callback_data form when it fits the 64-byte cap, fall back to index-based only when the name would overflow. Short-named bots keep the original upstream behavior: buttons on stale menu messages stay correct across list reordering. Only long-named bots (>= 49 chars) use the index-based form, where list stability is a hard trade-off vs not crashing. 3. Drop the redundant local re-import of show_bots_menu inside the bot_idx dispatcher branch — already imported at module scope. Validated end-to-end: same 72-char bot name exercises the index path cleanly.
Author
|
Addressed all three in 384c7f2:
Re-validated the fix end-to-end with the same 72-char bot name after the revision; |
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.
Problem
/botsfails withtelegram.error.BadRequest: Button_data_invalidwhen any bot has a name long enough thatbots:bot_detail:{bot_name}exceeds Telegram's 64-bytecallback_datacap (16-byte prefix + name, so names ≥ 49 chars overflow).Reproduction
Deploy any bot whose
instance_nameis ≥ 49 chars. This happens unprompted with the Hummingbot Backend API'sdeploy-v2-controllersendpoint, which appends its own deploy-time timestamp to whateverinstance_nameyou supply — long names are the default, not the exception. Observed on a fresh install:→
callback_data= 88 bytes → menu never renders. Log:Fix
Switch
_build_main_menu_keyboardto emitcallback_data=f"bots:bot_idx:{i}"and stash the ordered bot-name list incontext.chat_data["bots_main_list"]when the menu is built. A new dispatcher branch resolvesbot_idxback to the bot_name and callsshow_bot_detail().handlers/bots/menu.py: index-based callback + chat_data cachehandlers/bots/__init__.py: newbot_idxbranch next to existingbot_detailLegacy
bots:bot_detail:{name}branch is retained for callers that pass known-short names. Pattern mirrors the existingctrl_idxmechanism already in the same dispatcher.Scope
bots_main_listis absent or the index is out of range (e.g. stale button after a restart), logs a warning and re-opens the bots menu instead of crashing.Validated end-to-end
Tested against a live bot deployed via
POST /bot-orchestration/deploy-v2-controllers(72-char name, 88-byte callback_data). Stock upstream image crashes withButton_data_invalid; this branch renders the menu cleanly and both/botsand the bot-detail drill-down returnHTTP 200. Postmortem: gordonkoehn/riskcraft#164.