Skip to content

fix(telegram): typed inline buttons reply "This action is no longer available" instead of reaching the agent - #169504

Closed
aspalagin wants to merge 10 commits into
openclaw:mainfrom
aspalagin:fix/telegram-opaque-callback-text-fallback
Closed

aspalagin wants to merge 10 commits into
openclaw:mainfrom
aspalagin:fix/telegram-opaque-callback-text-fallback

Conversation

@aspalagin

@aspalagin aspalagin commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Related: #126950

What Problem This Solves

Fixes: tapping an agent-authored Telegram inline button (action.type: "callback" sent through the message tool) removes the keyboard and replies "This action is no longer available." instead of delivering the tap to the agent.

User Impact

Scope: this fixes typed callback buttons from Telegram-inbound agent turns. CLI-initiated agent turns still emit plugin-owned callbacks, so this PR does not fully resolve #126950.

User impact: typed callback buttons the agent sends through message (presentation.blocks[].buttons[].action = { type: "callback", value }) now reach the agent as callback_data: <value>, as documented in the Telegram rich-messages docs. Plugin-owned typed controls keep their current behavior: a registered interactive handler still claims them, and controls whose plugin was disabled or removed still reply "This action is no longer available." Legacy { label, value } buttons are unchanged. Ownership is applied where the buttons are rendered and survives a Gateway restart of a queued delivery.

Why This Change Was Made

Every typed callback button was encoded as tgcb1:<checksum>:<value>, the plugin-owned envelope. createTelegramCallbackRouter offers that envelope to plugin interactive handlers and, when none claims it, terminalizes it. Agent buttons never have a plugin handler, so every agent-authored tap was dead on arrival.

The fix keeps plugin ownership intact and gives agent buttons their own explicit path instead of relaxing the opaque guard:

  • Owner marker, host-owned. The agent message tool already runs runMessageAction with actionOrigin: "message-tool" (model-authored call). That server-owned fact is forwarded into ChannelMessageActionContext (createChannelActionContext) and, for durable core delivery of presentation payloads, into the outbound delivery context (OutboundChannelContext → ChannelOutboundContext). It is never read from model params or payload data. CLI, gateway background and plugin sends do not set it.
  • Agent envelope. extensions/telegram/src/native-command-callback-data.ts adds tgac1:<checksum>:<value> next to tgcb1: with the same checksum. toTelegramInlineButton uses it when typedCallbackOwner === "agent"; without the marker typed buttons keep tgcb1: exactly as before.
  • Ownership at render time (review P1). Core renders presentation through the plugin renderPresentation hook before sendPayload, and that step materializes channelData.telegram.buttons; later steps keep rendered buttons as-is. One shared resolver, resolveTelegramTypedCallbackOwner(actionOrigin) in button-types.ts, now feeds every Telegram materialization step: the renderPresentation hook (from ctx.actionOrigin), sendPayload (from params.actionOrigin) and handleTelegramAction (edit and other plugin-handled actions). No step derives ownership on its own.
  • Ownership across durable recovery (review P2). Queue admission projected only existing QueuedDeliveryPayload fields, so a send replayed after a restart lost the marker and rendered agent buttons as plugin controls. QueuedDeliveryPayload gains an optional actionOrigin?: "message-tool", written by projectQueuedDeliveryOptions only when present, and the same projection restores it in buildRecoveryDeliverParams, legacy preparation and custody restore. No new schema version: the row is plain JSON, the field is optional, rows written by earlier releases simply lack it and keep plugin-owned rendering (the prepared batch schema is untouched).
  • Ownership through gateway-dispatched plugin sends (revision 4, found by the live proof). Telegram runs its send action in gateway execution mode, so an agent message send does not stay inside runMessageAction: it goes through the gateway send RPC and is dispatched straight to the plugin action handler. That dispatch context only carried deliveryRetryOwner; actionOrigin was lost there, before handleTelegramAction decided ownership, so the live run on revision 3 still emitted tgcb1:. send.ts now sets actionOrigin: "message-tool" on that context from the same host-owned signal (trustedContext.runtimeAgentId, i.e. the agent runtime client identity, never request params), next to deliveryRetryOwner. Nothing changes for CLI, operator or external RPC clients.
  • Router. The tgcb1: branches match main (terminalize unowned plugin controls; the original bot.test.ts case is in place). tgac1: joins the reserved typed prefixes for the inline-button gates, is never offered to handleTelegramInteractiveCallback, terminalizes on a broken checksum or when inline buttons are disabled, and otherwise reaches the existing synthetic-text tail: keyboard cleared, agent receives callback_data: <value> (slash-prefixed values stay data, never commands).

