Repository navigation
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs real behavior proof before merge. What this changesThis 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.
Review scores
ProductKind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Partial 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 Decision needed
Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherThe 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]
Technical reviewBest 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
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +127, Tests +814, Docs 0. Total +941 across 30 files. Added test files: 5. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes: No label changes. Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (9 earlier review cycles; latest 8 shown)
Reviewed October 13, 2026, 8:52 AM ET / 12:52 UTC (Revision 10). |
fceeaf1 to
eaa2282
Compare
eaa2282 to
4a7f204
Compare
…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.
4a7f204 to
6fcf591
Compare
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.
34bdba2 to
522fa7b
Compare
…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.
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).
|
Thanks for the thorough review — revision 4 ( P1 — ownership before presentation rendering. One shared resolver ( P2 — ownership across durable recovery. 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 Data-model compatibility proof. PR body, section "Data-model compatibility proof": a pinned pre-change queue row ( Real behaviour proof. PR body, section "Real-behavior proof": self-hosted run on a gateway built from this exact head ( Compatibility. Legacy Maintainer decision. This implements your recommendation — explicit agent-choice ownership with the @clawsweeper re-review |
|
🦞👀 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.
|
Added the published-release → this head upgrade/recovery run to the PR body (section "Upgrade/recovery proof"), on the current head
So existing stored data loads and keeps its previous behaviour after upgrade (live, base-versus-head), and the in-tree @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
disabled: true render as active and stay clickable
#191645
|
Closing as a duplicate of #196217, which landed as 928c118. That change fixes the same defect (#126950): typed callback buttons sent with the Verified on the Telegram Test Server at the merged head: tapping a typed Thank you for the analysis and the earlier fix here; it informed the review of the landed change. |
Related: #126950
What Problem This Solves
Fixes: tapping an agent-authored Telegram inline button (
action.type: "callback"sent through themessagetool) 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 ascallback_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.createTelegramCallbackRouteroffers 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:
messagetool already runsrunMessageActionwithactionOrigin: "message-tool"(model-authored call). That server-owned fact is forwarded intoChannelMessageActionContext(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.extensions/telegram/src/native-command-callback-data.tsaddstgac1:<checksum>:<value>next totgcb1:with the same checksum.toTelegramInlineButtonuses it whentypedCallbackOwner === "agent"; without the marker typed buttons keeptgcb1:exactly as before.renderPresentationhook beforesendPayload, and that step materializeschannelData.telegram.buttons; later steps keep rendered buttons as-is. One shared resolver,resolveTelegramTypedCallbackOwner(actionOrigin)inbutton-types.ts, now feeds every Telegram materialization step: therenderPresentationhook (fromctx.actionOrigin),sendPayload(fromparams.actionOrigin) andhandleTelegramAction(editand other plugin-handled actions). No step derives ownership on its own.QueuedDeliveryPayloadfields, so a send replayed after a restart lost the marker and rendered agent buttons as plugin controls.QueuedDeliveryPayloadgains an optionalactionOrigin?: "message-tool", written byprojectQueuedDeliveryOptionsonly when present, and the same projection restores it inbuildRecoveryDeliverParams, 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).messagesend does not stay insiderunMessageAction: it goes through the gateway send RPC and is dispatched straight to the plugin action handler. That dispatch context only carrieddeliveryRetryOwner;actionOriginwas lost there, beforehandleTelegramActiondecided ownership, so the live run on revision 3 still emittedtgcb1:.send.tsnow setsactionOrigin: "message-tool"on that context from the same host-owned signal (trustedContext.runtimeAgentId, i.e. the agent runtime client identity, never request params), next todeliveryRetryOwner. Nothing changes for CLI, operator or external RPC clients.tgcb1:branches matchmain(terminalize unowned plugin controls; the originalbot.test.tscase is in place).tgac1:joins the reserved typed prefixes for the inline-button gates, is never offered tohandleTelegramInteractiveCallback, terminalizes on a broken checksum or when inline buttons are disabled, and otherwise reaches the existing synthetic-text tail: keyboard cleared, agent receivescallback_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 retainedsend.message-tool-callback-ownership.test.tsexercises both agent-runtime and direct-CLI sends through the registered Telegram action and durable delivery to HTTP, with independently pinnedtgac1:andtgcb1:expectations. Cross-parser rejection checks remain inbutton-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 --checkand 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 throughscripts/run-vitest.mjswith 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.src/gateway/server-methods/send.message-tool-callback-ownership.test.tsdrives the realmessage.actionsend 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 yieldstgac1:1ffnt:btntest_typedinsendMessage.reply_markup, a direct CLI client yieldstgcb1:1ffnt:btntest_typed(checksums pinned independently of the plugin). The agent case fails on revision 3 withexpected 'tgcb1:1ffnt:btntest_typed' to be 'tgac1:1ffnt:btntest_typed', the same symptom as the live run.selectMessageActionOwnershipis the single place that turns the agent-runtime client identity intodeliveryRetryOwnerandactionOrigin.extensions/telegram/src/outbound-adapter.typed-callback-owner.test.tscalls the registeredrenderPresentationhook with and withoutctx.actionOrigin:tgac1:7ok4o:deploy prodvstgcb1:7ok4o:deploy prodinchannelData.telegram.buttons, checksum parsed back to the value, and an already rendered agent envelope is not re-wrapped by a later owner-less canonicalization (thesendPayloadstep).src/infra/outbound/delivery-queue.action-origin-recovery.test.tsdrivesdeliverOutboundPayloadsCorewith a probe channel whoserenderPresentationrecordsctx.actionOrigin, both live and afterenqueueDelivery→loadPendingDelivery(real SQLite row) →buildRecoveryDeliverParams→ delivery. Agent-owned sends render agent-owned on both paths and the row storesactionOrigin; sends without an origin render plugin-owned and the row has no such key; a pinned pre-change row JSON (noactionOrigin) decodes throughdecodeOutboundDeliverySnapshot, delivers, and renders plugin-owned. The recovery case fails on the previous revision (replay rendered plugin-owned).extensions/telegram/src/bot-handlers.callback-router.agent-choice.test.tsdrives the real router through a grammYBotand a loopback Bot API with hardcoded, independently computed checksums: agent choice delivered ascallback_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 intgcb1:is claimed), broken checksum → unavailable, inline buttons off → unavailable, retiredtgcb1:code-agent:approve-123→ unavailable.button-types.test.ts,interactive-fallback.test.ts,outbound-adapter.telegram-http.test.ts(registeredsendPayloadover 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 newdatabaseWorkerCoreTestFilesentry).tsgo -p tsconfig.core.jsonclean; the CI test type config withincludenarrowed 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 againstupstream/main— clean. CI remains the authority for the full matrix.docs/channels/telegram/rich-messages.mdcallback 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.jsoncommit matches) on my own server, isolated--profile standinstance (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 modelgoogle/gemini-3.8-flashwith a minimal AGENTS.md (proof-send-button <label> <value>→ exactly onemessagetool send withpresentation.blocks[{type:"buttons",buttons:[{label, action:{type:"callback", value}}]}]; any inboundcallback_data: …→ replyreceived: <value>). The "user" is a Telethon userbot on my own account (sends the trigger, reads the bot's message including the rawcallback_data, clicks viamsg.click, reads the follow-ups). Logs redacted (<chat>,<user>, tokens). Harness: a checksum script (FNV-1a → base36, self-tested ontgcb1:1ffnt:btntest_typed), a Bot APIsendMessagehelper for control buttons, the Telethon clicker and a journal collector.History on the same harness: revision 1 was checksum-only; revision 2 added the
tgac1envelope; revision 3 applied ownership inrenderPresentationand 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 on4a7f2049a50(P1) and on6fcf59190c9(dispatch hop); (b) and (c) PASS on every revision.Revision 4, reviewed head
5f9943a26e7(built from this exact commit):messagesend,{label:"Pick8", action:{type:"callback", value:"btntest_typed"}}tgac1:1ffnt:btntest_typedreceived: btntest_typed; no "This action is no longer available."callback_query→ 11:15:55.966Inbound message telegram:<chat> -> @<user> (direct, 28 chars)(=callback_data: btntest_typed) → 11:15:59outbound send ok … messageId=54tgcb1:yvak0:code-agent:approve-123(valid checksum, no plugin owner)callback_query→ 11:16:12.998typed callback unavailable (handler missing or payload invalid); noInbound messagelegacy_valuereceived: legacy_valuecallback_query→ 11:16:28.224Inbound message … (direct, 27 chars)→outbound send ok … messageId=58Queued-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 keepsgetUpdatesworking but dropssendMessage, themessagetool 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 afterstop → 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 bydelivery-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 astgcb1: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 emittgac1:. 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 anddeliver 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).
npm i [email protected](release buildb8952d477f0c) 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
sendMessageto 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 typedbutton via the
messagetool. 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_jsonkeys: 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.
("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-preflightok,
[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.tgcb1:1ffnt:btntest_typed(what the releasematerialised); clicking it →
typed callback unavailable (handler missing or payload invalid)→ keyboardremoved, "This action is no longer available.", agent not invoked (plugin-owned terminal path, unchanged).
proof-send-button Pick13 btntest_typed→ buttontgac1:1ffnt:btntest_typed→ click →Inbound message … (direct, 28 chars)→ agent repliedreceived: btntest_typed, no "no longer available"; (b)tgcb1:yvak0:code-agent:approve-123sent 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
messagesends surface the error to the model instead); replay of atgac1:-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 fordoctor --fix(agent db v24→v26), thendelivery-recoveryloaded the release's pendingoutbound-prepared-v1row (noactionOrigin), 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.tspinsLEGACY_ENTRY_JSON, a durable-queue row in the exact shape releases before this PR wrote into the SQLiteentry_jsoncolumn:{ id, enqueuedAt, retryCount, attemptCount, channel, to, queuePolicy, preparedBatch }wherepreparedBatchis produced by the samecreateUnmodifiedPreparedOutboundBatch(payloads)thatdelivery-queue-storage.tsuses at admission (payload: textDeploy?plus a presentation with one callback buttondeploy prod). The row has noactionOriginkey at all (expect(LEGACY_ENTRY_JSON).not.toContain("actionOrigin")); there is no schema-version field on queue rows anddecodeOutboundDeliverySnapshotonly validatesid/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 throughbuildRecoveryDeliverParams→deliverOutboundPayloadsCoreexactly asdelivery-queue-recovery.tsdoes after a restart, against a probe channel whoserenderPresentationrecordsctx.actionOriginand 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 storesactionOrigin: "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):In the third case the legacy row decodes without error, is delivered once,
renderedOriginsis[undefined]and the delivered text isplugin-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.