Skip to content

Telegram: keep long model callbacks selectable in /models picker#31857

Merged
steipete merged 2 commits intoopenclaw:mainfrom
bmendonca3:bm/telegram-model-callback-fallback
Mar 2, 2026
Merged

Telegram: keep long model callbacks selectable in /models picker#31857
steipete merged 2 commits intoopenclaw:mainfrom
bmendonca3:bm/telegram-model-callback-fallback

Conversation

@bmendonca3
Copy link

Summary

Describe the problem and fix in 2–5 bullets:

  • Problem: Telegram model picker dropped long Amazon Bedrock models because callback_data exceeded Telegram's 64-byte limit and those buttons were silently skipped.
  • Why it matters: users could not select affected models from /models at all, even though they were configured/allowed.
  • What changed: added compact callback fallback format (mdl_sel/{model}), parser support for compact callbacks, and callback-handler provider inference when provider is omitted.
  • What did NOT change (scope boundary): no changes to /model directive resolution logic, no catalog/allowlist behavior changes, and no changes outside Telegram model-button callback handling.

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

User-visible / Behavior Changes

  • Telegram /models inline picker now keeps long model IDs selectable by using a compact callback format when provider/model exceeds Telegram callback limits.
  • Compact callbacks are resolved back to full /model <provider>/<model> selections when provider inference is unique.
  • Ambiguous compact callbacks now fail safely by returning to provider selection instead of selecting the wrong provider.

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)
  • If any Yes, explain risk + mitigation:

Repro + Verification

Environment

  • OS: macOS (Darwin)
  • Runtime/container: Node 22 + pnpm
  • Model/provider: Amazon Bedrock long model ID (us.anthropic.claude-3-5-sonnet-20240620-v1:0)
  • Integration/channel (if any): Telegram
  • Relevant config (redacted): agents.defaults.model=bedrock/us.anthropic.claude-3-5-sonnet-20240620-v1:0

Steps

  1. On main, build Telegram model buttons for provider amazon-bedrock and model us.anthropic.claude-3-5-sonnet-20240620-v1:0.
  2. Observe mdl_sel_amazon-bedrock/us.anthropic.claude-3-5-sonnet-20240620-v1:0 exceeds 64 bytes.
  3. Prior behavior: button is skipped (continue), so model is missing/unselectable in Telegram picker.

Expected

  • Long model remains selectable in Telegram picker.
  • Callback parser/handler supports compact fallback callback data and resolves to the intended provider/model.

Actual

  • Long model button is dropped on main, making selection impossible via Telegram picker.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios:
    • pnpm test -- src/telegram/model-buttons.test.ts src/telegram/bot.test.ts
    • Added/validated tests for compact callback parsing, compact callback generation, provider inference for compact callbacks, and safe handling of ambiguous compact callbacks.
    • pnpm check passes.
  • Edge cases checked:
    • Compact callback with slash-containing model IDs.
    • Ambiguous provider inference for same model ID across providers.
    • Callback byte-length limit enforcement remains <=64 bytes.
  • What you did not verify:
    • Live Telegram API interaction in a real chat.

Compatibility / Migration

  • Backward compatible? (Yes)
  • Config/env changes? (No)
  • Migration needed? (No)
  • If yes, exact upgrade steps:

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly:
    • Revert commit 384410d02.
  • Files/config to restore:
    • src/telegram/model-buttons.ts
    • src/telegram/bot-handlers.ts
    • src/telegram/model-buttons.test.ts
    • src/telegram/bot.test.ts
  • Known bad symptoms reviewers should watch for:
    • /models inline selection fails to resolve model callback.
    • Compact callback routes to wrong provider instead of showing provider list.

Risks and Mitigations

List only real risks for this PR. Add/remove entries as needed. If none, write None.

  • Risk: compact callbacks omit provider and require inference.
    • Mitigation: infer only when exactly one provider matches; otherwise return provider picker with explicit resolution prompt.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 2, 2026

Greptile Summary

This PR adds a compact callback format (mdl_sel/{model}) for Telegram model selection buttons that exceed the 64-byte callback limit. When the standard format (mdl_sel_{provider/model}) is too long, the code falls back to the compact format, then infers the provider by checking which provider(s) have that model ID.

Key changes:

  • Modified buildModelsKeyboard to use compact callbacks when standard format exceeds 64 bytes
  • Added compact callback parsing support in parseModelCallbackData
  • Implemented provider inference logic that resolves to a unique provider or safely falls back to provider selection for ambiguous cases
  • Added comprehensive test coverage for compact callbacks, provider inference, and ambiguous resolution

Implementation quality:

  • Edge cases properly handled (empty models rejected, models with slashes work correctly, overly long models still skipped)
  • Safe fallback behavior prevents incorrect provider selection
  • No changes to /model directive resolution or catalog behavior (well-scoped change)
  • Backward compatible with existing standard callback format

Confidence Score: 5/5

  • This PR is safe to merge with no identified risks
  • The implementation is sound with proper edge case handling, comprehensive test coverage, and safe fallback behavior. The compact callback format is well-designed, parsing logic is unambiguous (different delimiters prevent conflicts), and provider inference safely handles ambiguous cases by returning to provider selection rather than guessing. No security concerns, no logical errors, and the change is well-scoped to Telegram callback handling only.
  • No files require special attention

Last reviewed commit: 384410d

@steipete steipete force-pushed the bm/telegram-model-callback-fallback branch from 384410d to a1eda85 Compare March 2, 2026 20:38
@steipete steipete merged commit d80144f into openclaw:main Mar 2, 2026
@steipete
Copy link
Contributor

steipete commented Mar 2, 2026

Landed via temp rebase onto main.

  • Gate: pnpm -s vitest run src/telegram/model-buttons.test.ts
  • Gate: pnpm -s vitest run src/telegram/bot.test.ts -t "compact model callbacks|ambiguous compact model callbacks"
  • Note: full src/telegram/bot.test.ts currently has unrelated pre-existing custom-command test failures in this branch run; compact callback tests pass.
  • Land commit: a1eda85
  • Merge commit: d80144f

Thanks @bmendonca3!

dawi369 pushed a commit to dawi369/davis that referenced this pull request Mar 3, 2026
OWALabuy pushed a commit to kcinzgg/openclaw that referenced this pull request Mar 4, 2026
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram: model buttons silently dropped when Bedrock callback_data exceeds 64 bytes

2 participants