Skip to content

refactor(telegram): unify interactive keyboard rendering - #128728

Merged
steipete merged 2 commits into
mainfrom
codex/cleanup2-telegram-renderer-20260824
Aug 24, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/cleanup2-telegram-renderer-20260824

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Telegram maintained two separate inline-keyboard renderers for legacy interactive replies and modern message presentations. Both repeated the same button/select conversion and row chunking, leaving callback, approval, and fallback behavior vulnerable to drift.

Why This Change Was Made

Delete the obsolete plugin-private legacy renderer and reuse the existing Plugin SDK legacy-to-presentation bridge together with Telegram's canonical presentation renderer. Explicit keyboards still retain exact reference identity and short-circuit before lower-priority payloads are inspected. Legacy payloads are normalized once; text-only or entirely discarded legacy controls still fall back to usable presentation buttons, including existing dropped-control notifications.

The canonical renderer remains the sole owner of three-button row ordering, callback byte limits, typed approval/command/question authorization boundaries, opaque callback envelopes, and direct-chat Web App gating. No public API, configuration, SDK export, or security behavior changes.

Production: +10/-36, net -26 lines. Tests: +49 lines for explicit lazy identity and table-driven text-only/oversized-control fallback regressions.

User Impact

Telegram inline keyboards keep their existing visible behavior while a duplicate private rendering path is removed. Existing approval, question, callback, select, Web App, and delivery behavior remains unchanged.

Evidence

  • The new preservation regressions were added and run against untouched production code first: 33 Telegram button tests passed, proving the expected existing behavior before refactoring.
  • After the cleanup, ten focused suites passed: 607 tests covering button rendering, inline-button policy, interactive fallback, approval handlers, actions, outbound presentation/Web App handling, and real mocked Telegram delivery/send keyboard payloads.
  • Focused command: OPENCLAW_VITEST_FS_MODULE_CACHE_PATH=/private/tmp/openclaw-cleanup2-lane6-vitest-cache node scripts/run-vitest.mjs --configLoader runner extensions/telegram/src/button-types.test.ts extensions/telegram/src/inline-buttons.test.ts extensions/telegram/src/interactive-fallback.test.ts extensions/telegram/src/approval-handler.runtime.test.ts extensions/telegram/src/action-runtime.test.ts extensions/telegram/src/outbound-adapter.test.ts extensions/telegram/src/outbound-adapter.presentation.test.ts extensions/telegram/src/outbound-adapter.web-app.test.ts extensions/telegram/src/bot/delivery.test.ts extensions/telegram/src/send.test.ts.
  • Targeted formatter check, git diff --check, and exact changed-lane dry-run all pass; two independent source reviews found no issues and structured autoreview reports the patch correct.
  • Full local changed checks cannot run against this campaign's stale shared dependency install: even the direct two-file lint wrapper triggers unrelated existing Google provider enum, markdown-it type, and TUI declaration-generation failures before examining Telegram. Exact-head hosted CI and mandatory repository-native OPENCLAW_TESTBOX=1 scripts/pr prepare-run provide the authoritative clean-environment full gate.
  • No authenticated live Telegram API was used; real Telegram Bot API request payloads were verified through the existing mocked delivery/send boundaries.

@clawsweeper

clawsweeper Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: S maintainer Maintainer-authored PR labels Aug 24, 2026
@steipete
steipete marked this pull request as ready for review August 24, 2026 12:47
@clawsweeper clawsweeper Bot added mantis: telegram-visible-proof Mantis should capture Telegram visible proof. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 24, 2026
@openclaw-mantis

openclaw-mantis Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Mantis Telegram proof — PASS

