Repository navigation
fix(telegram): route widgets in private topics - #198022
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: aba6275b4e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ...(sent.messageThreadId !== undefined | ||
| ? { message_thread_id: sent.messageThreadId, is_topic_message: true } |
There was a problem hiding this comment.
Restore the widget topic before selecting its ingress lane
For a widget in private topic 77, restoring the topic here happens after durable ingress and createTelegramSequentializer() have chosen their lanes. getTelegramSequentialKey() still reads the original widget_query as telegram:<chatId>, while normal messages and /new in that topic use telegram:<chatId>:topic:77. Consequently, a later message can overtake a tap awaiting lookup/authorization, and a topic reset cannot supersede that pre-adoption tap because the core supersede owner matches exact lane keys. Resolve the sent-widget origin before admission/sequentialization too, so both owners use the originating topic. extensions/telegram/AGENTS.md explicitly assigns “per-chat/topic lane derivation” to the ingress/sequential-key owners.
AGENTS.md reference: extensions/telegram/AGENTS.md:L17-L18
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Thanks, that lane mismatch is a real gap. The topic is restored too late for durable ingress and sequentialization. I’m moving origin resolution to the ingress owner and adding ordering/reset coverage before updating the PR.
The CI failure is separate: the new send test isolates the runtime store without preserving the module’s other exports or explaining that isolation. I’m fixing that test too.
|
Codex review: needs maintainer review before merge. What this changesThis PR enables Telegram widgets in private-chat topics and preserves their originating conversation through taps, queueing, and replay. Example: Send a Vote widget in private chat 111, topic 77, then tap it.
Review scores
ProductKind: Feature · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR provides an owner-backed extension that current main still lacks; the earlier lane-selection and mock-export blockers are resolved, with no remaining actionable findings. Priority: P3 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Telegram plugin translates widget presentation requests into Bot API sends, records their origin, and routes incoming widget queries through durable ingress, sender authorization, and the existing agent message pipeline. flowchart TD
A[Widget presenter] --> B[Telegram send and widget store]
B --> C[Telegram widget query]
C --> D[Prepare recorded topic]
D --> E[Durable ingress and sequential lane]
E --> F[Authorize sender and dispatch agent]
F --> A
Technical reviewBest possible solution: Extend the existing widget store, presenter, and ingress owners with one prepared topic origin shared by lane selection, replay, authorization, and dispatch. Do we have a high-confidence way to reproduce the issue? Current-main presenter guards, tests, documentation, and original feature history independently establish the deliberate private-topic exclusion; no target code was executed during this review. Is this the best way to solve the issue? The change addresses the protocol’s missing topic at the existing send-record boundary and prepares it before scheduling, preserving the existing authorization and durable-ingress owners. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 3aac8f1b97b5. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +118, Tests +330, Docs 0, Other +2. Total +450 across 16 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (2 earlier review cycles)
Reviewed November 13, 2026, 1:49 AM ET / 06:49 UTC (Revision 3). |
obviyus
left a comment
There was a problem hiding this comment.
Thanks for picking this up. Widgets in private-chat topics are worth supporting. Before this can land, four things need to change:
- Pick the topic before the tap enters a queue.
getTelegramSequentialKey(extensions/telegram/src/sequential-key.ts) reads onlywidget_query.chat.id, so a tap on a widget in topic 77 goes into the plain private-chat queue, and durable ingress makes the same choice. The topic is restored only later, in the router. As a result, a later message in topic 77 can run before the tap, and/newin that topic can't cancel a pending tap. Look up the recorded topic before both queues are chosen, and carry that same identity through to the handler. - Don't drop taps in plain private chats when the record is missing. Today, a tap whose sent-widget record is gone still reaches the agent. With this PR it is dropped. The store holds at most 1,000 widgets, and a failed record write is only logged, so taps on older or unrecorded widgets in normal private chats would stop working. Drop a tap only when its origin is a topic that can't be confirmed.
- Fix the test mock that fails CI. The new
../runtime.jsmock inwidget-send.test.tsdrops the module's other exports. That failschecks-fast-baseline-ratchets, which failsci-gate. Keep the real exports, for example withimportOriginal. - Show a real Telegram round trip. Telegram's
WidgetQueryhas no thread ID, so this design depends entirely on the stored record. Mocked Bot API tests can't show that it works. Please add one real run to the PR body with private values redacted: a widget sent in each of two private-chat topics, each one tapped, each one updated in place in its own topic, and the agent's reply landing in the right topic. Also include one tap in a plain private chat.
We'll run our own end-to-end test on the final head before merging.
Maintainers are taking this over and will push the fixes here.
|
Thanks for this. We're taking over the remaining work: we'll push the fixes to this branch, keep your commits and credit, and run a live Telegram test before merging. |
…g it Telegram's widget_query carries the chat but not the private-chat topic. Resolve the tapped widget's recorded topic before ingress admission and the sequentializer pick a lane, the same way poll answers already do, and persist it in the spool payload so replays keep that lane. A tap now waits behind earlier messages in its own topic, and /new in that topic can supersede it. The router reuses that prepared origin. A tap whose widget record is missing routes to the private chat itself, as before, instead of being dropped. Simplify route resolution and keep the real runtime exports in the send test. Co-authored-by: obviyus <[email protected]>
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Thanks for taking this over and running the live tests. I'll use your version in my Gateway build and leave this branch with you while you finish the remaining replay check. |
A tap admitted before a restart must keep its private-topic lane and origin from the spool payload, not from a fresh record lookup, and still run before a later message in the same topic. Co-authored-by: obviyus <[email protected]>
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
* fix(telegram): route widgets in private topics * fix(telegram): choose a widget tap's topic lane before sequentializing it Telegram's widget_query carries the chat but not the private-chat topic. Resolve the tapped widget's recorded topic before ingress admission and the sequentializer pick a lane, the same way poll answers already do, and persist it in the spool payload so replays keep that lane. A tap now waits behind earlier messages in its own topic, and /new in that topic can supersede it. The router reuses that prepared origin. A tap whose widget record is missing routes to the private chat itself, as before, instead of being dropped. Simplify route resolution and keep the real runtime exports in the send test. Co-authored-by: obviyus <[email protected]> * test(telegram): restore a queued widget tap's topic after a restart A tap admitted before a restart must keep its private-topic lane and origin from the spool payload, not from a fresh record lookup, and still run before a later message in the same topic. Co-authored-by: obviyus <[email protected]> --------- Co-authored-by: Ayaan Zaidi <[email protected]> Co-authored-by: obviyus <[email protected]>
Port Telegram callbacks, hook session keys, private-topic approvals and interactive widgets with complete send/edit/route security companions. Include Feishu captioned media, iOS permission Sendable callbacks, WebKit animation/menu retirement and pending automations props handling. Keep Matrix malformed formatted-mention parsing linear-time. Adapt the 11.4 equivalents to the fixed beta baseline where available. Source PRs: #196217, #191585, #196822, #194027, #197519, #198038, #196991, #198380, #198658, #184432. Companion scope: #191647, #192162, #198022, #197271, #194146; #197670 is folded into #197519 equivalent. (cherry picked from commit 928c118) (cherry picked from commit 569ca48) (cherry picked from commit efa744e) (cherry picked from commit c301da9) (cherry picked from commit 641c4d5) (cherry picked from commit b9d3fb4) (cherry picked from commit a213a51) (cherry picked from commit ec46689) (cherry picked from commit 779d22e) (cherry picked from commit 129ccc3) (cherry picked from commit 849c050) (cherry picked from commit b22f35f) (cherry picked from commit 8b414e9) (cherry picked from commit 01ecda4) (cherry picked from commit f978e54) (cherry picked from commit 6e60479) (cherry picked from commit ec7b49a) (cherry picked from commit 1d72ad0) (cherry picked from commit 5e2c66f) (cherry picked from commit dfb6454) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit f7c581c7f8bf0e57c7d8799e928a121b24462450) Co-authored-by: vincentkoc <[email protected]>
What Problem This Solves
Telegram widgets (#196991) were turned off in private-chat topics. Telegram's
widget_querycarries the chat and message but not the topic, so a tap could not find its way back to the topic's conversation. Users who run their bot chat in Threaded Mode got no widgets there. Fixes #197923.User Impact
With
channels.telegram.widgets: true,show_widgetin a private-chat topic sends the widget into that topic. Tapping it runs the agent in that topic's conversation and updates the widget in place, like in a plain private chat. Plain private chats behave as before. Groups, channels and channel direct-message topics are unchanged.Why This Change Was Made
messageThreadId; absent in a plain private chat)./newin that topic can supersede it. Looking the topic up only inside the handler (the first version of this PR) left the tap on the plain-chat lane, where a later topic message could overtake it.Contributor: @dankarization wrote the original topic delivery and routing. The maintainer commit moves the topic lookup ahead of lane selection, restores routing for taps without a record, and simplifies the route check.
Evidence
Live Telegram Test Server, exact head
0a3ef28(also passed at6a43b6b) (builtdist, leased bot and TDLib 1.8.70 user, BotFather Threaded Mode on, deterministic mock model that callsshow_widget):show_widgetin topic A, then in a second topic Bchat_data{"votes":0})PINGin topic A{"votes":1}in topic A; the tap turn ran first, thenPONGreplied in topic A{"votes":1}in topic B; the tap turn's progress message appeared in topic BPINGPING(OpenClaw folded both into one turn because they arrived while the first turn was finishing), thenPONGNo extra widget messages were sent. The runner deleted its topics and restored Threaded Mode to off.
Ordering regression, real ingress queue:
telegram-ingress-spool.test.tsadmits a topic-widget tap and a later/newin the same topic. With this change both sharetelegram:7:topic:42and the tap dispatches first. On the first version of this PR the test fails: the tap lands ontelegram:7.Restart replay: the same file stops the monitor while the tap is mid-dispatch, changes the widget record to another topic, and restarts. The tap still runs on
topic:42from its spool payload, before the later topic message. Without restoring the payload origin the test fails.Unit tests: lane key with and without a recorded topic, two-topic routing, untracked-tap routing, presenter topic matching and delivery, and the Bot API send recording the topic. 58 tests pass across the widget, sequential-key and ingress-spool suites.
Stored data after upgrade: existing
telegram.widgetsrecords have nomessageThreadId. That is correct for all of them, because main never sent a widget into a topic; taps on them keep routing to the plain private chat. No schema or namespace changes.Checks: extension lint and the baseline ratchets pass locally (including mock exports and test lines).