Repository navigation
fix(telegram): preserve callback action ownership - #116383
Conversation
|
Codex review: stale review; fresh review needed. Summary Next step Review history (4 earlier review cycles)
|
6ff5ea5 to
21bc4c3
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Post-merge note on the change in direction: we intentionally narrowed this PR. The earlier version tried to solve two things at once: redesign how question choices are identified across the Gateway/SDK, and fix Telegram callback routing. After tracing the failure on current The landed fix changes the Telegram “traffic cop” instead:
In simple terms: we stopped changing the shared question system and fixed ownership where the mix-up happens—inside Telegram routing. This is smaller, preserves existing plugin buttons, and guarantees a visible outcome. We verified the final behavior through an exact-head mock-Gateway callback run and a real Telegram userbot round trip. |
…e agent (#196217) * fix(telegram): agent inline button taps expire instead of reaching the agent Closes #126950 ## What Problem This Solves Fixes: tapping an inline button an agent sent with the `message` tool (`presentation` button with `action: { type: "callback", value }`) removes the keyboard and replies "This action is no longer available." instead of delivering the choice to the agent. The agent's own system prompt recommends exactly this button shape, so every agent-authored Telegram choice is dead on arrival, on Telegram-started and CLI-started turns alike. ## User Impact User impact: a tap on an agent's typed callback button now reaches the agent as `callback_data: <value>`, as `docs/channels/telegram/rich-messages.md` already promised, for `message` sends and edits. The send itself carries the ownership rather than the caller's origin, so turns started outside Telegram (CLI, cron) take the same code path; the live proof below drives Telegram-started turns. A plugin interactive handler that registers the value's namespace still claims the tap first. Typed controls sent by any other producer keep today's behavior: no handler, no fallback, "This action is no longer available." Legacy `{ label, value }` buttons are unchanged. Buttons already delivered before the upgrade carry the old envelope and still expire when tapped; the agent can resend them. ## Why This Change Was Made Every typed callback was encoded as `tgcb1:`, the envelope whose unclaimed taps terminalize by design (#116383, so retired plugin buttons do not become raw agent input). Telegram had no way to tell an agent's button from a plugin's. Telegram now records that ownership itself, at the two places only `message` actions reach, so no core or Plugin SDK contract changes: - `prepareSendPayload` (the SDK hook core calls only for `message(action=send)` before persisting the payload) marks presentations that carry controls with Telegram-private `channelData.telegram.typedCallbackOwner: "agent"`. The mark travels in the persisted payload, so queued and recovered deliveries keep it. - `resolveTelegramButtonsFromParams`, used only by the Telegram action runtime that `message` actions reach (for example `edit`), renders its controls as agent-owned. - `canonicalizeTelegramPresentationPayload`, the single presentation-to-keyboard step every send funnel uses, encodes agent-owned typed callbacks as `tgac1:<checksum>:<value>` (same checksum and byte budget as `tgcb1:`). - The callback router offers a valid `tgac1:` value to plugin handlers exactly like today, then delivers it as `callback_data: <value>` (never as a slash command or approval). A malformed `tgac1:` payload, or any tap while inline buttons are off for the chat, terminalizes like `tgcb1:`. `tgcb1:` semantics, plugin dispatch, and the approval, question, native-command, and model-picker namespaces are untouched. ## Evidence - New `extensions/telegram/src/bot.agent-callbacks.test.ts` drives the real producer (`prepareSendPayload` → `canonicalizeTelegramPresentationPayload`) and the real callback router: the tap reaches the agent as `callback_data: /usdt remind|today 20:00` (slash and delimiter stay data) and the keyboard is cleared. Red on `upstream/main` (unavailable reply, no agent turn), green with the fix. The same file pins that malformed `tgac1:` payloads and taps with inline buttons off still terminalize without plugin dispatch or raw-text fallthrough. - `action-runtime.test.ts`: a `message(action=edit)` with a typed callback reaches Bot API `editMessageText` with an agent envelope (red without the change, green with it). - Consumer suites: `action-runtime`, `bot.create-telegram-bot`, `bot`, `bot.callback-retry`, `bot-handlers.callback-questions.runtime`, `button-types`, `channel-actions.contract`, `interactive-fallback`, `native-command-callback-data`, `outbound-adapter.normalize-payload`, `outbound-adapter.telegram-http`: all green. - `pnpm check:changed --base upstream/main`: format, lint, extension and extension-test typecheck, import cycles, line-cap and boundary guards pass. Two checks fail only on files this PR does not touch: changelog attributions (`CHANGELOG/*`) and the dead-export scan (`src/daemon/launchd.ts`, `ui/src/pages/dashboards/dashboard-tools.tsx`). - Live Telegram round trip: see below. Change size against the merge base: production +69/-11 in 6 files, tests +122 in 2 files, docs 1 line. No core, Plugin SDK, protocol, config, or schema change. ### Live Telegram round trip: real user, real bot, isolated exact-head Gateway Why not the Test Server: the repository's Telegram Test Server credentials are maintainer-leased through Convex, and Telegram stopped provisioning new Test Server accounts for random `99966X` numbers in 2026 (`signIn` returns `PHONE_CODE_INVALID` on DC 1–3; noted in gotd/td `telegram/auth` and in mctlhq/mctl-telegram#854). So this proof runs the same flow on production Telegram: - a Telegram bot created only for this proof, talking to one real Telegram user account in a private chat; - an isolated Gateway (own state dir, port and config; `dmPolicy: "allowlist"` with that one user) started from `node dist/entry.js gateway` built from this head `f1f382b9333`, and, for the contrast run, from `upstream/main` `4b077d31b91`; - for scenarios (a)–(c) and the contrast, the repository mock model `scripts/e2e/mock-openai-server.mjs` (chat completions), scripted to make the agent call the `message` tool with typed callback buttons; for scenario (r), a real model (`claude-haiku-5-5` through the `claude-cli` runtime) that is only asked in chat to send two buttons and to answer a tap; - the user side driven over MTProto (Telethon): send a message, read the bot's inline keyboard, tap a button (`messages.getBotCallbackAnswer`), and record every message, edit and keyboard change in the chat for 20–30 s after each action. Scenarios: (a) `message(action=send)` with typed callbacks, then a tap; (b) `message(action=edit)` that puts a new typed callback on that message, then a tap; (c) a control with the plugin envelope whose plugin is not installed (posted by the bot through Bot API `sendMessage` with `callback_data` from `buildTelegramOpaqueCallbackData("retired-plugin:approve")`, which is how a plugin-sent typed control renders), then a tap; (r) the same send and tap with the real model; (u) the nearest forbidden principal: the same agent envelope, posted by the bot, tapped by a user the Gateway's `allowFrom` does not include (the Gateway runs with `allowFrom: ["1"]`); contrast: scenario (a) on `upstream/main`. Identifiers are redacted: `<tester-id>`, `<bot-id>`, `<test-bot>`. No Telegram client screenshots: the test user account has two-step verification, so a fresh Telegram Web session cannot be opened without its password. The chat state below (messages, edits, keyboards with their `callback_data`) is read from that user's existing MTProto session after every action, so it is what any Telegram client shows. Result, read from the raw output below (`mockRequestsBefore`/`mockRequestsAfter` count every request the mock model received; scenario (r) has no mock): | Scenario | `upstream/main` `4b077d31b91` | This head (tree `4c112e5f`) | |---|---|---| | (a) `message` send renders the buttons as | `tgcb1:4f7dt:/pick beta\|2` (plugin envelope) | `tgac1:4f7dt:/pick beta\|2` (agent envelope) | | (a) tap "Beta" | keyboard removed, bot replies "This action is no longer available.", model requests 4 → 4 (no agent turn) | keyboard removed, a new agent turn whose user message is `callback_data: /pick beta\|2` (slash and `\|` stay data), agent replies `MODEL_SAW_CALLBACK` | | (b) `message` edit puts "Gamma" on the agent's message | not run | the agent's own message (bot-side id 12) becomes "Pick again" with `tgac1:1f5uj:pick:gamma` | | (b) tap "Gamma" | not run | keyboard removed, a new agent turn whose user message is `callback_data: pick:gamma`, agent replies `MODEL_SAW_EDITED_CALLBACK` | | (c) tap a `tgcb1:` control whose plugin is not installed | not run (same `tgcb1:` path) | keyboard removed, "This action is no longer available.", model requests unchanged (no agent turn) | | (r) real model (`claude-haiku-5-5`, `claude-cli`) asked in chat to send "Alpha"/"Beta" | not run | the model calls `message` itself; the buttons arrive as `tgac1:bcaw3:pick:alpha` and `tgac1:17dsn:pick:beta` | | (r) tap "Beta" | not run | keyboard removed, a new model turn, the model replies `GOT pick:beta` | | (u) tap an agent envelope (`tgac1:1kkc4:pick:unauthorized`) as a user outside `allowFrom` | not run | rejected before any effect: no agent turn (model requests 0 → 0), the message and its keyboard stay unchanged, no reply | Gateway trees: this head `4c112e5fd1b0327d95f54d6d52eb862ac6533175`, base `cb575aeaedcd153f4bfdd41b559834604ad3c106` (`git rev-parse HEAD^{tree}`). Regression tests from this PR, run against each tree (`pnpm vitest run extensions/telegram/src/bot.agent-callbacks.test.ts extensions/telegram/src/action-runtime.test.ts -t "message-send|agent-owned"`; on the base the two test files were copied in, then removed). The "inline buttons turned off" case is a guard that passes on both by design. <details><summary>Test output: <code>upstream/main</code> (red) and this head (green)</summary> ```text # upstream/main 4b077d3 × |extension-database-workers| extensions/telegram/src/action-runtime.test.ts > Telegram registered action authority and input contracts > renders typed callbacks in message-action edits as agent-owned controls 6653ms × |extension-telegram| extensions/telegram/src/bot.agent-callbacks.test.ts > delivers an unclaimed message-send tap to the agent as callback data 34ms × |extension-telegram| extensions/telegram/src/bot.agent-callbacks.test.ts > expires a message-send tap with a malformed envelope 3266ms ✓ |extension-telegram| extensions/telegram/src/bot.agent-callbacks.test.ts > expires a message-send tap with inline buttons turned off 5ms ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 3 ⎯⎯⎯⎯⎯⎯⎯ FAIL |extension-database-workers| extensions/telegram/src/action-runtime.test.ts > Telegram registered action authority and input contracts > renders typed callbacks in message-action edits as agent-owned controls FAIL |extension-telegram| extensions/telegram/src/bot.agent-callbacks.test.ts > delivers an unclaimed message-send tap to the agent as callback data AssertionError: expected "vi.fn()" to be called once, but got 0 times FAIL |extension-telegram| extensions/telegram/src/bot.agent-callbacks.test.ts > expires a message-send tap with a malformed envelope AssertionError: expected "vi.fn()" to not be called at all, but actually been called 1 times Test Files 2 failed (2) Tests 3 failed | 1 passed | 41 skipped (45) # this head (tree 4c112e5) ✓ |extension-database-workers| extensions/telegram/src/action-runtime.test.ts > Telegram registered action authority and input contracts > renders typed callbacks in message-action edits as agent-owned controls 3884ms ✓ |extension-telegram| extensions/telegram/src/bot.agent-callbacks.test.ts > delivers an unclaimed message-send tap to the agent as callback data 3127ms ✓ |extension-telegram| extensions/telegram/src/bot.agent-callbacks.test.ts > expires a message-send tap with a malformed envelope 5ms ✓ |extension-telegram| extensions/telegram/src/bot.agent-callbacks.test.ts > expires a message-send tap with inline buttons turned off 4ms Test Files 2 passed (2) Tests 4 passed | 41 skipped (45) ``` </details> <details><summary>Raw recorded output: this head (tree <code>4c112e5f</code>), scenarios (a), (b), (c)</summary> ```text run-notes.ndjson {"at":"2026-11-09T19:11:15.064Z","kind":"ready","variant":"fix","head":"f1f382b9333aa33e19a91bef8c2fda689c0c2c6f"} {"at":"2026-11-09T19:11:15.064Z","kind":"step","step":"a-send"} {"at":"2026-11-09T19:11:46.439Z","kind":"driver","args":["step","--record","--send","proof a: send buttons","--wait","30"],"status":0,"stderr":""} {"at":"2026-11-09T19:11:46.439Z","kind":"step","step":"a-click","mockRequestsBefore":4} {"at":"2026-11-09T19:12:19.045Z","kind":"driver","args":["step","--record","--click","Beta","--wait","30"],"status":0,"stderr":""} {"at":"2026-11-09T19:12:19.045Z","kind":"step-done","step":"a-click","mockRequestsAfter":6} {"at":"2026-11-09T19:12:19.046Z","kind":"step","step":"b-edit","editedMessageId":12} {"at":"2026-11-09T19:12:51.440Z","kind":"driver","args":["step","--record","--send","proof b: edit buttons","--wait","30"],"status":0,"stderr":""} {"at":"2026-11-09T19:12:51.441Z","kind":"step","step":"b-click","mockRequestsBefore":8} {"at":"2026-11-09T19:13:23.161Z","kind":"driver","args":["step","--record","--click","Gamma","--wait","30"],"status":0,"stderr":""} {"at":"2026-11-09T19:13:23.162Z","kind":"step-done","step":"b-click","mockRequestsAfter":10} {"at":"2026-11-09T19:13:23.336Z","kind":"step","step":"c-inject","callbackData":"tgcb1:1p82n:retired-plugin:approve"} {"at":"2026-11-09T19:13:24.586Z","kind":"driver","args":["inject","--text","Plugin control (plugin no longer installed)","--button","Approve","--data","tgcb1:1p82n:retired-plugin:approve"],"status":0,"stderr":""} {"at":"2026-11-09T19:13:24.586Z","kind":"step","step":"c-click","mockRequestsBefore":11} {"at":"2026-11-09T19:13:47.152Z","kind":"driver","args":["step","--record","--click","Approve","--wait","20"],"status":0,"stderr":""} {"at":"2026-11-09T19:13:47.154Z","kind":"step-done","step":"c-click","mockRequestsAfter":11} {"at":"2026-11-09T19:13:47.271Z","kind":"stopped","run":"<work>/run-fix-2026-11-09T19-11-03-988Z"} telegram-events.ndjson (the user's view of the bot chat over MTProto) {"t_ms": 214, "kind": "user-send", "message": {"id": 2532, "out": true, "text": "proof a: send buttons", "edited": null, "buttons": []}} {"t_ms": 3615, "kind": "bot-message", "message": {"id": 2533, "out": false, "text": "Pick one", "edited": null, "buttons": [[{"text": "Alpha", "data": "tgac1:bcaw3:pick:alpha"}, {"text": "Beta", "data": "tgac1:4f7dt:/pick beta|2"}]]}} {"t_ms": 201, "kind": "user-click", "messageId": 2533, "buttonText": "Beta", "callbackData": "tgac1:4f7dt:/pick beta|2"} {"t_ms": 748, "kind": "callback-answer", "message": null, "alert": false} {"t_ms": 1936, "kind": "bot-message-changed", "message": {"id": 2533, "out": false, "text": "Pick one", "edited": "2026-11-09T19:11:48+00:00", "buttons": []}} {"t_ms": 4140, "kind": "bot-message", "message": {"id": 2534, "out": false, "text": "MODEL_SAW_CALLBACK", "edited": null, "buttons": []}} {"t_ms": 283, "kind": "user-send", "message": {"id": 2535, "out": true, "text": "proof b: edit buttons", "edited": null, "buttons": []}} {"t_ms": 2714, "kind": "bot-message-changed", "message": {"id": 2533, "out": false, "text": "Pick again", "edited": "2026-11-09T19:12:21+00:00", "buttons": [[{"text": "Gamma", "data": "tgac1:1f5uj:pick:gamma"}]]}} {"t_ms": 3811, "kind": "bot-message", "message": {"id": 2536, "out": false, "text": "BUTTONS_EDITED", "edited": null, "buttons": []}} {"t_ms": 176, "kind": "user-click", "messageId": 2533, "buttonText": "Gamma", "callbackData": "tgac1:1f5uj:pick:gamma"} {"t_ms": 651, "kind": "callback-answer", "message": null, "alert": false} {"t_ms": 1834, "kind": "bot-message-changed", "message": {"id": 2533, "out": false, "text": "Pick again", "edited": "2026-11-09T19:12:53+00:00", "buttons": []}} {"t_ms": 4019, "kind": "bot-message", "message": {"id": 2537, "out": false, "text": "MODEL_SAW_EDITED_CALLBACK", "edited": null, "buttons": []}} {"t_ms": 194, "kind": "user-click", "messageId": 2538, "buttonText": "Approve", "callbackData": "tgcb1:1p82n:retired-plugin:approve"} {"t_ms": 716, "kind": "callback-answer", "message": null, "alert": false} {"t_ms": 1932, "kind": "bot-message-changed", "message": {"id": 2538, "out": false, "text": "Plugin control (plugin no longer installed)", "edited": "2026-11-09T19:13:26+00:00", "buttons": []}} {"t_ms": 3038, "kind": "bot-message", "message": {"id": 2539, "out": false, "text": "This action is no longer available.", "edited": null, "buttons": []}} mock-requests.ndjson: 11 requests, 6 chat completions {"seq":1,"chatCompletion":1,"newestUserTurn":"proof a: send buttons","endsWithToolResult":null} {"seq":2,"chatCompletion":2,"newestUserTurn":null,"endsWithToolResult":null} {"seq":5,"chatCompletion":3,"newestUserTurn":"callback_data: /pick beta|2","endsWithToolResult":null} {"seq":7,"chatCompletion":4,"newestUserTurn":"proof b: edit buttons","endsWithToolResult":null} {"seq":8,"chatCompletion":5,"newestUserTurn":"proof b: edit buttons","endsWithToolResult":"{ \"ok\": true, \"messageId\": \"12\", \"chatId\": \"<tester-id>\" }"} {"seq":10,"chatCompletion":6,"newestUserTurn":"callback_data: pick:gamma","endsWithToolResult":null} gateway.log (Telegram channel and tool lines: 18) 2026-11-09T22:11:09.623+03:00 telegram [default] starting account (reason: startup) 2026-11-09T22:11:09.968+03:00 telegram [default] starting provider (@<test-bot>) 2026-11-09T22:11:10.372+03:00 telegram [telegram][diag] isolated polling ingress started account=default 2026-11-09T22:11:16.116+03:00 telegram [telegram][diag] isolated polling worker batch received queued=1 2026-11-09T22:11:16.131+03:00 telegram [telegram][diag] isolated polling batch spooled updateId=183551771 2026-11-09T22:11:16.132+03:00 telegram [telegram][diag] isolated polling offset queued updateId=183551771 2026-11-09T22:11:47.666+03:00 telegram [telegram][diag] isolated polling worker batch received queued=1 2026-11-09T22:11:47.676+03:00 telegram [telegram][diag] isolated polling batch spooled updateId=183551772 2026-11-09T22:11:47.677+03:00 telegram [telegram][diag] isolated polling offset queued updateId=183551772 2026-11-09T22:12:20.223+03:00 telegram [telegram][diag] isolated polling worker batch received queued=1 2026-11-09T22:12:20.235+03:00 telegram [telegram][diag] isolated polling batch spooled updateId=183551773 2026-11-09T22:12:20.236+03:00 telegram [telegram][diag] isolated polling offset queued updateId=183551773 2026-11-09T22:12:52.558+03:00 telegram [telegram][diag] isolated polling worker batch received queued=1 2026-11-09T22:12:52.561+03:00 telegram [telegram][diag] isolated polling batch spooled updateId=183551774 2026-11-09T22:12:52.561+03:00 telegram [telegram][diag] isolated polling offset queued updateId=183551774 2026-11-09T22:13:25.687+03:00 telegram [telegram][diag] isolated polling worker batch received queued=1 2026-11-09T22:13:25.694+03:00 telegram [telegram][diag] isolated polling batch spooled updateId=183551775 2026-11-09T22:13:25.694+03:00 telegram [telegram][diag] isolated polling offset queued updateId=183551775 ``` </details> <details><summary>Raw recorded output: this head, scenario (r) with the real model</summary> ```text run-notes.ndjson {"at":"2026-11-09T19:22:58.970Z","kind":"ready","variant":"fix-realmodel","head":"6b83d3190f0d285c2371a7638a1cd1d3b12c87b5"} {"at":"2026-11-09T19:22:58.971Z","kind":"step","step":"r-send","backend":"claude-cli","model":"anthropic/claude-haiku-5-5"} {"at":"2026-11-09T19:24:30.586Z","kind":"driver","args":["step","--record","--wait","90","--send","Use the message tool (action \"send\") to send me one message with the text \"Pick one\" and two inline buttons: \"Alpha\" with action {\"type\":\"callback\",\"value\":\"pick:alpha\"} and \"Beta\" with action {\"type\":\"callback\",\"value\":\"pick:beta\"}. When I later tap a button you will receive its callback data; then reply with exactly: GOT <value>. Do nothing else and send no other text now."],"status":0,"stderr":""} {"at":"2026-11-09T19:24:30.586Z","kind":"step","step":"r-click"} {"at":"2026-11-09T19:26:02.991Z","kind":"driver","args":["step","--record","--click","Beta","--wait","90"],"status":0,"stderr":""} {"at":"2026-11-09T19:26:02.991Z","kind":"step-done","step":"r-click"} {"at":"2026-11-09T19:26:03.794Z","kind":"stopped","run":"<work>/run-fix-realmodel-2026-11-09T19-22-46-887Z"} telegram-events.ndjson (the user's view of the bot chat over MTProto) {"t_ms": 205, "kind": "user-send", "message": {"id": 2540, "out": true, "text": "Use the message tool (action \"send\") to send me one message with the text \"Pick one\" and two inline buttons: \"Alpha\" with action {\"type\":\"callback\",\"value\":\"pick:alpha\"} and \"Beta\" with action {\"type\":\"callback\",\"value\":\"pick:beta\"}. When I later tap a button you will receive its callback data; then reply with exactly: GOT <value>. Do nothing else and send no other text now.", "edited": null, "buttons": []}} {"t_ms": 5819, "kind": "bot-message", "message": {"id": 2541, "out": false, "text": "Working", "edited": null, "buttons": []}} {"t_ms": 6913, "kind": "bot-message-changed", "message": {"id": 2541, "out": false, "text": "Working\n🧩 ToolSearch", "edited": "2026-11-09T19:23:06+00:00", "buttons": []}} {"t_ms": 8043, "kind": "bot-message-changed", "message": {"id": 2541, "out": false, "text": "Working\n✉️ Message running", "edited": "2026-11-09T19:23:07+00:00", "buttons": []}} {"t_ms": 9137, "kind": "bot-message", "message": {"id": 2542, "out": false, "text": "Pick one", "edited": null, "buttons": [[{"text": "Alpha", "data": "tgac1:bcaw3:pick:alpha"}, {"text": "Beta", "data": "tgac1:17dsn:pick:beta"}]]}} {"t_ms": 10341, "kind": "bot-message-changed", "message": {"id": 2541, "out": false, "text": "Working\n✉️ Message", "edited": "2026-11-09T19:23:09+00:00", "buttons": []}} {"t_ms": 244, "kind": "user-click", "messageId": 2542, "buttonText": "Beta", "callbackData": "tgac1:17dsn:pick:beta"} {"t_ms": 739, "kind": "callback-answer", "message": null, "alert": false} {"t_ms": 865, "kind": "bot-message-changed", "message": {"id": 2542, "out": false, "text": "Pick one", "edited": "2026-11-09T19:24:32+00:00", "buttons": []}} {"t_ms": 4198, "kind": "bot-message", "message": {"id": 2543, "out": false, "text": "GOT pick:beta", "edited": null, "buttons": []}} mock-requests.ndjson: 0 requests, 0 chat completions gateway.log (Telegram channel and tool lines: 15) 2026-11-09T22:22:52.880+03:00 telegram [default] starting account (reason: startup) 2026-11-09T22:22:53.226+03:00 telegram [default] starting provider (@<test-bot>) 2026-11-09T22:22:53.634+03:00 telegram [telegram][diag] isolated polling ingress started account=default 2026-11-09T22:23:00.128+03:00 telegram [telegram][diag] isolated polling worker batch received queued=1 2026-11-09T22:23:00.155+03:00 telegram [telegram][diag] isolated polling batch spooled updateId=183551776 2026-11-09T22:23:00.157+03:00 telegram [telegram][diag] isolated polling offset queued updateId=183551776 2026-11-09T22:23:01.803+03:00 {"subsystem":"agent/cli-backend"} cli session history refused across auth boundary: reason=auth-unknown 2026-11-09T22:23:01.860+03:00 {"subsystem":"agent/cli-backend"} cli live session start: provider=claude-cli model=claude-haiku-5-5 activeSessions=1 2026-11-09T22:23:09.997+03:00 {"subsystem":"agent/cli-backend"} cli turn: provider=claude-cli model=claude-haiku-5-5 durationMs=8145 outBytes=106 outHash=9a81ffea36b1 2026-11-09T22:23:12.842+03:00 {"subsystem":"agent/cli-backend"} cli turn: provider=claude-cli model=claude-haiku-5-5 durationMs=2635 outBytes=138 outHash=1aa5649bb718 2026-11-09T22:24:31.797+03:00 telegram [telegram][diag] isolated polling worker batch received queued=1 2026-11-09T22:24:31.813+03:00 telegram [telegram][diag] isolated polling batch spooled updateId=183551777 2026-11-09T22:24:31.815+03:00 telegram [telegram][diag] isolated polling offset queued updateId=183551777 2026-11-09T22:24:34.880+03:00 {"subsystem":"agent/cli-backend"} cli turn: provider=claude-cli model=claude-haiku-5-5 durationMs=2223 outBytes=13 outHash=66bd0a01aad1 2026-11-09T22:24:37.232+03:00 {"subsystem":"agent/cli-backend"} cli turn: provider=claude-cli model=claude-haiku-5-5 durationMs=2294 outBytes=141 outHash=40dbdcf1830f ``` </details> <details><summary>Raw recorded output: this head, scenario (u) with the tapper outside <code>allowFrom</code></summary> ```text run-notes.ndjson {"at":"2026-11-09T19:31:46.140Z","kind":"ready","variant":"fix-unauthorized","head":"27c21a7646a54661cbfb42288bfb081468429a5b"} {"at":"2026-11-09T19:31:46.334Z","kind":"step","step":"u-inject","callbackData":"tgac1:1kkc4:pick:unauthorized","allowFromIncludesTester":false} {"at":"2026-11-09T19:31:47.556Z","kind":"driver","args":["inject","--text","Agent choice (tapper not in allowFrom)","--button","Pick","--data","tgac1:1kkc4:pick:unauthorized"],"status":0,"stderr":""} {"at":"2026-11-09T19:31:47.557Z","kind":"step","step":"u-click","mockRequestsBefore":0} {"at":"2026-11-09T19:32:14.601Z","kind":"driver","args":["step","--record","--click","Pick","--wait","25"],"status":0,"stderr":""} {"at":"2026-11-09T19:32:14.601Z","kind":"step-done","step":"u-click","mockRequestsAfter":0} {"at":"2026-11-09T19:32:14.745Z","kind":"stopped","run":"<work>/run-fix-unauthorized-2026-11-09T19-31-32-601Z"} telegram-events.ndjson (the user's view of the bot chat over MTProto) {"t_ms": 189, "kind": "user-click", "messageId": 2544, "buttonText": "Pick", "callbackData": "tgac1:1kkc4:pick:unauthorized"} {"t_ms": 446, "kind": "callback-answer", "message": null, "alert": false} mock-requests.ndjson: 0 requests, 0 chat completions gateway.log (Telegram channel and tool lines: 6) 2026-11-09T22:31:40.409+03:00 telegram [default] starting account (reason: startup) 2026-11-09T22:31:40.766+03:00 telegram [default] starting provider (@<test-bot>) 2026-11-09T22:31:41.184+03:00 telegram [telegram][diag] isolated polling ingress started account=default 2026-11-09T22:31:48.645+03:00 telegram [telegram][diag] isolated polling worker batch received queued=1 2026-11-09T22:31:48.672+03:00 telegram [telegram][diag] isolated polling batch spooled updateId=183551778 2026-11-09T22:31:48.674+03:00 telegram [telegram][diag] isolated polling offset queued updateId=183551778 ``` </details> <details><summary>Raw recorded output: <code>upstream/main</code> <code>4b077d31b91</code>, scenario (a)</summary> ```text run-notes.ndjson {"at":"2026-11-09T19:09:33.606Z","kind":"ready","variant":"base","head":"4b077d31b914aa62c6c10650abc62263ef3db839"} {"at":"2026-11-09T19:09:33.607Z","kind":"step","step":"a-send"} {"at":"2026-11-09T19:10:06.215Z","kind":"driver","args":["step","--record","--send","proof a: send buttons","--wait","30"],"status":0,"stderr":""} {"at":"2026-11-09T19:10:06.216Z","kind":"step","step":"a-click","mockRequestsBefore":4} {"at":"2026-11-09T19:10:38.079Z","kind":"driver","args":["step","--record","--click","Beta","--wait","30"],"status":0,"stderr":""} {"at":"2026-11-09T19:10:38.079Z","kind":"step-done","step":"a-click","mockRequestsAfter":4} {"at":"2026-11-09T19:10:38.221Z","kind":"stopped","run":"<work>/run-base-2026-11-09T19-09-22-036Z"} telegram-events.ndjson (the user's view of the bot chat over MTProto) {"t_ms": 347, "kind": "user-send", "message": {"id": 2529, "out": true, "text": "proof a: send buttons", "edited": null, "buttons": []}} {"t_ms": 3732, "kind": "bot-message", "message": {"id": 2530, "out": false, "text": "Pick one", "edited": null, "buttons": [[{"text": "Alpha", "data": "tgcb1:bcaw3:pick:alpha"}, {"text": "Beta", "data": "tgcb1:4f7dt:/pick beta|2"}]]}} {"t_ms": 198, "kind": "user-click", "messageId": 2530, "buttonText": "Beta", "callbackData": "tgcb1:4f7dt:/pick beta|2"} {"t_ms": 673, "kind": "callback-answer", "message": null, "alert": false} {"t_ms": 809, "kind": "bot-message-changed", "message": {"id": 2530, "out": false, "text": "Pick one", "edited": "2026-11-09T19:10:07+00:00", "buttons": []}} {"t_ms": 3009, "kind": "bot-message", "message": {"id": 2531, "out": false, "text": "This action is no longer available.", "edited": null, "buttons": []}} mock-requests.ndjson: 4 requests, 2 chat completions {"seq":1,"chatCompletion":1,"newestUserTurn":"proof a: send buttons","endsWithToolResult":null} {"seq":2,"chatCompletion":2,"newestUserTurn":null,"endsWithToolResult":null} gateway.log (Telegram channel and tool lines: 9) 2026-11-09T22:09:27.507+03:00 telegram [default] starting account (reason: startup) 2026-11-09T22:09:27.876+03:00 telegram [default] starting provider (@<test-bot>) 2026-11-09T22:09:28.290+03:00 telegram [telegram][diag] isolated polling ingress started account=default 2026-11-09T22:09:34.846+03:00 telegram [telegram][diag] isolated polling worker batch received queued=1 2026-11-09T22:09:34.871+03:00 telegram [telegram][diag] isolated polling batch spooled updateId=183551769 2026-11-09T22:09:34.873+03:00 telegram [telegram][diag] isolated polling offset queued updateId=183551769 2026-11-09T22:10:07.375+03:00 telegram [telegram][diag] isolated polling worker batch received queued=1 2026-11-09T22:10:07.403+03:00 telegram [telegram][diag] isolated polling batch spooled updateId=183551770 2026-11-09T22:10:07.404+03:00 telegram [telegram][diag] isolated polling offset queued updateId=183551770 ``` </details> * test(telegram): allocate test lines for agent callback regressions --------- Co-authored-by: Dmitriy <[email protected]> Co-authored-by: obviyus <[email protected]>
…e agent (openclaw#196217) * fix(telegram): agent inline button taps expire instead of reaching the agent Closes openclaw#126950 ## What Problem This Solves Fixes: tapping an inline button an agent sent with the `message` tool (`presentation` button with `action: { type: "callback", value }`) removes the keyboard and replies "This action is no longer available." instead of delivering the choice to the agent. The agent's own system prompt recommends exactly this button shape, so every agent-authored Telegram choice is dead on arrival, on Telegram-started and CLI-started turns alike. ## User Impact User impact: a tap on an agent's typed callback button now reaches the agent as `callback_data: <value>`, as `docs/channels/telegram/rich-messages.md` already promised, for `message` sends and edits. The send itself carries the ownership rather than the caller's origin, so turns started outside Telegram (CLI, cron) take the same code path; the live proof below drives Telegram-started turns. A plugin interactive handler that registers the value's namespace still claims the tap first. Typed controls sent by any other producer keep today's behavior: no handler, no fallback, "This action is no longer available." Legacy `{ label, value }` buttons are unchanged. Buttons already delivered before the upgrade carry the old envelope and still expire when tapped; the agent can resend them. ## Why This Change Was Made Every typed callback was encoded as `tgcb1:`, the envelope whose unclaimed taps terminalize by design (openclaw#116383, so retired plugin buttons do not become raw agent input). Telegram had no way to tell an agent's button from a plugin's. Telegram now records that ownership itself, at the two places only `message` actions reach, so no core or Plugin SDK contract changes: - `prepareSendPayload` (the SDK hook core calls only for `message(action=send)` before persisting the payload) marks presentations that carry controls with Telegram-private `channelData.telegram.typedCallbackOwner: "agent"`. The mark travels in the persisted payload, so queued and recovered deliveries keep it. - `resolveTelegramButtonsFromParams`, used only by the Telegram action runtime that `message` actions reach (for example `edit`), renders its controls as agent-owned. - `canonicalizeTelegramPresentationPayload`, the single presentation-to-keyboard step every send funnel uses, encodes agent-owned typed callbacks as `tgac1:<checksum>:<value>` (same checksum and byte budget as `tgcb1:`). - The callback router offers a valid `tgac1:` value to plugin handlers exactly like today, then delivers it as `callback_data: <value>` (never as a slash command or approval). A malformed `tgac1:` payload, or any tap while inline buttons are off for the chat, terminalizes like `tgcb1:`. `tgcb1:` semantics, plugin dispatch, and the approval, question, native-command, and model-picker namespaces are untouched. ## Evidence - New `extensions/telegram/src/bot.agent-callbacks.test.ts` drives the real producer (`prepareSendPayload` → `canonicalizeTelegramPresentationPayload`) and the real callback router: the tap reaches the agent as `callback_data: /usdt remind|today 20:00` (slash and delimiter stay data) and the keyboard is cleared. Red on `upstream/main` (unavailable reply, no agent turn), green with the fix. The same file pins that malformed `tgac1:` payloads and taps with inline buttons off still terminalize without plugin dispatch or raw-text fallthrough. - `action-runtime.test.ts`: a `message(action=edit)` with a typed callback reaches Bot API `editMessageText` with an agent envelope (red without the change, green with it). - Consumer suites: `action-runtime`, `bot.create-telegram-bot`, `bot`, `bot.callback-retry`, `bot-handlers.callback-questions.runtime`, `button-types`, `channel-actions.contract`, `interactive-fallback`, `native-command-callback-data`, `outbound-adapter.normalize-payload`, `outbound-adapter.telegram-http`: all green. - `pnpm check:changed --base upstream/main`: format, lint, extension and extension-test typecheck, import cycles, line-cap and boundary guards pass. Two checks fail only on files this PR does not touch: changelog attributions (`CHANGELOG/*`) and the dead-export scan (`src/daemon/launchd.ts`, `ui/src/pages/dashboards/dashboard-tools.tsx`). - Live Telegram round trip: see below. Change size against the merge base: production +69/-11 in 6 files, tests +122 in 2 files, docs 1 line. No core, Plugin SDK, protocol, config, or schema change. ### Live Telegram round trip: real user, real bot, isolated exact-head Gateway Why not the Test Server: the repository's Telegram Test Server credentials are maintainer-leased through Convex, and Telegram stopped provisioning new Test Server accounts for random `99966X` numbers in 2026 (`signIn` returns `PHONE_CODE_INVALID` on DC 1–3; noted in gotd/td `telegram/auth` and in mctlhq/mctl-telegram#854). So this proof runs the same flow on production Telegram: - a Telegram bot created only for this proof, talking to one real Telegram user account in a private chat; - an isolated Gateway (own state dir, port and config; `dmPolicy: "allowlist"` with that one user) started from `node dist/entry.js gateway` built from this head `f1f382b9333`, and, for the contrast run, from `upstream/main` `35c0b79a9e9`; - for scenarios (a)–(c) and the contrast, the repository mock model `scripts/e2e/mock-openai-server.mjs` (chat completions), scripted to make the agent call the `message` tool with typed callback buttons; for scenario (r), a real model (`claude-haiku-5-5` through the `claude-cli` runtime) that is only asked in chat to send two buttons and to answer a tap; - the user side driven over MTProto (Telethon): send a message, read the bot's inline keyboard, tap a button (`messages.getBotCallbackAnswer`), and record every message, edit and keyboard change in the chat for 20–30 s after each action. Scenarios: (a) `message(action=send)` with typed callbacks, then a tap; (b) `message(action=edit)` that puts a new typed callback on that message, then a tap; (c) a control with the plugin envelope whose plugin is not installed (posted by the bot through Bot API `sendMessage` with `callback_data` from `buildTelegramOpaqueCallbackData("retired-plugin:approve")`, which is how a plugin-sent typed control renders), then a tap; (r) the same send and tap with the real model; (u) the nearest forbidden principal: the same agent envelope, posted by the bot, tapped by a user the Gateway's `allowFrom` does not include (the Gateway runs with `allowFrom: ["1"]`); contrast: scenario (a) on `upstream/main`. Identifiers are redacted: `<tester-id>`, `<bot-id>`, `<test-bot>`. No Telegram client screenshots: the test user account has two-step verification, so a fresh Telegram Web session cannot be opened without its password. The chat state below (messages, edits, keyboards with their `callback_data`) is read from that user's existing MTProto session after every action, so it is what any Telegram client shows. Result, read from the raw output below (`mockRequestsBefore`/`mockRequestsAfter` count every request the mock model received; scenario (r) has no mock): | Scenario | `upstream/main` `35c0b79a9e9` | This head (tree `4c112e5f`) | |---|---|---| | (a) `message` send renders the buttons as | `tgcb1:4f7dt:/pick beta\|2` (plugin envelope) | `tgac1:4f7dt:/pick beta\|2` (agent envelope) | | (a) tap "Beta" | keyboard removed, bot replies "This action is no longer available.", model requests 4 → 4 (no agent turn) | keyboard removed, a new agent turn whose user message is `callback_data: /pick beta\|2` (slash and `\|` stay data), agent replies `MODEL_SAW_CALLBACK` | | (b) `message` edit puts "Gamma" on the agent's message | not run | the agent's own message (bot-side id 12) becomes "Pick again" with `tgac1:1f5uj:pick:gamma` | | (b) tap "Gamma" | not run | keyboard removed, a new agent turn whose user message is `callback_data: pick:gamma`, agent replies `MODEL_SAW_EDITED_CALLBACK` | | (c) tap a `tgcb1:` control whose plugin is not installed | not run (same `tgcb1:` path) | keyboard removed, "This action is no longer available.", model requests unchanged (no agent turn) | | (r) real model (`claude-haiku-5-5`, `claude-cli`) asked in chat to send "Alpha"/"Beta" | not run | the model calls `message` itself; the buttons arrive as `tgac1:bcaw3:pick:alpha` and `tgac1:17dsn:pick:beta` | | (r) tap "Beta" | not run | keyboard removed, a new model turn, the model replies `GOT pick:beta` | | (u) tap an agent envelope (`tgac1:1kkc4:pick:unauthorized`) as a user outside `allowFrom` | not run | rejected before any effect: no agent turn (model requests 0 → 0), the message and its keyboard stay unchanged, no reply | Gateway trees: this head `4c112e5fd1b0327d95f54d6d52eb862ac6533175`, base `cb575aeaedcd153f4bfdd41b559834604ad3c106` (`git rev-parse HEAD^{tree}`). Regression tests from this PR, run against each tree (`pnpm vitest run extensions/telegram/src/bot.agent-callbacks.test.ts extensions/telegram/src/action-runtime.test.ts -t "message-send|agent-owned"`; on the base the two test files were copied in, then removed). The "inline buttons turned off" case is a guard that passes on both by design. <details><summary>Test output: <code>upstream/main</code> (red) and this head (green)</summary> ```text # upstream/main 35c0b79 × |extension-database-workers| extensions/telegram/src/action-runtime.test.ts > Telegram registered action authority and input contracts > renders typed callbacks in message-action edits as agent-owned controls 6653ms × |extension-telegram| extensions/telegram/src/bot.agent-callbacks.test.ts > delivers an unclaimed message-send tap to the agent as callback data 34ms × |extension-telegram| extensions/telegram/src/bot.agent-callbacks.test.ts > expires a message-send tap with a malformed envelope 3266ms ✓ |extension-telegram| extensions/telegram/src/bot.agent-callbacks.test.ts > expires a message-send tap with inline buttons turned off 5ms ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 3 ⎯⎯⎯⎯⎯⎯⎯ FAIL |extension-database-workers| extensions/telegram/src/action-runtime.test.ts > Telegram registered action authority and input contracts > renders typed callbacks in message-action edits as agent-owned controls FAIL |extension-telegram| extensions/telegram/src/bot.agent-callbacks.test.ts > delivers an unclaimed message-send tap to the agent as callback data AssertionError: expected "vi.fn()" to be called once, but got 0 times FAIL |extension-telegram| extensions/telegram/src/bot.agent-callbacks.test.ts > expires a message-send tap with a malformed envelope AssertionError: expected "vi.fn()" to not be called at all, but actually been called 1 times Test Files 2 failed (2) Tests 3 failed | 1 passed | 41 skipped (45) # this head (tree 4c112e5) ✓ |extension-database-workers| extensions/telegram/src/action-runtime.test.ts > Telegram registered action authority and input contracts > renders typed callbacks in message-action edits as agent-owned controls 3884ms ✓ |extension-telegram| extensions/telegram/src/bot.agent-callbacks.test.ts > delivers an unclaimed message-send tap to the agent as callback data 3127ms ✓ |extension-telegram| extensions/telegram/src/bot.agent-callbacks.test.ts > expires a message-send tap with a malformed envelope 5ms ✓ |extension-telegram| extensions/telegram/src/bot.agent-callbacks.test.ts > expires a message-send tap with inline buttons turned off 4ms Test Files 2 passed (2) Tests 4 passed | 41 skipped (45) ``` </details> <details><summary>Raw recorded output: this head (tree <code>4c112e5f</code>), scenarios (a), (b), (c)</summary> ```text run-notes.ndjson {"at":"2026-11-09T19:11:15.064Z","kind":"ready","variant":"fix","head":"f1f382b9333aa33e19a91bef8c2fda689c0c2c6f"} {"at":"2026-11-09T19:11:15.064Z","kind":"step","step":"a-send"} {"at":"2026-11-09T19:11:46.439Z","kind":"driver","args":["step","--record","--send","proof a: send buttons","--wait","30"],"status":0,"stderr":""} {"at":"2026-11-09T19:11:46.439Z","kind":"step","step":"a-click","mockRequestsBefore":4} {"at":"2026-11-09T19:12:19.045Z","kind":"driver","args":["step","--record","--click","Beta","--wait","30"],"status":0,"stderr":""} {"at":"2026-11-09T19:12:19.045Z","kind":"step-done","step":"a-click","mockRequestsAfter":6} {"at":"2026-11-09T19:12:19.046Z","kind":"step","step":"b-edit","editedMessageId":12} {"at":"2026-11-09T19:12:51.440Z","kind":"driver","args":["step","--record","--send","proof b: edit buttons","--wait","30"],"status":0,"stderr":""} {"at":"2026-11-09T19:12:51.441Z","kind":"step","step":"b-click","mockRequestsBefore":8} {"at":"2026-11-09T19:13:23.161Z","kind":"driver","args":["step","--record","--click","Gamma","--wait","30"],"status":0,"stderr":""} {"at":"2026-11-09T19:13:23.162Z","kind":"step-done","step":"b-click","mockRequestsAfter":10} {"at":"2026-11-09T19:13:23.336Z","kind":"step","step":"c-inject","callbackData":"tgcb1:1p82n:retired-plugin:approve"} {"at":"2026-11-09T19:13:24.586Z","kind":"driver","args":["inject","--text","Plugin control (plugin no longer installed)","--button","Approve","--data","tgcb1:1p82n:retired-plugin:approve"],"status":0,"stderr":""} {"at":"2026-11-09T19:13:24.586Z","kind":"step","step":"c-click","mockRequestsBefore":11} {"at":"2026-11-09T19:13:47.152Z","kind":"driver","args":["step","--record","--click","Approve","--wait","20"],"status":0,"stderr":""} {"at":"2026-11-09T19:13:47.154Z","kind":"step-done","step":"c-click","mockRequestsAfter":11} {"at":"2026-11-09T19:13:47.271Z","kind":"stopped","run":"<work>/run-fix-2026-11-09T19-11-03-988Z"} telegram-events.ndjson (the user's view of the bot chat over MTProto) {"t_ms": 214, "kind": "user-send", "message": {"id": 2532, "out": true, "text": "proof a: send buttons", "edited": null, "buttons": []}} {"t_ms": 3615, "kind": "bot-message", "message": {"id": 2533, "out": false, "text": "Pick one", "edited": null, "buttons": [[{"text": "Alpha", "data": "tgac1:bcaw3:pick:alpha"}, {"text": "Beta", "data": "tgac1:4f7dt:/pick beta|2"}]]}} {"t_ms": 201, "kind": "user-click", "messageId": 2533, "buttonText": "Beta", "callbackData": "tgac1:4f7dt:/pick beta|2"} {"t_ms": 748, "kind": "callback-answer", "message": null, "alert": false} {"t_ms": 1936, "kind": "bot-message-changed", "message": {"id": 2533, "out": false, "text": "Pick one", "edited": "2026-11-09T19:11:48+00:00", "buttons": []}} {"t_ms": 4140, "kind": "bot-message", "message": {"id": 2534, "out": false, "text": "MODEL_SAW_CALLBACK", "edited": null, "buttons": []}} {"t_ms": 283, "kind": "user-send", "message": {"id": 2535, "out": true, "text": "proof b: edit buttons", "edited": null, "buttons": []}} {"t_ms": 2714, "kind": "bot-message-changed", "message": {"id": 2533, "out": false, "text": "Pick again", "edited": "2026-11-09T19:12:21+00:00", "buttons": [[{"text": "Gamma", "data": "tgac1:1f5uj:pick:gamma"}]]}} {"t_ms": 3811, "kind": "bot-message", "message": {"id": 2536, "out": false, "text": "BUTTONS_EDITED", "edited": null, "buttons": []}} {"t_ms": 176, "kind": "user-click", "messageId": 2533, "buttonText": "Gamma", "callbackData": "tgac1:1f5uj:pick:gamma"} {"t_ms": 651, "kind": "callback-answer", "message": null, "alert": false} {"t_ms": 1834, "kind": "bot-message-changed", "message": {"id": 2533, "out": false, "text": "Pick again", "edited": "2026-11-09T19:12:53+00:00", "buttons": []}} {"t_ms": 4019, "kind": "bot-message", "message": {"id": 2537, "out": false, "text": "MODEL_SAW_EDITED_CALLBACK", "edited": null, "buttons": []}} {"t_ms": 194, "kind": "user-click", "messageId": 2538, "buttonText": "Approve", "callbackData": "tgcb1:1p82n:retired-plugin:approve"} {"t_ms": 716, "kind": "callback-answer", "message": null, "alert": false} {"t_ms": 1932, "kind": "bot-message-changed", "message": {"id": 2538, "out": false, "text": "Plugin control (plugin no longer installed)", "edited": "2026-11-09T19:13:26+00:00", "buttons": []}} {"t_ms": 3038, "kind": "bot-message", "message": {"id": 2539, "out": false, "text": "This action is no longer available.", "edited": null, "buttons": []}} mock-requests.ndjson: 11 requests, 6 chat completions {"seq":1,"chatCompletion":1,"newestUserTurn":"proof a: send buttons","endsWithToolResult":null} {"seq":2,"chatCompletion":2,"newestUserTurn":null,"endsWithToolResult":null} {"seq":5,"chatCompletion":3,"newestUserTurn":"callback_data: /pick beta|2","endsWithToolResult":null} {"seq":7,"chatCompletion":4,"newestUserTurn":"proof b: edit buttons","endsWithToolResult":null} {"seq":8,"chatCompletion":5,"newestUserTurn":"proof b: edit buttons","endsWithToolResult":"{ \"ok\": true, \"messageId\": \"12\", \"chatId\": \"<tester-id>\" }"} {"seq":10,"chatCompletion":6,"newestUserTurn":"callback_data: pick:gamma","endsWithToolResult":null} gateway.log (Telegram channel and tool lines: 18) 2026-11-09T22:11:09.623+03:00 telegram [default] starting account (reason: startup) 2026-11-09T22:11:09.968+03:00 telegram [default] starting provider (@<test-bot>) 2026-11-09T22:11:10.372+03:00 telegram [telegram][diag] isolated polling ingress started account=default 2026-11-09T22:11:16.116+03:00 telegram [telegram][diag] isolated polling worker batch received queued=1 2026-11-09T22:11:16.131+03:00 telegram [telegram][diag] isolated polling batch spooled updateId=183551771 2026-11-09T22:11:16.132+03:00 telegram [telegram][diag] isolated polling offset queued updateId=183551771 2026-11-09T22:11:47.666+03:00 telegram [telegram][diag] isolated polling worker batch received queued=1 2026-11-09T22:11:47.676+03:00 telegram [telegram][diag] isolated polling batch spooled updateId=183551772 2026-11-09T22:11:47.677+03:00 telegram [telegram][diag] isolated polling offset queued updateId=183551772 2026-11-09T22:12:20.223+03:00 telegram [telegram][diag] isolated polling worker batch received queued=1 2026-11-09T22:12:20.235+03:00 telegram [telegram][diag] isolated polling batch spooled updateId=183551773 2026-11-09T22:12:20.236+03:00 telegram [telegram][diag] isolated polling offset queued updateId=183551773 2026-11-09T22:12:52.558+03:00 telegram [telegram][diag] isolated polling worker batch received queued=1 2026-11-09T22:12:52.561+03:00 telegram [telegram][diag] isolated polling batch spooled updateId=183551774 2026-11-09T22:12:52.561+03:00 telegram [telegram][diag] isolated polling offset queued updateId=183551774 2026-11-09T22:13:25.687+03:00 telegram [telegram][diag] isolated polling worker batch received queued=1 2026-11-09T22:13:25.694+03:00 telegram [telegram][diag] isolated polling batch spooled updateId=183551775 2026-11-09T22:13:25.694+03:00 telegram [telegram][diag] isolated polling offset queued updateId=183551775 ``` </details> <details><summary>Raw recorded output: this head, scenario (r) with the real model</summary> ```text run-notes.ndjson {"at":"2026-11-09T19:22:58.970Z","kind":"ready","variant":"fix-realmodel","head":"6b83d3190f0d285c2371a7638a1cd1d3b12c87b5"} {"at":"2026-11-09T19:22:58.971Z","kind":"step","step":"r-send","backend":"claude-cli","model":"anthropic/claude-haiku-5-5"} {"at":"2026-11-09T19:24:30.586Z","kind":"driver","args":["step","--record","--wait","90","--send","Use the message tool (action \"send\") to send me one message with the text \"Pick one\" and two inline buttons: \"Alpha\" with action {\"type\":\"callback\",\"value\":\"pick:alpha\"} and \"Beta\" with action {\"type\":\"callback\",\"value\":\"pick:beta\"}. When I later tap a button you will receive its callback data; then reply with exactly: GOT <value>. Do nothing else and send no other text now."],"status":0,"stderr":""} {"at":"2026-11-09T19:24:30.586Z","kind":"step","step":"r-click"} {"at":"2026-11-09T19:26:02.991Z","kind":"driver","args":["step","--record","--click","Beta","--wait","90"],"status":0,"stderr":""} {"at":"2026-11-09T19:26:02.991Z","kind":"step-done","step":"r-click"} {"at":"2026-11-09T19:26:03.794Z","kind":"stopped","run":"<work>/run-fix-realmodel-2026-11-09T19-22-46-887Z"} telegram-events.ndjson (the user's view of the bot chat over MTProto) {"t_ms": 205, "kind": "user-send", "message": {"id": 2540, "out": true, "text": "Use the message tool (action \"send\") to send me one message with the text \"Pick one\" and two inline buttons: \"Alpha\" with action {\"type\":\"callback\",\"value\":\"pick:alpha\"} and \"Beta\" with action {\"type\":\"callback\",\"value\":\"pick:beta\"}. When I later tap a button you will receive its callback data; then reply with exactly: GOT <value>. Do nothing else and send no other text now.", "edited": null, "buttons": []}} {"t_ms": 5819, "kind": "bot-message", "message": {"id": 2541, "out": false, "text": "Working", "edited": null, "buttons": []}} {"t_ms": 6913, "kind": "bot-message-changed", "message": {"id": 2541, "out": false, "text": "Working\n🧩 ToolSearch", "edited": "2026-11-09T19:23:06+00:00", "buttons": []}} {"t_ms": 8043, "kind": "bot-message-changed", "message": {"id": 2541, "out": false, "text": "Working\n✉️ Message running", "edited": "2026-11-09T19:23:07+00:00", "buttons": []}} {"t_ms": 9137, "kind": "bot-message", "message": {"id": 2542, "out": false, "text": "Pick one", "edited": null, "buttons": [[{"text": "Alpha", "data": "tgac1:bcaw3:pick:alpha"}, {"text": "Beta", "data": "tgac1:17dsn:pick:beta"}]]}} {"t_ms": 10341, "kind": "bot-message-changed", "message": {"id": 2541, "out": false, "text": "Working\n✉️ Message", "edited": "2026-11-09T19:23:09+00:00", "buttons": []}} {"t_ms": 244, "kind": "user-click", "messageId": 2542, "buttonText": "Beta", "callbackData": "tgac1:17dsn:pick:beta"} {"t_ms": 739, "kind": "callback-answer", "message": null, "alert": false} {"t_ms": 865, "kind": "bot-message-changed", "message": {"id": 2542, "out": false, "text": "Pick one", "edited": "2026-11-09T19:24:32+00:00", "buttons": []}} {"t_ms": 4198, "kind": "bot-message", "message": {"id": 2543, "out": false, "text": "GOT pick:beta", "edited": null, "buttons": []}} mock-requests.ndjson: 0 requests, 0 chat completions gateway.log (Telegram channel and tool lines: 15) 2026-11-09T22:22:52.880+03:00 telegram [default] starting account (reason: startup) 2026-11-09T22:22:53.226+03:00 telegram [default] starting provider (@<test-bot>) 2026-11-09T22:22:53.634+03:00 telegram [telegram][diag] isolated polling ingress started account=default 2026-11-09T22:23:00.128+03:00 telegram [telegram][diag] isolated polling worker batch received queued=1 2026-11-09T22:23:00.155+03:00 telegram [telegram][diag] isolated polling batch spooled updateId=183551776 2026-11-09T22:23:00.157+03:00 telegram [telegram][diag] isolated polling offset queued updateId=183551776 2026-11-09T22:23:01.803+03:00 {"subsystem":"agent/cli-backend"} cli session history refused across auth boundary: reason=auth-unknown 2026-11-09T22:23:01.860+03:00 {"subsystem":"agent/cli-backend"} cli live session start: provider=claude-cli model=claude-haiku-5-5 activeSessions=1 2026-11-09T22:23:09.997+03:00 {"subsystem":"agent/cli-backend"} cli turn: provider=claude-cli model=claude-haiku-5-5 durationMs=8145 outBytes=106 outHash=9a81ffea36b1 2026-11-09T22:23:12.842+03:00 {"subsystem":"agent/cli-backend"} cli turn: provider=claude-cli model=claude-haiku-5-5 durationMs=2635 outBytes=138 outHash=1aa5649bb718 2026-11-09T22:24:31.797+03:00 telegram [telegram][diag] isolated polling worker batch received queued=1 2026-11-09T22:24:31.813+03:00 telegram [telegram][diag] isolated polling batch spooled updateId=183551777 2026-11-09T22:24:31.815+03:00 telegram [telegram][diag] isolated polling offset queued updateId=183551777 2026-11-09T22:24:34.880+03:00 {"subsystem":"agent/cli-backend"} cli turn: provider=claude-cli model=claude-haiku-5-5 durationMs=2223 outBytes=13 outHash=66bd0a01aad1 2026-11-09T22:24:37.232+03:00 {"subsystem":"agent/cli-backend"} cli turn: provider=claude-cli model=claude-haiku-5-5 durationMs=2294 outBytes=141 outHash=40dbdcf1830f ``` </details> <details><summary>Raw recorded output: this head, scenario (u) with the tapper outside <code>allowFrom</code></summary> ```text run-notes.ndjson {"at":"2026-11-09T19:31:46.140Z","kind":"ready","variant":"fix-unauthorized","head":"27c21a7646a54661cbfb42288bfb081468429a5b"} {"at":"2026-11-09T19:31:46.334Z","kind":"step","step":"u-inject","callbackData":"tgac1:1kkc4:pick:unauthorized","allowFromIncludesTester":false} {"at":"2026-11-09T19:31:47.556Z","kind":"driver","args":["inject","--text","Agent choice (tapper not in allowFrom)","--button","Pick","--data","tgac1:1kkc4:pick:unauthorized"],"status":0,"stderr":""} {"at":"2026-11-09T19:31:47.557Z","kind":"step","step":"u-click","mockRequestsBefore":0} {"at":"2026-11-09T19:32:14.601Z","kind":"driver","args":["step","--record","--click","Pick","--wait","25"],"status":0,"stderr":""} {"at":"2026-11-09T19:32:14.601Z","kind":"step-done","step":"u-click","mockRequestsAfter":0} {"at":"2026-11-09T19:32:14.745Z","kind":"stopped","run":"<work>/run-fix-unauthorized-2026-11-09T19-31-32-601Z"} telegram-events.ndjson (the user's view of the bot chat over MTProto) {"t_ms": 189, "kind": "user-click", "messageId": 2544, "buttonText": "Pick", "callbackData": "tgac1:1kkc4:pick:unauthorized"} {"t_ms": 446, "kind": "callback-answer", "message": null, "alert": false} mock-requests.ndjson: 0 requests, 0 chat completions gateway.log (Telegram channel and tool lines: 6) 2026-11-09T22:31:40.409+03:00 telegram [default] starting account (reason: startup) 2026-11-09T22:31:40.766+03:00 telegram [default] starting provider (@<test-bot>) 2026-11-09T22:31:41.184+03:00 telegram [telegram][diag] isolated polling ingress started account=default 2026-11-09T22:31:48.645+03:00 telegram [telegram][diag] isolated polling worker batch received queued=1 2026-11-09T22:31:48.672+03:00 telegram [telegram][diag] isolated polling batch spooled updateId=183551778 2026-11-09T22:31:48.674+03:00 telegram [telegram][diag] isolated polling offset queued updateId=183551778 ``` </details> <details><summary>Raw recorded output: <code>upstream/main</code> <code>35c0b79a9e9</code>, scenario (a)</summary> ```text run-notes.ndjson {"at":"2026-11-09T19:09:33.606Z","kind":"ready","variant":"base","head":"35c0b79a9e95f37d136324db76ffbe96ae346de9"} {"at":"2026-11-09T19:09:33.607Z","kind":"step","step":"a-send"} {"at":"2026-11-09T19:10:06.215Z","kind":"driver","args":["step","--record","--send","proof a: send buttons","--wait","30"],"status":0,"stderr":""} {"at":"2026-11-09T19:10:06.216Z","kind":"step","step":"a-click","mockRequestsBefore":4} {"at":"2026-11-09T19:10:38.079Z","kind":"driver","args":["step","--record","--click","Beta","--wait","30"],"status":0,"stderr":""} {"at":"2026-11-09T19:10:38.079Z","kind":"step-done","step":"a-click","mockRequestsAfter":4} {"at":"2026-11-09T19:10:38.221Z","kind":"stopped","run":"<work>/run-base-2026-11-09T19-09-22-036Z"} telegram-events.ndjson (the user's view of the bot chat over MTProto) {"t_ms": 347, "kind": "user-send", "message": {"id": 2529, "out": true, "text": "proof a: send buttons", "edited": null, "buttons": []}} {"t_ms": 3732, "kind": "bot-message", "message": {"id": 2530, "out": false, "text": "Pick one", "edited": null, "buttons": [[{"text": "Alpha", "data": "tgcb1:bcaw3:pick:alpha"}, {"text": "Beta", "data": "tgcb1:4f7dt:/pick beta|2"}]]}} {"t_ms": 198, "kind": "user-click", "messageId": 2530, "buttonText": "Beta", "callbackData": "tgcb1:4f7dt:/pick beta|2"} {"t_ms": 673, "kind": "callback-answer", "message": null, "alert": false} {"t_ms": 809, "kind": "bot-message-changed", "message": {"id": 2530, "out": false, "text": "Pick one", "edited": "2026-11-09T19:10:07+00:00", "buttons": []}} {"t_ms": 3009, "kind": "bot-message", "message": {"id": 2531, "out": false, "text": "This action is no longer available.", "edited": null, "buttons": []}} mock-requests.ndjson: 4 requests, 2 chat completions {"seq":1,"chatCompletion":1,"newestUserTurn":"proof a: send buttons","endsWithToolResult":null} {"seq":2,"chatCompletion":2,"newestUserTurn":null,"endsWithToolResult":null} gateway.log (Telegram channel and tool lines: 9) 2026-11-09T22:09:27.507+03:00 telegram [default] starting account (reason: startup) 2026-11-09T22:09:27.876+03:00 telegram [default] starting provider (@<test-bot>) 2026-11-09T22:09:28.290+03:00 telegram [telegram][diag] isolated polling ingress started account=default 2026-11-09T22:09:34.846+03:00 telegram [telegram][diag] isolated polling worker batch received queued=1 2026-11-09T22:09:34.871+03:00 telegram [telegram][diag] isolated polling batch spooled updateId=183551769 2026-11-09T22:09:34.873+03:00 telegram [telegram][diag] isolated polling offset queued updateId=183551769 2026-11-09T22:10:07.375+03:00 telegram [telegram][diag] isolated polling worker batch received queued=1 2026-11-09T22:10:07.403+03:00 telegram [telegram][diag] isolated polling batch spooled updateId=183551770 2026-11-09T22:10:07.404+03:00 telegram [telegram][diag] isolated polling offset queued updateId=183551770 ``` </details> * test(telegram): allocate test lines for agent callback regressions --------- Co-authored-by: Dmitriy <[email protected]> Co-authored-by: obviyus <[email protected]>
…201764) ## Problem A button the agent sends with the `message` tool (`presentation` button with `action: { type: "callback", value }`, or a legacy `value`) has no recorded owner. When no plugin claims the tap, each channel guesses: - **Slack**: the agent gets a `Slack interaction: {json…}` system event instead of the value. - **Discord** (registry path): the agent gets only `Clicked "<label>"`; the callback value is lost. - **Teams**: the agent gets the raw card JSON `{"value":…,"label":…}`. - **Telegram**: v2026.11.5 and main already deliver `message`-tool buttons through a Telegram-private patch (`tgac1`, backported to stable as `9afcc1b7b29a`), so the plain send/edit path works on stable (E2E below). That patch is set only by Telegram's `prepareSendPayload` hook and its edit path. Paths that skip it still render the plugin envelope `tgcb1:` and expire with "This action is no longer available.": the queue-persistence/`forceCoreDelivery` path, tool-authored source replies and legacy `interactive`. Builds before v2026.11.5 expire every typed agent button. Legacy slash values run as commands. The main user-visible fixes are the other channels; on Telegram this PR replaces the private patch with the core owner and covers the paths it missed. - **Feishu / Mattermost / LINE**: legacy values pass through without an owner. ## Root cause `MessagePresentationAction { type: "callback" }` is "opaque callback value interpreted by the target channel/plugin" (`src/interactive/payload.ts:78-82`), and the SDK dispatcher returns only `{ matched: false }` for an unclaimed tap (`src/plugins/interactive.ts:63-65`). Nothing records that the agent owns the control, so each channel picks its own fallback. Telegram patched this privately with `channelData.telegram.typedCallbackOwner`, which was set on only two producer paths (`extensions/telegram/src/channel-actions.ts:215-249`, `button-types.ts:270-282`). ## Solution One core owner records ownership **inside the value**: - `src/interactive/agent-control.ts` (new, core-private codec): `stampAgentControls()` prefixes every callback value that a message action authors with a 2-byte mark (`::`), unconditionally; the decoder removes exactly one mark, so every authored value round-trips (`::pick:a` → `callback_data: ::pick:a`). A leading `:` is an empty namespace, and the plugin registry refuses empty namespaces (`interactive-registry.ts:58-68`), so a plugin can never claim a value by its mark. - Marking happens where controls **leave core for a channel**, which a delivery reaches exactly once (not at the runner entry, whose params can re-enter through the runner's own Gateway `message.action` hop): - `dispatchChannelMessageAction`: the plugin-action leaf, for runner actions and direct Gateway `message.action` callers. - `executeSendAction` core branch: right before `sendMessage` persists the payload to the outbound queue, so recovered sends keep the mark. Queue recovery delivers the stored payload without passing a leaf again. - `extractToolAuthoredSourceReplyPayload`: tool-authored source replies, which are delivered by the reply pipeline, not by either leaf above. - `dispatchPluginInteractiveHandler` strips the mark before namespace matching and passes the plain value to the handler. The result type is unchanged. - Additive SDK exports on `openclaw/plugin-sdk/interactive-runtime`: `agentControlText(data)` returns `callback_data: <value>` for a marked value and `undefined` otherwise; `stampAgentControls(payload)` marks a payload's callback controls (Telegram uses it once, for sends queued by v2026.11.5). - Channels: an unclaimed tap → `agentControlText(data) ?? <current behavior>`. - **Telegram**: marked values travel raw in `callback_data` (62 bytes for the agent's value; the old `tgac1:` envelope left 52). Unmarked typed values keep the `tgcb1` envelope, and an unclaimed one still answers "This action is no longer available." (#116383 semantics). - **Slack, LINE, Teams, Feishu (legacy quick envelope), Mattermost (legacy signed context), Discord (registry path)**: decode the mark so it never reaches the agent. The mark is part of the value, so every encoder, the delivery queue and a Gateway restart keep it without channel cooperation. No state, config, schema, timers or flags. ## What was deleted - Telegram: `TELEGRAM_AGENT_CALLBACK_PREFIX` (`tgac1:`), `TelegramTypedCallbackOwner`, the `owner` parameter, `hasTelegramAgentCallbackPrefix` / `parseTelegramAgentCallbackData`, `typedCallbackOwner` in `TelegramButtonBuildOptions`, the `prepareSendPayload` mark and its `interactive-fallback` reader, and the router's `tgac1` branches. - `tgac1` shipped in v2026.11.5 (backport `9afcc1b7b29a`), so a read-only `tgac1` decoder stays in the Telegram router for buttons already in chats (plugin-first on the inner value, then `callback_data: <value>`). Outgoing agent buttons no longer use it; remove the reader once those messages have aged out. Sends still queued by v2026.11.5 carry `channelData.telegram.typedCallbackOwner: "agent"`; Telegram's canonicalize step marks those with the core codec (remove once such queue rows have drained). ## Accepted edges (named, not coded) - Typed agent buttons delivered as `tgcb1:` by stables before v2026.11.5 are indistinguishable from plugin buttons: they keep their current behavior (unclaimed → unavailable). The agent can resend. - A plugin installed later can claim older agent buttons in its namespace (plugin-first is kept on the inner value). - Values starting with `/` now arrive as `callback_data: /…` instead of running as commands. Use `action.type: "command"` for command buttons (docs updated). - Marking closes a spoof: a legacy raw value could previously mint `tgcmd:` or approval-looking data on Telegram. - Native passthrough (raw Telegram `reply_markup`, Slack blocks, Discord `components`) is not marked and keeps its current owner. Discord native components/forms keep the registry and `agentComponents.ttlMs`. - Discord presentation buttons still use the 30-minute registry TTL. Stateless Discord controls are the next PR. - Slack delivers the tap as a session system event (now the plain `callback_data: <value>` text), not a user message. - Repeat taps produce repeat turns, the same as typing twice. Telegram still clears the keyboard on tap. - Third-party channel plugins that forward raw callback values show the 2-byte mark to the agent until they adopt `agentControlText`. - Teams/Mattermost value size is unbounded (needs a separate decision). - Taps route to the conversation's session (unchanged for Telegram, Slack, Teams, LINE, Mattermost). ## Plugin SDK impact - Additive: `agentControlText` and `stampAgentControls` on `plugin-sdk/interactive-runtime` (the focused presentation subpath; `plugin-runtime` is a deprecated broad barrel). No type change; `MessagePresentationAction` and the dispatcher result are unchanged. - Behavior: message-action callback values reach channel adapters with a leading `::`, and plugin interactive handlers receive the value without it. - ClawHub static usage (plugin-sdk-impact, 2026-11-19, 2,675 eligible releases, coverage incomplete: 423 partial, 1 failed): `api.registerInteractiveHandler` 10 plugins, `plugin-runtime#dispatchPluginInteractiveHandler` 3, `#createChannelInteractiveDispatcher` 2, `#registerPluginInteractiveHandler` 1. Handlers keep receiving the same `namespace`/`payload`; channel plugins that forward raw values see the mark (degradation, not a break). Bundled source scan not run. ## Tests (red on base `2d9c5d679497`, green on head) Wire bytes come from a real send through `runMessageAction` → the Telegram plugin → a loopback Bot API (`test/telegram-agent-control-taps.integration.test.ts`); the Telegram tap tests feed those exact bytes through the real callback router. | Test | Base | Head | |---|---|---| | `test/telegram-agent-control-taps.integration.test.ts` send on the core-forced path (`forceCoreDelivery`, what queue persistence uses; skips `prepareSendPayload`) + edit → `callback_data` | ✗ (`tgcb1:`/`tgac1:` envelopes) | ✓ `::/pick a\|1`, `::pick:b`, 64-byte legacy | | `bot.agent-callbacks`: unclaimed agent tap → `callback_data: /pick a\|1`, no mark | ✗ | ✓ | | `bot.agent-callbacks`: plugin claims inner value first | ✗ | ✓ | | `bot.agent-callbacks`: mention-gated group tap delivered | ✗ | ✓ | | `bot.agent-callbacks`: agent control with inline buttons off → unavailable | ✗ | ✓ | | `bot.agent-callbacks`: `tgac1` button already sent by v2026.11.5 → `callback_data: pick:beta` | ✓ (guard) | ✓ | | `bot.agent-callbacks`: unauthorized tapper ignored; unclaimed `tgcb1` → unavailable | ✓ (guard) | ✓ | | `message-action-runner.plugin-dispatch`: runner → plugin marked once; authored `::a` → `::::a` | ✗ | ✓ | | `message-action-gateway`: runner → Gateway `message.action` hop forwards controls unmarked (the Gateway leaf marks once) | ✓ (guard) | ✓ | | `outbound-send-service`: core send marks once before queue persistence | ✗ | ✓ | | `message-action-dispatch.registry`: direct Gateway message action marked once; authored `::pick:a` round-trips | ✗ | ✓ | | `interactive-fallback`: send queued by v2026.11.5 with `typedCallbackOwner` → `::pick:a` | ✗ | ✓ | | `embedded-agent-messaging-extraction.tool-authored`: source reply marked once (`:pick:a` → `:::pick:a`) | ✗ | ✓ | | `src/plugins/interactive.test.ts`: decode removes exactly one mark (`::::pick:a` → `callback_data: ::pick:a`) | ✗ | ✓ | | `src/plugins/interactive.test.ts` dispatcher matches by value, not mark | ✗ | ✓ | | `embedded-agent-messaging-extraction.tool-authored` source reply marked | ✗ | ✓ | | Slack `interactions.lifecycle`, LINE `bot-message-context`, Teams `monitor-handler.adaptive-card`, Feishu `bot.card-action`, Mattermost `monitor-interactions.question` + `interactions` | ✗ each | ✓ each | Consumer suites rerun on head: Telegram, Slack events, LINE, Teams, Feishu, Mattermost, Discord monitor, `src/infra/outbound` (107 files), `src/interactive`. `message-action-runner.plugin-dispatch` updated for the marked value. `extensions/mattermost/src/mattermost/slash-http.boundary.test.ts` fails identically on base (inherited, untouched). Gates: `pnpm tsgo:core`, `pnpm check:test-types`, oxlint/oxfmt on changed files, rg for removed symbols (only the historical `config/test-lines-allocations/196217-*` record mentions `tgac1`). ## E2E (Telegram Test Server, real user via TDLib, isolated scratch Gateway from source, real model `gpt-5.5`) The agent was asked to send "Pick one <run>" with Alpha/Beta callback buttons through the `message` tool and to reply `GOT <value>` after a tap; the userbot tapped Beta. | Run | Rendered `callback_data` (Beta) | Agent received / replied | |---|---|---| | Base v2026.11.5 | `tgac1:17dsn:pick:beta` | `GOT pick:beta` | | Head `a960e5e7ac4c`, authored value `::pick:beta` | `::::pick:beta` | `GOT ::pick:beta` (exact round trip, one mark removed) | | Head `a960e5e7ac4c`, Gateway restarted after the turn (121 s), then the original message's button tapped | `::pick:beta` | `GOT pick:beta` | Re-run on the final Telegram code (heads `8d5d953` / `9a18b4c`; the last commit touches only Discord): | Run | Agent received / replied | |---|---| | Plain Beta tap (`pick:beta`) | `GOT pick:beta` | | Authored value `::x` | `GOT ::x` (exact round trip) | | Scratch Gateway restarted between send and tap (`9a18b4c`) | `GOT pick:beta` | Note: v2026.11.5 already carries the `tgac1` backport, so the plain message-tool send/edit path on Telegram is not red on stable. On Telegram, this PR replaces that private patch with the core owner (no regression, now also covering the paths that skip `prepareSendPayload`). The user-visible base defects are on the other channels, proven by the handler tests above. <details><summary>Sanitized E2E timelines (TDLib recorder, real user, real model gpt-5.5)</summary> #### Base v2026.11.5 (e13cf15) ```text 193 ms action send completed <prompt: send "Pick one <run>" with Alpha (pick:alpha) / Beta (pick:beta) callback buttons; reply GOT <value> on tap> 193 ms message user <prompt: send "Pick one <run>" with Alpha (pick:alpha) / Beta (pick:beta) callback buttons; reply GOT <value> on tap> 126937 ms message bot Pick one 3E6C05F3 callback_data=[['tgac1:bcaw3:pick:alpha', 'tgac1:17dsn:pick:beta']] (msg 013568) 127389 ms action click completed Beta (msg 013568) 127944 ms message bot Working / Message: running 129930 ms edit bot Working / Last activity: Message 132155 ms delete bot 140750 ms message bot GOT pick:beta ``` #### Head a960e5e, authored Beta value `::pick:beta` ```text 186 ms action send completed <prompt: send "Pick one <run>" with Alpha (pick:alpha) / Beta (::pick:beta) callback buttons; reply GOT <value> on tap> 187 ms message user <prompt: send "Pick one <run>" with Alpha (pick:alpha) / Beta (::pick:beta) callback buttons; reply GOT <value> on tap> 55704 ms message bot Pick one 69957FA7 callback_data=[['::pick:alpha', '::::pick:beta']] (msg 184320) 56063 ms action click completed Beta (msg 184320) 58691 ms message bot Working / ✉️ Message 61747 ms message bot GOT ::pick:beta 62921 ms delete bot ``` #### Head a960e5e, Gateway restarted between send and tap ```text 192 ms action send completed <prompt: send "Pick one <run>" with Alpha (pick:alpha) / Beta (pick:beta) callback buttons; reply GOT <value> on tap> 192 ms message user <prompt: send "Pick one <run>" with Alpha (pick:alpha) / Beta (pick:beta) callback buttons; reply GOT <value> on tap> 68815 ms message bot Pick one 5F394A3C callback_data=[['::pick:alpha', '::pick:beta']] (msg 378624) 68815 ms action awaitReply completed Pick one 5F394A3C 70886 ms message bot Working / ✉️ Message running 71983 ms edit bot Working / ✉️ Message 74975 ms delete bot 480757 ms action click completed Beta (msg 378624) 510229 ms message bot GOT pick:beta gateway action: restartGateway at 150002 ms, took 120775 ms, completed ``` </details> ## Size - Production: +153 / −81 (net **+72**). Telegram −32 (includes the read-only `tgac1` decoder and the v2026.11.5 queued-send reader); core codec, the three exactly-once leaves, dispatcher strip and SDK exports +89; six channel decoders +15. Not net negative: the line-cap ratchet required a sibling codec module and kept Telegram's existing `resolveTelegramButtonsFromParams` wrapper; shipped-stable compatibility (v2026.11.5 `tgac1` buttons and queued sends) and exactly-once leaf marking were added in review. The series goes net negative in the same owner: Discord stateless controls retire the unused `agent:`/`agentsel:` handlers (133 lines), and Mattermost drops its duplicate tap delivery. - Tests/docs/test config: +287 net (old `tgac1` tests deleted; test lines within the 400-line budget). ## Local review Local ClawSweeper review (gpt-6.1-sol) on `9a18b4c`: **patch is correct, 0 findings**. Earlier rounds found and this PR fixed: the lossy idempotent mark (now marked exactly once where controls leave core), Telegram sends queued by v2026.11.5, and Discord legacy `{label, value}` buttons and selects falling into the command fallback before the agent decoder (test: `extensions/discord/src/monitor/monitor.test.ts` "delivers marked legacy presentation controls as agent callback data", red without the fix). Co-authored-by: Ayaan Zaidi <[email protected]>
…penclaw#201764) ## Problem A button the agent sends with the `message` tool (`presentation` button with `action: { type: "callback", value }`, or a legacy `value`) has no recorded owner. When no plugin claims the tap, each channel guesses: - **Slack**: the agent gets a `Slack interaction: {json…}` system event instead of the value. - **Discord** (registry path): the agent gets only `Clicked "<label>"`; the callback value is lost. - **Teams**: the agent gets the raw card JSON `{"value":…,"label":…}`. - **Telegram**: v2026.11.5 and main already deliver `message`-tool buttons through a Telegram-private patch (`tgac1`, backported to stable as `9afcc1b7b29a`), so the plain send/edit path works on stable (E2E below). That patch is set only by Telegram's `prepareSendPayload` hook and its edit path. Paths that skip it still render the plugin envelope `tgcb1:` and expire with "This action is no longer available.": the queue-persistence/`forceCoreDelivery` path, tool-authored source replies and legacy `interactive`. Builds before v2026.11.5 expire every typed agent button. Legacy slash values run as commands. The main user-visible fixes are the other channels; on Telegram this PR replaces the private patch with the core owner and covers the paths it missed. - **Feishu / Mattermost / LINE**: legacy values pass through without an owner. ## Root cause `MessagePresentationAction { type: "callback" }` is "opaque callback value interpreted by the target channel/plugin" (`src/interactive/payload.ts:78-82`), and the SDK dispatcher returns only `{ matched: false }` for an unclaimed tap (`src/plugins/interactive.ts:63-65`). Nothing records that the agent owns the control, so each channel picks its own fallback. Telegram patched this privately with `channelData.telegram.typedCallbackOwner`, which was set on only two producer paths (`extensions/telegram/src/channel-actions.ts:215-249`, `button-types.ts:270-282`). ## Solution One core owner records ownership **inside the value**: - `src/interactive/agent-control.ts` (new, core-private codec): `stampAgentControls()` prefixes every callback value that a message action authors with a 2-byte mark (`::`), unconditionally; the decoder removes exactly one mark, so every authored value round-trips (`::pick:a` → `callback_data: ::pick:a`). A leading `:` is an empty namespace, and the plugin registry refuses empty namespaces (`interactive-registry.ts:58-68`), so a plugin can never claim a value by its mark. - Marking happens where controls **leave core for a channel**, which a delivery reaches exactly once (not at the runner entry, whose params can re-enter through the runner's own Gateway `message.action` hop): - `dispatchChannelMessageAction`: the plugin-action leaf, for runner actions and direct Gateway `message.action` callers. - `executeSendAction` core branch: right before `sendMessage` persists the payload to the outbound queue, so recovered sends keep the mark. Queue recovery delivers the stored payload without passing a leaf again. - `extractToolAuthoredSourceReplyPayload`: tool-authored source replies, which are delivered by the reply pipeline, not by either leaf above. - `dispatchPluginInteractiveHandler` strips the mark before namespace matching and passes the plain value to the handler. The result type is unchanged. - Additive SDK exports on `openclaw/plugin-sdk/interactive-runtime`: `agentControlText(data)` returns `callback_data: <value>` for a marked value and `undefined` otherwise; `stampAgentControls(payload)` marks a payload's callback controls (Telegram uses it once, for sends queued by v2026.11.5). - Channels: an unclaimed tap → `agentControlText(data) ?? <current behavior>`. - **Telegram**: marked values travel raw in `callback_data` (62 bytes for the agent's value; the old `tgac1:` envelope left 52). Unmarked typed values keep the `tgcb1` envelope, and an unclaimed one still answers "This action is no longer available." (openclaw#116383 semantics). - **Slack, LINE, Teams, Feishu (legacy quick envelope), Mattermost (legacy signed context), Discord (registry path)**: decode the mark so it never reaches the agent. The mark is part of the value, so every encoder, the delivery queue and a Gateway restart keep it without channel cooperation. No state, config, schema, timers or flags. ## What was deleted - Telegram: `TELEGRAM_AGENT_CALLBACK_PREFIX` (`tgac1:`), `TelegramTypedCallbackOwner`, the `owner` parameter, `hasTelegramAgentCallbackPrefix` / `parseTelegramAgentCallbackData`, `typedCallbackOwner` in `TelegramButtonBuildOptions`, the `prepareSendPayload` mark and its `interactive-fallback` reader, and the router's `tgac1` branches. - `tgac1` shipped in v2026.11.5 (backport `9afcc1b7b29a`), so a read-only `tgac1` decoder stays in the Telegram router for buttons already in chats (plugin-first on the inner value, then `callback_data: <value>`). Outgoing agent buttons no longer use it; remove the reader once those messages have aged out. Sends still queued by v2026.11.5 carry `channelData.telegram.typedCallbackOwner: "agent"`; Telegram's canonicalize step marks those with the core codec (remove once such queue rows have drained). ## Accepted edges (named, not coded) - Typed agent buttons delivered as `tgcb1:` by stables before v2026.11.5 are indistinguishable from plugin buttons: they keep their current behavior (unclaimed → unavailable). The agent can resend. - A plugin installed later can claim older agent buttons in its namespace (plugin-first is kept on the inner value). - Values starting with `/` now arrive as `callback_data: /…` instead of running as commands. Use `action.type: "command"` for command buttons (docs updated). - Marking closes a spoof: a legacy raw value could previously mint `tgcmd:` or approval-looking data on Telegram. - Native passthrough (raw Telegram `reply_markup`, Slack blocks, Discord `components`) is not marked and keeps its current owner. Discord native components/forms keep the registry and `agentComponents.ttlMs`. - Discord presentation buttons still use the 30-minute registry TTL. Stateless Discord controls are the next PR. - Slack delivers the tap as a session system event (now the plain `callback_data: <value>` text), not a user message. - Repeat taps produce repeat turns, the same as typing twice. Telegram still clears the keyboard on tap. - Third-party channel plugins that forward raw callback values show the 2-byte mark to the agent until they adopt `agentControlText`. - Teams/Mattermost value size is unbounded (needs a separate decision). - Taps route to the conversation's session (unchanged for Telegram, Slack, Teams, LINE, Mattermost). ## Plugin SDK impact - Additive: `agentControlText` and `stampAgentControls` on `plugin-sdk/interactive-runtime` (the focused presentation subpath; `plugin-runtime` is a deprecated broad barrel). No type change; `MessagePresentationAction` and the dispatcher result are unchanged. - Behavior: message-action callback values reach channel adapters with a leading `::`, and plugin interactive handlers receive the value without it. - ClawHub static usage (plugin-sdk-impact, 2026-11-19, 2,675 eligible releases, coverage incomplete: 423 partial, 1 failed): `api.registerInteractiveHandler` 10 plugins, `plugin-runtime#dispatchPluginInteractiveHandler` 3, `#createChannelInteractiveDispatcher` 2, `#registerPluginInteractiveHandler` 1. Handlers keep receiving the same `namespace`/`payload`; channel plugins that forward raw values see the mark (degradation, not a break). Bundled source scan not run. ## Tests (red on base `80a1676e6269`, green on head) Wire bytes come from a real send through `runMessageAction` → the Telegram plugin → a loopback Bot API (`test/telegram-agent-control-taps.integration.test.ts`); the Telegram tap tests feed those exact bytes through the real callback router. | Test | Base | Head | |---|---|---| | `test/telegram-agent-control-taps.integration.test.ts` send on the core-forced path (`forceCoreDelivery`, what queue persistence uses; skips `prepareSendPayload`) + edit → `callback_data` | ✗ (`tgcb1:`/`tgac1:` envelopes) | ✓ `::/pick a\|1`, `::pick:b`, 64-byte legacy | | `bot.agent-callbacks`: unclaimed agent tap → `callback_data: /pick a\|1`, no mark | ✗ | ✓ | | `bot.agent-callbacks`: plugin claims inner value first | ✗ | ✓ | | `bot.agent-callbacks`: mention-gated group tap delivered | ✗ | ✓ | | `bot.agent-callbacks`: agent control with inline buttons off → unavailable | ✗ | ✓ | | `bot.agent-callbacks`: `tgac1` button already sent by v2026.11.5 → `callback_data: pick:beta` | ✓ (guard) | ✓ | | `bot.agent-callbacks`: unauthorized tapper ignored; unclaimed `tgcb1` → unavailable | ✓ (guard) | ✓ | | `message-action-runner.plugin-dispatch`: runner → plugin marked once; authored `::a` → `::::a` | ✗ | ✓ | | `message-action-gateway`: runner → Gateway `message.action` hop forwards controls unmarked (the Gateway leaf marks once) | ✓ (guard) | ✓ | | `outbound-send-service`: core send marks once before queue persistence | ✗ | ✓ | | `message-action-dispatch.registry`: direct Gateway message action marked once; authored `::pick:a` round-trips | ✗ | ✓ | | `interactive-fallback`: send queued by v2026.11.5 with `typedCallbackOwner` → `::pick:a` | ✗ | ✓ | | `embedded-agent-messaging-extraction.tool-authored`: source reply marked once (`:pick:a` → `:::pick:a`) | ✗ | ✓ | | `src/plugins/interactive.test.ts`: decode removes exactly one mark (`::::pick:a` → `callback_data: ::pick:a`) | ✗ | ✓ | | `src/plugins/interactive.test.ts` dispatcher matches by value, not mark | ✗ | ✓ | | `embedded-agent-messaging-extraction.tool-authored` source reply marked | ✗ | ✓ | | Slack `interactions.lifecycle`, LINE `bot-message-context`, Teams `monitor-handler.adaptive-card`, Feishu `bot.card-action`, Mattermost `monitor-interactions.question` + `interactions` | ✗ each | ✓ each | Consumer suites rerun on head: Telegram, Slack events, LINE, Teams, Feishu, Mattermost, Discord monitor, `src/infra/outbound` (107 files), `src/interactive`. `message-action-runner.plugin-dispatch` updated for the marked value. `extensions/mattermost/src/mattermost/slash-http.boundary.test.ts` fails identically on base (inherited, untouched). Gates: `pnpm tsgo:core`, `pnpm check:test-types`, oxlint/oxfmt on changed files, rg for removed symbols (only the historical `config/test-lines-allocations/196217-*` record mentions `tgac1`). ## E2E (Telegram Test Server, real user via TDLib, isolated scratch Gateway from source, real model `gpt-5.5`) The agent was asked to send "Pick one <run>" with Alpha/Beta callback buttons through the `message` tool and to reply `GOT <value>` after a tap; the userbot tapped Beta. | Run | Rendered `callback_data` (Beta) | Agent received / replied | |---|---|---| | Base v2026.11.5 | `tgac1:17dsn:pick:beta` | `GOT pick:beta` | | Head `a960e5e7ac4c`, authored value `::pick:beta` | `::::pick:beta` | `GOT ::pick:beta` (exact round trip, one mark removed) | | Head `a960e5e7ac4c`, Gateway restarted after the turn (121 s), then the original message's button tapped | `::pick:beta` | `GOT pick:beta` | Re-run on the final Telegram code (heads `8d5d953` / `9a18b4c`; the last commit touches only Discord): | Run | Agent received / replied | |---|---| | Plain Beta tap (`pick:beta`) | `GOT pick:beta` | | Authored value `::x` | `GOT ::x` (exact round trip) | | Scratch Gateway restarted between send and tap (`9a18b4c`) | `GOT pick:beta` | Note: v2026.11.5 already carries the `tgac1` backport, so the plain message-tool send/edit path on Telegram is not red on stable. On Telegram, this PR replaces that private patch with the core owner (no regression, now also covering the paths that skip `prepareSendPayload`). The user-visible base defects are on the other channels, proven by the handler tests above. <details><summary>Sanitized E2E timelines (TDLib recorder, real user, real model gpt-5.5)</summary> #### Base v2026.11.5 (e13cf15) ```text 193 ms action send completed <prompt: send "Pick one <run>" with Alpha (pick:alpha) / Beta (pick:beta) callback buttons; reply GOT <value> on tap> 193 ms message user <prompt: send "Pick one <run>" with Alpha (pick:alpha) / Beta (pick:beta) callback buttons; reply GOT <value> on tap> 126937 ms message bot Pick one 3E6C05F3 callback_data=[['tgac1:bcaw3:pick:alpha', 'tgac1:17dsn:pick:beta']] (msg 013568) 127389 ms action click completed Beta (msg 013568) 127944 ms message bot Working / Message: running 129930 ms edit bot Working / Last activity: Message 132155 ms delete bot 140750 ms message bot GOT pick:beta ``` #### Head a960e5e, authored Beta value `::pick:beta` ```text 186 ms action send completed <prompt: send "Pick one <run>" with Alpha (pick:alpha) / Beta (::pick:beta) callback buttons; reply GOT <value> on tap> 187 ms message user <prompt: send "Pick one <run>" with Alpha (pick:alpha) / Beta (::pick:beta) callback buttons; reply GOT <value> on tap> 55704 ms message bot Pick one 69957FA7 callback_data=[['::pick:alpha', '::::pick:beta']] (msg 184320) 56063 ms action click completed Beta (msg 184320) 58691 ms message bot Working / ✉️ Message 61747 ms message bot GOT ::pick:beta 62921 ms delete bot ``` #### Head a960e5e, Gateway restarted between send and tap ```text 192 ms action send completed <prompt: send "Pick one <run>" with Alpha (pick:alpha) / Beta (pick:beta) callback buttons; reply GOT <value> on tap> 192 ms message user <prompt: send "Pick one <run>" with Alpha (pick:alpha) / Beta (pick:beta) callback buttons; reply GOT <value> on tap> 68815 ms message bot Pick one 5F394A3C callback_data=[['::pick:alpha', '::pick:beta']] (msg 378624) 68815 ms action awaitReply completed Pick one 5F394A3C 70886 ms message bot Working / ✉️ Message running 71983 ms edit bot Working / ✉️ Message 74975 ms delete bot 480757 ms action click completed Beta (msg 378624) 510229 ms message bot GOT pick:beta gateway action: restartGateway at 150002 ms, took 120775 ms, completed ``` </details> ## Size - Production: +153 / −81 (net **+72**). Telegram −32 (includes the read-only `tgac1` decoder and the v2026.11.5 queued-send reader); core codec, the three exactly-once leaves, dispatcher strip and SDK exports +89; six channel decoders +15. Not net negative: the line-cap ratchet required a sibling codec module and kept Telegram's existing `resolveTelegramButtonsFromParams` wrapper; shipped-stable compatibility (v2026.11.5 `tgac1` buttons and queued sends) and exactly-once leaf marking were added in review. The series goes net negative in the same owner: Discord stateless controls retire the unused `agent:`/`agentsel:` handlers (133 lines), and Mattermost drops its duplicate tap delivery. - Tests/docs/test config: +287 net (old `tgac1` tests deleted; test lines within the 400-line budget). ## Local review Local ClawSweeper review (gpt-6.1-sol) on `9a18b4c`: **patch is correct, 0 findings**. Earlier rounds found and this PR fixed: the lossy idempotent mark (now marked exactly once where controls leave core), Telegram sends queued by v2026.11.5, and Discord legacy `{label, value}` buttons and selects falling into the command fallback before the agent decoder (test: `extensions/discord/src/monitor/monitor.test.ts` "delivers marked legacy presentation controls as agent callback data", red without the fix). Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Telegram native-command buttons could be consumed by a plugin registered under the private
tgcmdnamespace. Stale or malformed typedtgcb1buttons acknowledged a tap but produced no visible result.Why This Change Was Made
The callback router now keeps parsed native commands on the native path, reserves the full typed-callback prefix, and terminalizes unhandled typed buttons by removing their controls and sending neutral unavailable feedback. Legacy raw
tgcb1:*plugin callbacks still reach their registered owner.No callback wire version, Plugin SDK, Gateway protocol, config, default, or question-flow change.
User Impact
Native Telegram command buttons always run the OpenClaw command they represent. Expired or retired typed buttons explain that the action is unavailable instead of silently dead-ending.
Verification
273/273passed acrossbot.create-telegram-bot.test.tsandbot.test.ts.pnpm check:changedpassed, including format, API baseline, boundaries, production/testtsgo, and lint.pnpm buildpassed after both remote SSH proof backends were unavailable.0.97.main; interveningmaincommits did not touch the four changed files.The user-driver does not expose an inline-button click command. The changed callback routes therefore use the mocked Bot API matrix below; the live userbot artifact proves the same exact-head Gateway and Telegram transport remain healthy.
{ "head": "21bc4c323bc0b98afbd8ffbb06441d2a0f82ec32", "proof": "telegram-e2e-userbot", "topology": "real Telegram user -> ephemeral exact-head Gateway -> mock provider -> Telegram bot reply", "providerRequests": 1, "recordingComplete": true, "timeline": [ { "elapsedMs": 953, "kind": "typing-start", "source": "sut" }, { "elapsedMs": 2533, "kind": "typing-stop", "source": "sut" }, { "elapsedMs": 2533, "kind": "message", "source": "sut", "text": "OPENCLAW_E2E_OK" } ], "scratchRemovedAfterExit": true, "status": "PASS" }{ "head": "21bc4c323bc0b98afbd8ffbb06441d2a0f82ec32", "proof": "Telegram callback router with mocked Bot API", "nativeNamespaceCollision": { "pluginCalls": 0, "nativeRuns": 1 }, "staleTypedCallback": { "acknowledged": 1, "buttonsCleared": 1, "visibleUnavailableMessages": 1, "rawTextFallthrough": 0 }, "malformedTypedCallback": { "acknowledged": 1, "buttonsCleared": 1, "visibleUnavailableMessages": 1, "rawTextFallthrough": 0 }, "legacyRawCallback": { "pluginCalls": 1, "visibleUnavailableMessages": 0 }, "inlineButtonsOff": { "pluginCalls": 0, "buttonsCleared": 1, "visibleUnavailableMessages": 1 }, "status": "PASS" }Exact-head callback boundary proof
Ephemeral exact-head Gateway + mock Telegram Bot API + mock provider + temporary collision plugin. The harness delivered real Bot API callback updates through polling and recorded outbound Bot API effects.
{ "schemaVersion": 1, "pr": 116383, "head": "21bc4c323bc0b98afbd8ffbb06441d2a0f82ec32", "completed": true, "harness": { "ephemeralGateway": true, "mockBotApi": true, "mockProvider": true, "externalCollisionPlugin": true }, "cases": [ { "name": "native namespace collision", "callbackAnswered": true, "sentVisibleOutcome": true, "unavailableFeedback": false, "buttonsCleared": true, "pluginInvocations": [] }, { "name": "legacy raw tgcb1 callback", "callbackAnswered": true, "sentVisibleOutcome": false, "unavailableFeedback": false, "buttonsCleared": false, "pluginInvocations": [ "tgcb1:inspect:123" ] }, { "name": "stale typed callback", "callbackAnswered": true, "sentVisibleOutcome": true, "unavailableFeedback": true, "buttonsCleared": true, "pluginInvocations": [] }, { "name": "malformed typed callback", "callbackAnswered": true, "sentVisibleOutcome": true, "unavailableFeedback": true, "buttonsCleared": true, "pluginInvocations": [] }, { "name": "native callback after inline buttons disabled", "callbackAnswered": true, "sentVisibleOutcome": true, "unavailableFeedback": true, "buttonsCleared": true, "pluginInvocations": [] } ], "assertions": { "nativeNamespaceRemainedTelegramOwned": true, "legacyRawCallbackRemainedPluginOwned": true, "staleTypedCallbackFailedVisible": true, "malformedTypedCallbackFailedVisible": true, "disabledNativeCallbackFailedVisible": true }, "passed": true }