Evidence

Test cleanup and scope clarification (2026-11-06)

Current head: a67d3b6f0438.

Removed extensions/telegram/src/action-runtime.typed-callback-owner.test.ts (112 lines, two duplicate cases), addressing the review's test-value note. The retained send.message-tool-callback-ownership.test.ts exercises both agent-runtime and direct-CLI sends through the registered Telegram action and durable delivery to HTTP, with independently pinned tgac1: and tgcb1: expectations. Cross-parser rejection checks remain in button-types.test.ts; adapter and recovery coverage is unchanged. No production code changed, and no explicit test registration referenced the deleted file.

Validation: independent source/history audit found no unique coverage in the removed file; git diff --check and formatting checks on the retained tests pass. The repository's changed-check dry run classifies this as an extension-test deletion. Runtime validation was attempted through scripts/run-vitest.mjs with one worker, a 2 GiB cap, and no swap: the combined Gateway/button selection and then the button-only selection were stopped during compiled-worker preparation at that cap. Neither attempt is a passing test run. Full type checks and a full build were not run for this test-only cleanup. Earlier test and live results below remain evidence from their recorded revisions.

Remaining work: the branch currently conflicts with main; the CLI-initiated agent scenario described below remains unresolved; the required Telegram Test Server proof and SDK owner decision are still outstanding. Accordingly this PR now uses Related: #126950, not an automatic issue-closing link.

  • Gateway dispatch hop, full core send path (revision 4): src/gateway/server-methods/send.message-tool-callback-ownership.test.ts drives the real message.action send handler with the bundled Telegram plugin (loaded through the plugin facade, so core tests still do not import the extension) to a loopback Bot API: an agent-runtime client yields tgac1:1ffnt:btntest_typed in sendMessage.reply_markup, a direct CLI client yields tgcb1:1ffnt:btntest_typed (checksums pinned independently of the plugin). The agent case fails on revision 3 with expected 'tgcb1:1ffnt:btntest_typed' to be 'tgac1:1ffnt:btntest_typed', the same symptom as the live run. selectMessageActionOwnership is the single place that turns the agent-runtime client identity into deliveryRetryOwner and actionOrigin.
  • Render path (P1): extensions/telegram/src/outbound-adapter.typed-callback-owner.test.ts calls the registered renderPresentation hook with and without ctx.actionOrigin: tgac1:7ok4o:deploy prod vs tgcb1:7ok4o:deploy prod in channelData.telegram.buttons, checksum parsed back to the value, and an already rendered agent envelope is not re-wrapped by a later owner-less canonicalization (the sendPayload step).
  • Durable recovery (P2) and compatibility: src/infra/outbound/delivery-queue.action-origin-recovery.test.ts drives deliverOutboundPayloadsCore with a probe channel whose renderPresentation records ctx.actionOrigin, both live and after enqueueDelivery → loadPendingDelivery (real SQLite row) → buildRecoveryDeliverParams → delivery. Agent-owned sends render agent-owned on both paths and the row stores actionOrigin; sends without an origin render plugin-owned and the row has no such key; a pinned pre-change row JSON (no actionOrigin) decodes through decodeOutboundDeliverySnapshot, delivers, and renders plugin-owned. The recovery case fails on the previous revision (replay rendered plugin-owned).
  • Router: extensions/telegram/src/bot-handlers.callback-router.agent-choice.test.ts drives the real router through a grammY Bot and a loopback Bot API with hardcoded, independently computed checksums: agent choice delivered as callback_data: <value> with the keyboard cleared (plain and slash-prefixed values), no cleanup when no keyboard is left, agent choice never offered to a plugin handler even inside a claimed namespace (positive control: the same namespace in tgcb1: is claimed), broken checksum → unavailable, inline buttons off → unavailable, retired tgcb1:code-agent:approve-123 → unavailable.
  • Builder/adapter: button-types.test.ts, interactive-fallback.test.ts, outbound-adapter.telegram-http.test.ts (registered sendPayload over HTTP by origin), src/infra/outbound/message-action-contracts.test.ts. Locally green: Telegram set 122 tests (7 files, incl. outbound-adapter.telegram-http.test.ts), core durable-queue set 122 tests (9 files, incl. delivery-queue.storage, deliver-queue-admission, delivery-queue-migration, delivery-queue.recovery, Vitest project-ownership tests for the new databaseWorkerCoreTestFiles entry).
  • Local checks ran in memory-bounded transient units on a 15 GB host: tsgo -p tsconfig.core.json clean; the CI test type config with include narrowed to the Telegram extension plus the two new core test files — clean. oxfmt, oxlint, format:docs:check, line-cap / max-lines / assertion-safety / test-mock-exports ratchets against upstream/main — clean. CI remains the authority for the full matrix.
  • Docs: docs/channels/telegram/rich-messages.md callback paragraph states the ownership rule, that it is decided at render time, and that it survives a restart.

Real-behavior proof (self-hosted)

Setup: gateway built from the PR head (dist/build-info.json commit matches) on my own server, isolated --profile stand instance (port 19789), Telegram production Bot API via long polling (not the Test Server; I have no access to the QA Convex lease), a throwaway test bot, agent model google/gemini-3.8-flash with a minimal AGENTS.md (proof-send-button <label> <value> → exactly one message tool send with presentation.blocks[{type:"buttons",buttons:[{label, action:{type:"callback", value}}]}]; any inbound callback_data: … → reply received: <value>). The "user" is a Telethon userbot on my own account (sends the trigger, reads the bot's message including the raw callback_data, clicks via msg.click, reads the follow-ups). Logs redacted (<chat>, <user>, tokens). Harness: a checksum script (FNV-1a → base36, self-tested on tgcb1:1ffnt:btntest_typed), a Bot API sendMessage helper for control buttons, the Telethon clicker and a journal collector.

History on the same harness: revision 1 was checksum-only; revision 2 added the tgac1 envelope; revision 3 applied ownership in renderPresentation and across durable recovery but still failed (a) live (tgcb1: on the wire) — tracing the running gateway showed the marker was dropped at the gateway dispatch hop described above, which revision 4 fixes. (a) FAIL on 4a7f2049a50 (P1) and on 6fcf59190c9 (dispatch hop); (b) and (c) PASS on every revision.

Revision 4, reviewed head 5f9943a26e7 (built from this exact commit):

Scenario Button sent as Click result Gateway log Result
(a) agent message send, {label:"Pick8", action:{type:"callback", value:"btntest_typed"}} tgac1:1ffnt:btntest_typed keyboard removed; agent replied received: btntest_typed; no "This action is no longer available." 11:15:55.882 callback_query → 11:15:55.966 Inbound message telegram:<chat> -> @<user> (direct, 28 chars) (= callback_data: btntest_typed) → 11:15:59 outbound send ok … messageId=54 PASS
(b) Bot API send, tgcb1:yvak0:code-agent:approve-123 (valid checksum, no plugin owner) as sent keyboard removed; bot replied "This action is no longer available."; agent NOT invoked 11:16:12.982 callback_query → 11:16:12.998 typed callback unavailable (handler missing or payload invalid); no Inbound message PASS
(c) Bot API send, raw legacy_value as sent keyboard removed; agent replied received: legacy_value 11:16:28.118 callback_query → 11:16:28.224 Inbound message … (direct, 27 chars) → outbound send ok … messageId=58 PASS

Queued-restart replay (P2) was attempted live and turned out not to be reproducible by design: with a local Bot API proxy in front of the stand (channels.telegram.apiRoot) that keeps getUpdates working but drops sendMessage, the message tool send failed synchronously ([tools] message failed: OutboundDeliveryError: Network request for 'sendMessage' failed! raw_params={"presentation":{"blocks":[{"type":"buttons",…) and surfaced to the model (caller-owned retry), so the only durable entry left was the turn's final text reply (recovery_state=completed_permanent) and there was nothing to replay after stop → unblock → start. The restart-replay path for a message-tool send is therefore only reachable in the enqueue → platform-send crash window, which I could not hit live; it stays covered by delivery-queue.action-origin-recovery.test.ts (real SQLite row, see below).

Side observation, not part of this PR's claim: an agent turn started via the CLI (openclaw agent --channel telegram --to … --message "proof-send-button …") emits the same button as tgcb1: both live and after a durable replay (that path does queue and replay on restart: [delivery-recovery] Found 1 pending delivery entries — starting recovery … Recovered delivery … on telegram). Telegram-inbound turns emit tgac1:. CLI-initiated turns apparently do not present the agent-runtime identity to the gateway send RPC, so their buttons stay plugin-shaped — worth a follow-up, out of scope here.

Not proven: Telegram Test Server; group chats / topics; non-Gemini models; the live crash-window replay.

Upgrade/recovery proof (published v2026.10.2 → this head, 3764614)

Goal: show that durable-queue rows written by the published release (no actionOrigin) still load and
deliver after switching the same state directory to this branch, and that the upgraded instance behaves as
claimed. Same self-hosted stand as the earlier proofs (isolated --profile stand, production Telegram Bot API,
throwaway bot, Telethon userbot on the owner's account for clicks; logs redacted).

  1. Release writes the row. npm i [email protected] (release build b8952d477f0c) into a private prefix,
    started on a fresh state dir for the stand profile (the release refuses state written by this branch:
    "state database uses schema 21; this build supports 20" — expected, that is a downgrade). With outbound
    sendMessage to api.telegram.org blocked for the stand's cgroup only, an agent turn
    (openclaw agent --channel telegram --to … --message "proof-send-button Pick12 btntest_typed") sent a typed
    button via the message tool. The release queued it: [delivery-recovery] Outbound delivery retry: entry 9addf650-… not ready for retry yet, [telegram] sendMessage failed: Network request for 'sendMessage' failed!.
    SQLite delivery_queue_entries: status=pending entry_kind=outbound-prepared-v1 channel=telegram retry_count=2;
    entry_json keys: accountId, attemptCount, channel, effectiveReplyToId, enqueuedAt, forceDocument,
    gatewayClientScopes, id, lastAttemptAt, lastError, preparedBatch, queuePolicy, renderedBatchPlan,
    requiresProducerClaim, retryCount, session, to — no actionOrigin;
    preparedBatch.entries[0].payload.channelData.telegram.buttons = [[{"text":"Pick12","callback_data":"tgcb1:1ffnt:btntest_typed"}]].
    Gateway stopped with the row still pending.
  2. Switch to this branch on the same state. First start exits 78 with the standard upgrade gate
    ("agent database uses schema version 24; run openclaw doctor --fix"). doctor --fix --non-interactive:
    pre-migration SQLite backups saved, "Upgraded agent database schema … v24 -> v26". Start: state.schema-preflight
    ok, [gateway] ready, [delivery-recovery] Found 1 pending delivery entries — starting recovery →
    outbound send ok … messageId=66 → Recovered delivery 9addf650-… on telegram → Delivery recovery complete: 1 recovered, 0 failed. No migration/decoder/session errors in the journal.
  3. Legacy row behaves as before. The recovered message carried tgcb1:1ffnt:btntest_typed (what the release
    materialised); clicking it → typed callback unavailable (handler missing or payload invalid) → keyboard
    removed, "This action is no longer available.", agent not invoked (plugin-owned terminal path, unchanged).
  4. Upgraded instance, Telegram-originated turns: (a) proof-send-button Pick13 btntest_typed → button
    tgac1:1ffnt:btntest_typed → click → Inbound message … (direct, 28 chars) → agent replied
    received: btntest_typed, no "no longer available"; (b) tgcb1:yvak0:code-agent:approve-123 sent via Bot API →
    click → typed callback unavailable → "This action is no longer available.", agent not invoked;
    (c) raw legacy_value → click → Inbound … (27 chars) → received: legacy_value. All PASS.

Not proven: Telegram Test Server; the release row was produced by a CLI-initiated agent turn (that path queues
on network failure, Telegram-inbound message sends surface the error to the model instead); replay of a
tgac1:-owned row across restart is covered by the unit test with a real SQLite row, not live.

Data-model compatibility proof

Published-release data (live). The upgrade/recovery run above used rows written by the published [email protected] on the same state directory: the branch's startup gate asked for doctor --fix (agent db v24→v26), then delivery-recovery loaded the release's pending outbound-prepared-v1 row (no actionOrigin), delivered it and kept its plugin-owned rendering. The pinned fixture below is the in-tree regression for the same contract.

Fixture. src/infra/outbound/delivery-queue.action-origin-recovery.test.ts pins LEGACY_ENTRY_JSON, a durable-queue row in the exact shape releases before this PR wrote into the SQLite entry_json column: { id, enqueuedAt, retryCount, attemptCount, channel, to, queuePolicy, preparedBatch } where preparedBatch is produced by the same createUnmodifiedPreparedOutboundBatch(payloads) that delivery-queue-storage.ts uses at admission (payload: text Deploy? plus a presentation with one callback button deploy prod). The row has no actionOrigin key at all (expect(LEGACY_ENTRY_JSON).not.toContain("actionOrigin")); there is no schema-version field on queue rows and decodeOutboundDeliverySnapshot only validates id/enqueuedAt/retryCount, so this is what an existing database contains after upgrade.

What the test does. It feeds that JSON through the production decoder (decodeOutboundDeliverySnapshot({ queueName: OUTBOUND_DELIVERY_QUEUE_NAME, entryJson })), then through buildRecoveryDeliverParams → deliverOutboundPayloadsCore exactly as delivery-queue-recovery.ts does after a restart, against a probe channel whose renderPresentation records ctx.actionOrigin and prefixes the text with the owner it derived. The two sibling cases run the same live-then-replay path for an agent-owned send (row stores actionOrigin: "message-tool", replay renders agent-owned) and for a send without origin (row has no key, replay renders plugin-owned).

Result (vitest run --reporter=verbose, revision 4):

✓ typed callback ownership across durable recovery › renders agent-owned message-tool sends the same way live and after replay
✓ typed callback ownership across durable recovery › renders plugin and operator sends the same way live and after replay
✓ typed callback ownership across durable recovery › loads rows stored before ownership existed and keeps them plugin-owned
Test Files  1 passed · Tests  3 passed

In the third case the legacy row decodes without error, is delivered once, renderedOrigins is [undefined] and the delivered text is plugin-owned:Deploy? — rows written before the change keep their previous (plugin-owned) behaviour, nothing is re-encoded or migrated. New rows only gain the optional key when the send actually came from the message tool.

@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: M labels Oct 12, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. 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. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR gives agent-authored Telegram callback buttons a separate envelope and carries their ownership through rendering and durable recovery.

Example: An agent responding to a Telegram message sends a Pick button with callback value btntest_typed.

  • Before: Tapping the button clears its keyboard and replies “This action is no longer available.”
  • After: Tapping the button delivers callback_data: btntest_typed to the agent.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful repair with production flow and published-release recovery evidence, no discrete introduced bug found, and remaining owner and scoped-proof gates.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Partial
User problem: A user taps a documented agent-authored Telegram choice, but the choice never reaches the agent.
Reason: The repair has demonstrated user value, but the additive plugin-context contract needs owner direction; use Related rather than closing the linked issue while CLI-initiated message-tool buttons remain broken.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open: this PR repairs confirmed current-main callback loss while preserving plugin ownership, but the additive SDK ownership contract needs area-owner direction.

Priority: P1
Reviewed head: 3764614b32072d15968b9f927a50ecbd881f3c48
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should the SDK-visible action and outbound contexts expose host-owned actionOrigin for the separate Telegram agent-choice envelope?
  • Recommendation: Adopt explicit agent ownership: Approve the additive host-origin contract and separate agent envelope while retaining existing plugin and stored-button semantics.
  • Why: The documented agent-choice bug merits repair, but this PR adds an ownership contract to plugin-facing contexts; no written area-owner approval of that contract was found.

Before merge

  • Add real behavior proof - The fully fetched PR body supplies production-Telegram Gateway message-tool and click output on the upgraded current head, including agent delivery, retired-plugin rejection, and legacy delivery; root policy still requires Test Server userbot evidence, which the author explicitly marks outstanding. Attach redacted logs, live output, or a recording without API keys, phone numbers, IPs, or non-public endpoints. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

None.

Tests

  • Low-value test extensions/telegram/src/action-runtime.typed-callback-owner.test.ts: Remove this duplicate send-origin matrix: the Gateway-to-wire test exercises the same registered Telegram action and durable send path with independent envelope expectations.
  • Missing end-to-end proof: Attach the required Telegram Test Server userbot run showing an agent typed-button tap reaching the agent and a retired plugin control remaining unavailable.
Agent review details

How this fits together

The Gateway passes message-tool origin into shared outbound delivery and Telegram rendering; Telegram callback routing converts authorized agent-choice taps into inbound agent messages while retaining plugin-owned routing.

flowchart LR
  A[Agent message tool] --> B[Gateway action context]
  B --> C[Outbound delivery and queue]
  C --> D[Telegram button renderer]
  D --> E[Telegram callback router]
  E --> F[Agent inbound message]
  E --> G[Plugin handler or unavailable feedback]
Loading

Technical review

Best possible solution:

Restore typed agent-choice delivery through explicit host-owned origin while preserving plugin controls and tracking the remaining CLI-initiated path separately.

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

Current-main producer and router source establish the failure, supported by independent official-release reports; this read-only review ran no target code.

Is this the best way to solve the issue?

Explicit ownership is safer than allowing unclaimed plugin callbacks to fall through, although the supplied live run shows that CLI-initiated agent turns remain outside the repaired path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against a1e828269c9a.

Provenance checked

  • Typed callback action separation keeps the original intent (d641126: Typed presentation actions preserve command, callback, and approval distinctions across channels.)
  • Unhandled plugin callback terminalization keeps the original intent (4d91d44: Retired or malformed plugin buttons must provide unavailable feedback rather than becoming raw agent input.)
  • Gateway runtime ownership and retries keeps the original intent (10169f0: Message actions retain current runtime and scheduled authority through preparation and effects.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +127, Tests +814, Docs 0. Total +941 across 30 files. Added test files: 5.

View PR surface stats
Area Files Added Removed Net
Source 20 172 45 +127
Tests 9 814 0 +814
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 30 987 46 +941

Review metrics

Metric Value Why it matters
Ownership contract additions Two plugin-facing contexts and one durable payload gain optional actionOrigin. The existing message-tool origin becomes available to channel rendering and recovery without a new configuration option or SQL schema version.

Root-cause cluster

Relationship: partial_overlap
Canonical: #126950
Summary: This PR addresses the canonical typed agent-button failure for Telegram-originated turns, with a documented CLI-initiated remainder.

Members:

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Documented Telegram message-tool buttons lose user choices on current main and multiple official releases.
  • merge-risk: 🚨 compatibility: The patch extends plugin-facing ownership contexts and changes routing semantics for newly rendered agent-authored typed callbacks.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. The PR changes visible inline-button tap delivery, keyboard cleanup, and agent replies, all observable through Telegram Test Server userbot clicks.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Provide the required Test Server callback proof.
  • Obtain area-owner direction on the additive ownership contract.
  • Remove the duplicated registered-send origin matrix.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (9 earlier review cycles; latest 8 shown)
  • reviewed 2026-10-12T23:39:21.299Z sha eaa22828cbd0be10ff0740a9329083d8e4531ce8 :: needs real behavior proof before merge. :: [P1] Apply agent ownership before presentation rendering | [P2] Preserve callback ownership across durable recovery
  • reviewed 2026-10-13T06:12:55.133Z sha 4a7f2049a507e3ce51a05fccbbb0d1b3381f0765 :: needs real behavior proof before merge. :: [P1] Apply agent ownership before presentation rendering | [P2] Preserve callback ownership across durable recovery
  • reviewed 2026-10-13T07:12:16.471Z sha 6fcf591 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-13T08:20:37.443Z sha 522fa7b :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-13T08:31:30.661Z sha 30e8028 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-13T11:09:50.901Z sha 5f9943a :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-13T11:35:29.383Z sha 5f9943a :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-13T12:42:16.351Z sha 3764614 :: needs real behavior proof before merge. :: none

Reviewed October 13, 2026, 8:52 AM ET / 12:52 UTC (Revision 10).

@aspalagin
aspalagin force-pushed the fix/telegram-opaque-callback-text-fallback branch from fceeaf1 to eaa2282 Compare October 12, 2026 23:03
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: L and removed size: M labels Oct 12, 2026
@aspalagin
aspalagin force-pushed the fix/telegram-opaque-callback-text-fallback branch from eaa2282 to 4a7f204 Compare October 13, 2026 06:05
…vailable" instead of reaching the agent

Agent inline buttons with action.type "callback" are encoded as typed tgcb1 payloads. When no plugin interactive handler claims the namespace, the callback router terminalized the click instead of delivering the documented `callback_data: <value>` text to the agent, so every agent-authored button was dead on arrival.

Typed callbacks with a valid checksum now fall through to the generic text path: the keyboard is cleared and the agent receives `callback_data: <value>` (never interpreted as a command, even for slash-prefixed values). Malformed payloads and disabled inline buttons still terminalize.
…hile keeping plugin-owned controls terminal

Agent inline buttons sent through the message tool with action.type "callback" were encoded as plugin-style tgcb1 payloads. With no plugin interactive handler owning them, the callback router terminalized every tap with "This action is no longer available." instead of delivering the documented `callback_data: <value>` text to the agent.

Typed callback buttons now carry an explicit owner. Model-authored message-tool sends (host-owned actionOrigin, forwarded through the message action context and the durable delivery context) encode their buttons as tgac1:<checksum>:<value>; the router delivers a valid agent choice to the agent as `callback_data: <value>` (never a command, even for slash-prefixed values) and terminalizes broken checksums or disabled inline buttons. Plugin-owned tgcb1 controls keep their vanilla routing: registered handlers claim them and retired or unowned controls still reply that the action is no longer available.
…tion

Core renders presentation through the plugin renderPresentation hook before
sendPayload, so buttons were materialized as plugin-owned tgcb1: envelopes and
the later sendPayload owner could not change them. Derive the typed callback
owner from the host-owned ctx.actionOrigin in the render hook as well, through
one shared resolver used by every Telegram button materialization step.
Queue admission projected only existing QueuedDeliveryPayload fields, so a
message-tool send replayed after a Gateway restart lost actionOrigin and its
agent-owned buttons rendered as plugin controls. Persist the origin with the
queued delivery row (optional field, absent for every other producer and on
rows written by earlier releases) and restore it on replay.
@aspalagin
aspalagin force-pushed the fix/telegram-opaque-callback-text-fallback branch from 4a7f204 to 6fcf591 Compare October 13, 2026 07:02
@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Oct 13, 2026
Telegram runs its send action in gateway execution mode, so a message-tool
send reaches the gateway send RPC and is dispatched straight to the plugin
action handler. That dispatch context only carried deliveryRetryOwner; the
host action origin was lost before the Telegram handler decided callback
ownership, so agent buttons were still rendered as plugin-owned tgcb1 data.

Derive both ownership facts in one host-owned helper
(selectMessageActionOwnership, keyed on the agent runtime client identity,
never request params) and spread it into the dispatch context. Cover the
registered Telegram send action down to the Bot API reply_markup in a
loopback test.
@aspalagin
aspalagin force-pushed the fix/telegram-opaque-callback-text-fallback branch from 34bdba2 to 522fa7b Compare October 13, 2026 08:10
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Oct 13, 2026
…gram send action

Drive the real message.action send through the bundled Telegram plugin
facade to a loopback Bot API: an agent-runtime client yields an agent-owned
tgac1 callback button on the wire, a direct CLI client keeps the plugin-owned
tgcb1 envelope. The agent case fails without the gateway dispatch fix.
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Oct 13, 2026
Build the request context from the shared makeContext fixture instead of a
direct cast, and keep the loopback Bot API handler's promise out of the
http server callback (no-misused-promises).
@aspalagin

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review — revision 4 (5f9943a26e7) is up; the two commits after 30e802846e4 only fix typing/lint in the new gateway test, no runtime change. Everything you listed under Before merge is addressed in the PR body; summary:

P1 — ownership before presentation rendering. One shared resolver (resolveTelegramTypedCallbackOwner in button-types.ts) feeds every Telegram materialization step: the renderPresentation hook, sendPayload and handleTelegramAction. Covered by outbound-adapter.typed-callback-owner.test.ts (hook) and action-runtime.typed-callback-owner.test.ts (the registered send action through handleTelegramAction and core delivery to a loopback Bot API: tgac1: with a valid checksum for ctx.actionOrigin: "message-tool", tgcb1: without).

P2 — ownership across durable recovery. QueuedDeliveryPayload.actionOrigin is written only when present and restored by the same projection on recovery, legacy preparation and custody restore. delivery-queue.action-origin-recovery.test.ts drives the live path and a real SQLite row through buildRecoveryDeliverParams; replay renders agent-owned for message-tool sends and plugin-owned otherwise.

Dispatch hop (found by the live run on revision 3). Telegram declares gateway execution mode for its actions, so a message-tool send is dispatched through the gateway send RPC straight to handleAction, and that dispatch context carried deliveryRetryOwner but not actionOrigin. selectMessageActionOwnership now derives both from the agent-runtime client identity (host-owned, never request params or payload) and the dispatch context spreads it. send.message-tool-callback-ownership.test.ts covers the full core send path: the real message.action handler with the bundled Telegram plugin to a loopback Bot API — agent-runtime client → tgac1:1ffnt:btntest_typed in reply_markup, direct CLI client → tgcb1:…; the agent case fails on revision 3 with exactly the live symptom.

Data-model compatibility proof. PR body, section "Data-model compatibility proof": a pinned pre-change queue row (LEGACY_ENTRY_JSON, the exact entry_json shape earlier releases wrote, no actionOrigin key; queue rows carry no schema version and the decoder only validates id/enqueuedAt/retryCount) goes through decodeOutboundDeliverySnapshot → buildRecoveryDeliverParams → deliverOutboundPayloadsCore and renders plugin-owned (renderedOrigins = [undefined], text plugin-owned:Deploy?), i.e. existing rows keep their previous behaviour, nothing is migrated or re-encoded.

Real behaviour proof. PR body, section "Real-behavior proof": self-hosted run on a gateway built from this exact head (5f9943a26e7), production Telegram, a Telethon userbot on my own account tapping the buttons: (a) agent message send → tgac1:1ffnt:btntest_typed on the wire, tap delivered as callback_data: btntest_typed, keyboard cleared, no "This action is no longer available."; (b) retired tgcb1:yvak0:code-agent:approve-123 → unavailable, agent not invoked; (c) raw legacy_value → delivered. The same harness showed (a) FAIL on 4a7f2049a50 (P1) and on 6fcf59190c9 (dispatch hop). I do not have access to the QA Convex lease, so this is not the Test Server userbot harness and is labelled as such. The live queued-restart replay was attempted twice (network block of sendMessage via a local Bot API proxy): a failed message-tool send surfaces synchronously to the model with caller-owned retry, so nothing agent-owned stays queued outside the enqueue → platform-send crash window; that path remains covered by the SQLite-row recovery test. One side observation from those attempts: agent turns started via the CLI (openclaw agent --channel telegram …) still emit tgcb1: because that client does not present the agent-runtime identity — out of scope here, happy to follow up.

Compatibility. Legacy {label, value} buttons, plugin-owned tgcb1: controls, approval/question/native-command callbacks and retired controls are unchanged (scenarios (b)/(c) live; router tests). CLI/operator/external RPC sends never carry the origin.

Maintainer decision. This implements your recommendation — explicit agent-choice ownership with the tgac1 envelope and a host-provided actionOrigin — while keeping every plugin guarantee from #116383. Keeping every typed button plugin-shaped and documenting legacy {label, value} for agents remains a one-commit fallback if an area owner prefers it.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

Remove message-action-contracts.test.ts (it mirrored the actionOrigin
assignment instead of proving a user-facing contract) and the typed
callback owner matrix in interactive-fallback.test.ts (already covered by
the registered rendering hook, the HTTP adapter test and the Gateway-to-wire
test). No runtime changes.
@aspalagin

Copy link
Copy Markdown
Contributor Author

Added the published-release → this head upgrade/recovery run to the PR body (section "Upgrade/recovery proof"), on the current head 3764614b320 (the commit after 5f9943a26e7 only removes the two duplicate test matrices you flagged):

  • [email protected] (published build b8952d477f0c) ran the stand profile on a fresh state directory and, with sendMessage blocked for that process only, queued an agent-authored typed button: delivery_queue_entries row status=pending, entry_kind=outbound-prepared-v1, no actionOrigin key, buttons already materialised as tgcb1:1ffnt:btntest_typed.
  • Switching the same state directory to this branch hit the standard upgrade gate (doctor --fix, agent db v24→v26, pre-migration backups), then [delivery-recovery] Found 1 pending delivery entries — starting recovery … Recovered delivery … 1 recovered, 0 failed. The recovered release-written button stayed plugin-owned: tap → typed callback unavailable → "This action is no longer available.", agent not invoked. No migration/decoder/session errors.
  • On the upgraded instance, Telegram-originated turns: (a) agent button → tgac1:1ffnt:btntest_typed, tap delivered as callback_data: btntest_typed; (b) retired tgcb1:…:code-agent:approve-123 → unavailable; (c) raw legacy_value → delivered.

So existing stored data loads and keeps its previous behaviour after upgrade (live, base-versus-head), and the in-tree delivery-queue.action-origin-recovery.test.ts pins the same contract. The duplicate matrices (message-action-contracts.test.ts, the owner matrix in interactive-fallback.test.ts) are removed. Still outstanding on my side: the Telegram Test Server userbot run — I am setting up test-DC credentials of my own to run the telegram-e2e-userbot lane and will attach that output separately.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus

obviyus commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

Closing as a duplicate of #196217, which landed as 928c118.

That change fixes the same defect (#126950): typed callback buttons sent with the message tool now render as an agent-owned tgac1: envelope, and an unclaimed tap reaches the agent as callback_data: <value>. Retired plugin controls (tgcb1:) keep expiring. It does this inside the Telegram plugin, without the core-wide actionOrigin plumbing in this PR, and it also covers turns this PR left open (for example CLI-started turns), because ownership is marked where message sends and edits render.

Verified on the Telegram Test Server at the merged head: tapping a typed pick:alpha button reached the agent and got GOT pick:alpha, where main replied "This action is no longer available."

Thank you for the analysis and the earlier fix here; it informed the review of the landed change.

@obviyus obviyus closed this Nov 13, 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 docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram: opaque callback payloads (tgcb1:) silently dropped for non-plugin callers

2 participants