Summary: A real Telegram user exercised the legacy-to-modern keyboard fallback on current main and the pull-request candidate. In both lanes, a legacy control with a 65-byte callback was discarded, the valid modern fallback rendered as the only button, and clicking it ran /status successfully. The recorded Bot API keyboard payloads were identical. This is a behavior-preserving refactor rather than a user-visible bug fix, and the candidate preserves the reported behavior.

  • Scenario: A temporary native plugin command returned one reply containing both (1) a legacy interactive button whose callback_data candidate was 65 bytes, exceeding Telegram's 64-byte limit, and (2) a modern presentation button labeled 'Fallback status' with a typed /status command action. As the real Telegram user, send /mantis_keyboard, verify that only the fallback button is visible, press it, and verify that the keyboard is cleared and a native OpenClaw status reply appears. Confirm the underlying sendMessage payload contains only callback_data 'tgcmd:/status' and no model-provider request occurs.
  • Trigger: clawsweeper_label
  • Run: https://github.com/openclaw/openclaw/actions/runs/32730462461
  • Artifact: https://github.com/openclaw/openclaw/actions/runs/32730462461/artifacts/9521729006
  • Baseline: pass at 018b01e5002a579616b5f4fa3b454108452316d2 — Main rendered exactly one 'Fallback status' button. Its sendMessage payload contained only callback_data 'tgcmd:/status'. The real-user click produced answerCallbackQuery, cleared the inline keyboard, and delivered the OpenClaw status reply; provider request count was zero.
  • Candidate (PR merged onto main): pass at 2fe8840758a3321541f4f17685d874c40a220eae — The candidate rendered the same single 'Fallback status' button with the same 'tgcmd:/status' Bot API payload. The real-user click cleared the keyboard and delivered the candidate's OpenClaw status reply; provider request count was zero.
  • Differential (trusted facts): The baseline and candidate first keyboard sendMessage request bodies are identical, and both complete the same real Telegram click path. This directly covers the changed branch where an entirely discarded legacy keyboard must not suppress a lower-priority presentation keyboard. The candidate therefore preserves the visible and callback behavior while removing the duplicate renderer.
  • Overall: pass
Before — current main After — this PR
baseline previewGifCropped candidate previewGifCropped

Motion-trimmed clips:

Raw QA files: https://artifacts.openclaw.ai/mantis/telegram-visible/pr-128728/run-32730462461-1/index.json

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 24, 2026
@clawsweeper

clawsweeper Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 24, 2026, 9:10 AM ET / 13:10 UTC.

ClawSweeper review

What this changes

The PR removes Telegram’s private legacy keyboard renderer and routes legacy interactive replies through the Plugin SDK presentation bridge and Telegram’s canonical keyboard renderer.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open: current main still has the duplicate legacy Telegram renderer, while this PR replaces it with the shared presentation path without a concrete source-level regression. A completed real Telegram proof and exact-head checks are still needed before merge.

Priority: P3
Reviewed head: f631973a1052fd1a9adbc5ff69ef1d8293487d71

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) PR readiness rating was derived from proof quality, review findings, security review, and reviewer confidence.
Proof confidence 🌊 off-meta tidepool Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Evidence reviewed 7 items Current-main behavior: Current main retains the separate legacy renderer and eagerly normalizes legacy input before resolving explicit buttons; the central cleanup is therefore not already implemented on main.
Canonical replacement: The PR short-circuits explicit buttons, converts normalized legacy controls through the SDK bridge, and reuses the existing presentation renderer.
SDK conversion contract: Legacy button and option types are aliases of their presentation counterparts, and the bridge maps text, buttons, and selects without a Telegram-specific parallel conversion.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs --configLoader runner extensions/telegram/src/button-types.test.ts

Result: PASS (completed)

node scripts/run-vitest.mjs --configLoader runner extensions/telegram/src/button-types.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128728-YKLRz1/target$ node scripts/run-vitest.mjs --configLoader runner extensions/telegram/src/button-types.te
st.ts
node scripts/run-vitest.mjs --configLoader runner extensions/telegram/src/button-types.test.ts
[test] starting test/vitest/vitest.extension-telegram.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-128728-YKLRz1/target

 ✓  extension-telegram  extensions/telegram/src/button-types.test.ts (33 tests) 64ms

 Test Files  1 passed (1)
      Tests  33 passed (33)
   Start at  13:11:07
   Duration  5.92s (transform 4.63s, setup 1.03s, import 4.68s, tests 64ms, environment 0ms)

