Skip to content

fix(telegram): index-based callback_data fallback for long model names - #98754

Closed
ly-wang19 wants to merge 2 commits into
openclaw:mainfrom
ly-wang19:fix/telegram-model-picker-index-callback-98221
Closed

ly-wang19 wants to merge 2 commits into
openclaw:mainfrom
ly-wang19:fix/telegram-model-picker-index-callback-98221

Conversation

@ly-wang19

Copy link
Copy Markdown
Contributor

What Problem This Solves

Closes #98221.

Telegram's inline callback_data field has a hard 64-byte limit. The /models picker currently has two encodings:

  • Standard: mdl_sel_{provider}/{model} — used when it fits.
  • Compact: mdl_sel/{model} — used as a fallback.

When both exceed 64 bytes (e.g. long Ollama namespaced names like llama3.1:70b-instruct-q6_K-xlarge-accelerated-release-candidate), buildModelSelectionCallbackData returns null and buildModelsKeyboard silently drops the model from the picker. Users on providers with long IDs see an incomplete model list with no indication that models are missing.

Why This Change Was Made

Adds a third fallback encoding: mdl_idx_{provider}_{index}, where index is the model's position in the provider's alphabetically sorted model list. The resolver looks the index up in the sorted list to recover the original model ID.

  • Index encoding is compact. For any reasonable provider id, mdl_idx_<provider>_<N> is far under 64 bytes — mdl_idx_openrouter_999 is 23 bytes — so this fallback covers virtually every real-world case where the compact form overflows.
  • The sort order is already a runtime invariant. bot-handlers.runtime.ts already sorts the provider's models alphabetically before paginating, and resolveModelSelection now performs the same sort on the byProvider set, so the index in the callback lines up with the model the user clicked.
  • No behavior change for short names. Standard and compact encodings remain the first two choices; index encoding only kicks in when both would overflow.

User Impact

Users on providers with long model IDs (Ollama namespaced names, some OpenRouter aliases, Bedrock inference profile ARNs) will now see all models in the /models picker instead of a silently truncated list. Selecting a previously-dropped model now works and sets the session override as expected.

Evidence

  • New unit tests in extensions/telegram/src/model-buttons.test.ts:
    • parseModelCallbackData accepts mdl_idx_openai_0 and mdl_idx_anthropic_42, rejects malformed variants (mdl_idx_openai, mdl_idx_openai_-1, mdl_idx_openai_abc).
    • buildModelSelectionCallbackData returns mdl_idx_openai_5 when standard and compact both overflow, and returns null only when the index encoding also overflows.
    • buildModelsKeyboard no longer drops long models — they get an index-based callback (mdl_idx_openrouter_2).
    • resolveModelSelection resolves select-index callbacks via sorted-list position and returns an ambiguous result for unknown provider or out-of-range index.
  • Caller updated: extensions/telegram/src/bot-handlers.runtime.ts now handles select-index callbacks alongside select.
  • Local vitest run: extensions/telegram/src/model-buttons.test.ts — 31 passed.
  • oxlint clean on all three changed files.

🤖 Generated with Claude Code

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: S labels Jul 1, 2026
@clawsweeper

clawsweeper Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close as superseded: this branch fixes the visible missing-button symptom, but it resolves bare provider/index callbacks against the current model list and is weaker than the open, proof-positive canonical sibling with stale-list guards.

Root-cause cluster
Relationship: superseded
Canonical: #98694
Summary: This PR is a duplicate candidate for the same Telegram long-callback model-picker bug, superseded by an open, mergeable, proof-positive sibling with stale-callback guards.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Canonical path: Close this duplicate branch and converge on one legacy-compatible index/fingerprint Telegram callback fix through #98694 if maintainers accept that callback format.

So I’m closing this here and keeping the remaining discussion on #98694.

Review details

Best possible solution:

Close this duplicate branch and converge on one legacy-compatible index/fingerprint Telegram callback fix through #98694 if maintainers accept that callback format.

Do we have a high-confidence way to reproduce the issue?

Yes, source-level. Current main and v2026.6.11 return null for model callbacks where both name encodings exceed 64 bytes, and the keyboard skips that row while the header counts the full model list.

Is this the best way to solve the issue?

No. The index fallback direction is right, but this PR's bare provider/index callback is not the best fix because it lacks stale-list identity guards already present in the canonical sibling.

Security review:

Security review cleared: The diff is limited to Telegram callback parsing/rendering and tests, with no dependency, workflow, permission, secret, or package-resolution changes.

AGENTS.md: found and applied where relevant.

What I checked:

  • Repository policy read: Root and scoped Telegram AGENTS.md files were read; the Telegram guide applies because this PR changes callback handling and visible Telegram model-picker behavior. (AGENTS.md:1)
  • Current main bug path: Current main still returns null when both standard and compact model callback payloads exceed the byte limit, leaving the keyboard builder without a button to render. (extensions/telegram/src/model-buttons.ts:107, 8e95e56e2dac)
  • Current handler count mismatch: The handler sorts the full provider model set, builds buttons from that list, and formats the header with the full model count, so skipped buttons create the reported mismatch. (extensions/telegram/src/bot-handlers.runtime.ts:2914, 8e95e56e2dac)
  • Latest release still affected: The latest release tag v2026.6.11 contains the same null-return and skip path, so the linked bug is not already fixed in a release. (extensions/telegram/src/model-buttons.ts:107, e085fa1a3ffd)
  • Current PR stale-index risk: The PR head resolves select-index callbacks by indexing into the current sorted provider model set, with no count, page, or fingerprint identity guard for old Telegram keyboards. (extensions/telegram/src/model-buttons.ts:169, 5ff28b465920)
  • Current PR test gap: The added tests cover sorted-index resolution, unknown providers, and out-of-range indexes, but not same-count or shifted-list stale callback rejection. (extensions/telegram/src/model-buttons.test.ts:120, 5ff28b465920)

Likely related people:

  • obviyus: GitHub commit metadata maps the current blamed callback builder, skip path, and handler model-list lines through commit 44e88f5. (role: recent area contributor; confidence: medium; commits: 44e88f550b69; files: extensions/telegram/src/model-buttons.ts, extensions/telegram/src/bot-handlers.runtime.ts)
  • bmendonca3: History for mdl_sel/ points to the compact model-only Telegram callback fallback that remains part of the shipped overflow path. (role: fallback behavior introducer; confidence: high; commits: 54eb13893fd5; files: src/telegram/model-buttons.ts, src/telegram/model-buttons.test.ts)
  • gildo: GitHub commit metadata maps the original inline /models and /model button picker implementation to this handle. (role: original feature contributor; confidence: high; commits: 16349b6e9312; files: src/telegram/model-buttons.ts, src/telegram/bot-handlers.ts)
  • scoootscooob: History shows the Telegram channel implementation was moved into extensions/telegram, carrying this model-button surface into the current plugin boundary. (role: extension boundary migration owner; confidence: medium; commits: e5bca0832fbd; files: extensions/telegram/src/model-buttons.ts, extensions/telegram/src/bot-handlers.runtime.ts)
  • steipete: Recent history on the model-button file includes callback-data byte-limit refactoring adjacent to this overflow behavior. (role: recent adjacent callback-limit contributor; confidence: medium; commits: 047b701859ab; files: extensions/telegram/src/model-buttons.ts)

Codex review notes: model internal, reasoning high; reviewed against 8e95e56e2dac.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. mantis: telegram-visible-proof Mantis should capture Telegram visible proof. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jul 1, 2026
@clawsweeper
clawsweeper Bot temporarily deployed to qa-live-shared July 1, 2026 20:42 Inactive
@openclaw-mantis

Copy link
Copy Markdown
Contributor

Mantis Telegram Desktop Proof

Summary: Mantis captured native Telegram Desktop before/after GIFs showing the /models picker for a long model name.

Main screenshot This PR screenshot
Baseline native Telegram Desktop screenshot Candidate native Telegram Desktop screenshot
Main This PR
Baseline native Telegram Desktop proof GIF Candidate native Telegram Desktop proof GIF

Motion-trimmed clips:

Raw QA files: https://artifacts.openclaw.ai/mantis/telegram-desktop/pr-98754/run-28546391760-1/index.json

@harjothkhara

Copy link
Copy Markdown
Contributor

Independent review note for current head 6d154a2aa0e6acdc58196a9485c2ccaf1c5ba815 after the newer Mantis proof landed:

I rechecked this PR against current main and the sibling cluster for #98221. The underlying bug is real: current buildModelSelectionCallbackData still returns null when both mdl_sel_{provider}/{model} and mdl_sel/{model} exceed Telegram's 64-byte callback limit, and buildModelsKeyboard then skips that model while the handler header still counts it.

The new Mantis Telegram Desktop proof is useful evidence that this branch makes the long-name button visible, but it does not change the best-fix ranking. This branch still encodes only provider + sorted index, then resolves that index against the current provider model list. If an old Telegram keyboard remains visible and the provider list shifts while the index is still in range, the click can select a different model than the one originally rendered.

For the competing fixes, #98694 is still the stronger canonical path: it keeps legacy name-based callback parsing for in-flight buttons, uses bounded index callback data, and adds count/fingerprint stale-list guards plus tests for same-count/different-list drift. I would close this duplicate or move any useful Mantis proof/context over to #98694, rather than landing this bare-index variant.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 2, 2026
@clawsweeper clawsweeper Bot closed this Jul 2, 2026
@clawsweeper

clawsweeper Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

🦞✅
ClawSweeper autoclose is complete.

Reason: structured ClawSweeper close marker: close-required (sha=5ff28b4659202acbff5d4b95f17c4364b597dfe6)

Closed:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram mantis: telegram-visible-proof Mantis should capture Telegram visible proof. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram /model picker silently drops models when callback_data exceeds 64 bytes

2 participants