fix(bots): avoid Telegram 64-byte callback_data overflow on bots menu - #1
Closed
gordonkoehn wants to merge 2 commits into
Closed
fix(bots): avoid Telegram 64-byte callback_data overflow on bots menu#1gordonkoehn 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.
Owner
Author
|
Upstreamed as hummingbot/condor#61. Validated end-to-end on a 72-char bot name in live deploy — postmortem at gordonkoehn/riskcraft#164. Keeping this fork PR open for traceability; will close once upstream merges. |
… 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.
Owner
Author
|
Superseded by hummingbot/condor#61 — this fork PR was only a self-review surface. Closing here; keeping the Do not delete this branch until upstream merges. |
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).Reproduction
Deploy any bot whose name is ≥ 49 chars. Hummingbot's deploy templates produced a 54-char name in my own run:
→
callback_data= 70 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"]before the keyboard is built. A new dispatcher branch resolvesbot_idxback to the 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 in the same dispatcher.Scope
bots_main_listis absent or the index is out of range (e.g. stale button after a restart), logs and re-opens the menu instead of crashing.