[test] passed 1 Vitest shard in 11.28s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128728-YKLRz1/target$ node scripts/run-vitest.mjs --configLoader runner extensions/telegram/src/button-types.te
st.ts

































Assertions:

  • PASS expect_output: button-types.test.ts

How this fits together

Telegram outbound paths accept explicit keyboards, legacy interactive replies, and portable presentations, then turn the selected controls into inline-keyboard rows for Telegram delivery. The resolver’s precedence and dropped-control reporting affect callback, approval, question, and fallback behavior across send and reply funnels.

flowchart LR
A[Outbound reply inputs] --> B[Telegram keyboard resolver]
B --> C{Explicit keyboard present?}
C -->|Yes| D[Inline keyboard rows]
C -->|No| E[Legacy reply bridge]
E --> F[Canonical presentation renderer]
F --> D
D --> G[Telegram delivery funnels]
Loading

Before merge

  • Resolve merge risk (P2) - Telegram callback and fallback behavior is compatibility-sensitive; the only real Telegram investigation recorded in the discussion is still in progress, so it does not yet prove after-fix delivery.
  • Resolve merge risk (P1) - The PR is behind current main and its required checks are incomplete; merge evidence must be refreshed for the exact landing head.
Agent review details

Security

None.

PR surface

Source -26, Tests +49, Other 0. Total +23 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 10 36 -26
Tests 1 49 0 +49
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 3 60 37 +23

Review metrics

Metric Value Why it matters
Production versus test delta production -26; tests +49; assertion baseline -1 The refactor removes the duplicate renderer while adding focused precedence and fallback coverage; the baseline change records the reduced assertion count.

Merge-risk options

Maintainer options:

  1. Finish Telegram proof before merge (recommended)
    Wait for the active Mantis run or equivalent redacted live Telegram trace to show preserved keyboard delivery and fallback behavior on this head.
  2. Accept mock-only transport evidence
    A maintainer may explicitly accept the focused mocked delivery and renderer suites without a completed live Telegram trace.

Technical review

Best possible solution:

Keep the SDK bridge and single Telegram renderer, then attach a redacted real Telegram result covering explicit keyboards, legacy controls, and unusable-control fallback before landing.

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

Not applicable: this is a refactor rather than a report of a current failure; source and focused tests establish the intended precedence and fallback invariants.

Is this the best way to solve the issue?

Yes: the SDK bridge is type-compatible and lossless for legacy controls, so reusing the canonical renderer is more maintainable than retaining a second Telegram conversion path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 659ca1ed01c2.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P3: This is a small behavior-preserving Telegram renderer cleanup with no reported production regression.
  • merge-risk: 🚨 compatibility: The resolver controls existing Telegram callback, approval, question, and fallback keyboard behavior for installed bots.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
  • mantis: telegram-visible-proof: Mantis should capture Telegram visible proof. Inline keyboard rendering and readable fallback behavior are visibly demonstrable in a short Telegram chat flow.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the prior Telegram interactive-renderer unification, later question-row preservation work, and the current resolver refactor. (role: feature owner and recent area contributor; confidence: high; commits: ecaafb6a4f29, 999f14392b97, f631973a1052; files: extensions/telegram/src/button-types.ts, src/interactive/payload.ts)
  • Guoji-XYDT: Authored the recent degraded-inline-control behavior fix that the resolver’s fallback and dropped-control paths must preserve. (role: adjacent behavior contributor; confidence: medium; commits: 47bd1bb19412; files: extensions/telegram/src/button-types.ts, extensions/telegram/src/action-runtime.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 15e9bea into main Aug 24, 2026
321 of 323 checks passed
@steipete
steipete deleted the codex/cleanup2-telegram-renderer-20260824 branch August 24, 2026 13:24
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 25, 2026
…8728)

* refactor(telegram): unify interactive keyboard rendering

* chore(telegram): ratchet removed keyboard assertion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram maintainer Maintainer-authored PR mantis: telegram-visible-proof Mantis should capture Telegram visible proof. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant