Skip to content

fix(telegram): keep DM topic approvals in their conversation - #198038

Merged
obviyus merged 3 commits into
openclaw:mainfrom
dankarization:fix-telegram-dm-topic-approvals-20261113
Nov 13, 2026
Merged

obviyus merged 3 commits into
openclaw:mainfrom
dankarization:fix-telegram-dm-topic-approvals-20261113

Conversation

@dankarization

@dankarization dankarization commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Closes #197907

What Problem This Solves

An exec or plugin approval requested inside a private Telegram bot topic is sent to the root DM, not to the topic. The topic only gets "Approval required. I sent the approval request to Telegram DMs, not this chat." The user has to leave the conversation to find the card.

User Impact

When the requester is also an approver on the same Telegram account, the approval card and its result stay in the topic where the request started. Other approvers still get their usual DM card. The requester gets one terminal result, whichever approver card is processed first.

This screenshot shows the original bug, before the fix:

Approval sent outside its private bot topic

Why This Change Was Made

With execApprovals.target: "dm", the delivery plan uses only approver DM targets. The approver DM target for the requester is the bare chat id, so the topic was dropped.

  • The Telegram approver-DM resolver now carries the origin topic onto the requester's own DM target, only when the bot account and the numeric private chat both match the request origin.
  • The redirect notice is not sent when the card already went to the origin topic.
  • The terminal-result fallback waits for a later origin card in the same fan-out before it sends a separate result to the topic, so a requester that is processed second does not get two results. A failed edit of the topic card still sends one replacement result.

Evidence

Live Telegram Test Server E2E, real Gateway + deterministic mock model, leased QA user, Threaded Mode on, execApprovals: { enabled: true, approvers: [<qa user>], target: "dm" }, tools.exec.mode: "ask". The user sends EXEC:/usr/bin/touch ... inside a fresh DM topic, then taps Allow Once.

  • main at 8ebe740925ca: the card Approval required ... /approve <id> allow-once was posted in the root DM (no topic). The topic got Approval required. I sent the approval request to Telegram DMs, not this chat., and the tap could not find the button in the topic.
  • This head b358a299a60b: the card was posted in the topic (topicId=200489). The tap edited the same card to Exec approval resolved / Allowed once, the command ran, and one EXEC_DONE reply arrived in the topic. No redirect notice and no message in the root DM. A later PING:after in the topic was answered there.

Captured Telegram events (TDLib recorder on the QA user; msg# is the tail of the TDLib message id, so equal ids are the same message):

main 8ebe740 (before)
   97.3s  bot   message topic 198770 msg#985856  PONG:ctxa
   97.7s  user  message root DM      msg#985857  PING:rootctx
   97.7s  user  message topic 198770 msg#034433  EXEC:/usr/bin/touch /tmp/c-topics-approval-base
  100.1s  user  tap     Allow Once -> failed
  104.3s  bot   message root DM      msg#131584  PONG:rootctx
  107.2s  bot   message root DM      msg#180160  Approval required. /  / Run: /  / /approve ec14bb47-0f7c-499c-b392-fe0
  108.2s  bot   message topic 198770 msg#228736  Working / 🛠️ Exec running
  109.2s  bot   message topic 198770 msg#277312  Approval required. I sent the approval request to Telegram DMs, not th
this head b358a29 (after)
    0.2s  user  message topic 200489 msg#953665  PING:warm
    8.4s  bot   message topic 200489 msg#147968  PONG:warm
    8.6s  user  message topic 200489 msg#147969  EXEC:/usr/bin/touch /tmp/c-topics-approval-fix
   12.4s  bot   message topic 200489 msg#245120  Working / 🛠️ Exec running
   13.4s  bot   message topic 200489 msg#293696  Approval required. /  / Run: /  / /approve fda16bf4-fd1b-4571-9cf5-56f
   13.7s  user  tap     Allow Once -> completed
   14.4s  bot   edit    topic 200489 msg#293696  ✅ Approval resolved here / Recorded result: Allowed once / ID: fda16bf
   15.4s  bot   edit    topic 200489 msg#293696  ✅ Exec approval resolved / Recorded result: Allowed once / Resolved by
   16.4s  bot   edit    topic 200489 msg#245120  Working / 🛠️ Exec
   18.4s  bot   message topic 200489 msg#342272  EXEC_DONE:(no output)
   19.4s  bot   delete  topic 200489 msg#245120  
  200.4s  user  message topic 200489 msg#342273  PING:after
  204.9s  bot   message topic 200489 msg#439424  PONG:after
  • Regressions red on main: with this head's test files on main source, 15 cases fail (approval-native: matching private-chat approver keeps the origin topic, saved account binding; approval-handler.runtime: terminal results on the private topic for every outcome, and all six requester-first/requester-second/expiry/failed-edit fan-out orderings). All pass on this head.
  • Focused tests (78 pass on this head): approval-native, approval-handler.runtime (requester-first, requester-second, expiry and failed-edit orderings), approval-native-route-coordinator, approval-handler-runtime.

@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

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

View the workflow run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T02:12:39.455688Z c6f1425 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c6f14253c3

ℹ️ 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".

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 13, 2026
@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Keeps a matching approver’s Telegram approval card in the originating private topic and coordinates terminal results across approver cards.

Example: An approver requests an exec approval in private Telegram topic 200489 with target set to dm.

  • Before: The approval card appears in the root DM and the topic receives a redirect notice.
  • After: The card stays in topic 200489, is updated after approval, and the command result arrives there.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful, focused repair with captured end-to-end behavior and no actionable findings; the failing QA gate remains unattributed.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (logs): Captured Telegram events from the reviewed head exercise a real Gateway, deterministic model, leased Test Server user, private topic, approval callback, command execution, and subsequent reply; these resolve the previous request for inspectable output, while fan-out failure cases have focused regression coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Approvers must leave the active private Telegram topic to find an approval card in the root DM.
Reason: The change restores conversation-local delivery for the same authorized recipient without adding settings or changing other approvers’ destinations.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current Telegram routing defect and resolves the earlier duplicate-result finding; no actionable patch defects remain.

Priority: P2
Reviewed head: b358a299a60b6456c4e554a0b3526ad7a0ab1583

Before merge

None.

Findings

None.

Agent review details

How this fits together

The shared approval runtime plans delivery and finalizes cards; Telegram supplies account-scoped recipients, topic routing, and message transport.

flowchart TD
  A[Approval request] --> B[Shared delivery planner]
  B --> C[Telegram recipient resolver]
  C --> D[Requester private topic]
  C --> E[Other approver DMs]
  D --> F[Approval resolution]
  E --> F
  F --> G[Shared finalizer and Telegram card updates]
Loading

Technical review

Best possible solution:

Retain the focused account-scoped topic routing and shared fan-out context, then settle the failing exact-head QA gate before landing.

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

Current-main source maps approvers to bare DM recipients and drops the private topic; supplied before-fix Telegram events demonstrate that path, though no reproduction was executed during this read-only review.

Is this the best way to solve the issue?

The patch repairs recipient derivation in Telegram and exposes existing finalization order through the shared runtime, preserving account filtering, other approvers, and failed-edit fallback.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Telegram approver recipient derivation keeps the original intent (c87c8e6: Consolidate channel approvals around shared capability and resolver seams.)
  • Topic-aware terminal-result fallback keeps the original intent (6a6fa4d: Return terminal results to the originating topic without duplicating successful same-topic card edits.)
  • Shared approval finalization keeps the original intent (8853510: Share resolved and expired finalization while preserving approval authority and delivery behavior.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit cd35859 adds extensions/telegram/src/approval-handler.runtime.ts:275 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: cd358597cf49; files: extensions/telegram/src/approval-handler.runtime.ts)
  • Gustavo Madeira Santana: Raw commit c87c8e6 adds extensions/telegram/src/approval-native.ts:83 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c87c8e66bf7d; files: extensions/telegram/src/approval-native.ts)

PR surface

Source +70, Tests +270, Other +2. Total +342 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 89 19 +70
Tests 3 281 11 +270
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 8 372 30 +342

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Root-cause cluster

Relationship: same_root_cause
Canonical: #197907
Summary: The linked issue describes this private-DM recipient-topic defect; the forum-origin proposal addresses a separate metadata reconciliation failure.

Members:

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Approval routing affects private-topic conversations while approval remains available in the root DM.
  • merge-risk: 🚨 compatibility: The public approval transport callback gains optional remainingEntries context; this is an additive repair through the existing SDK owner, preserving existing callback implementations.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

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

Workflow

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

History

Review history (2 earlier review cycles)
  • reviewed 2026-11-13T02:19:27.076Z sha c6f1425 :: needs real behavior proof before merge. :: [P2] Coordinate terminal receipts across all delivered approval cards
  • reviewed 2026-11-13T18:02:14.792Z sha b358a29 :: needs real behavior proof before merge. :: none

Reviewed November 13, 2026, 1:20 PM ET / 18:20 UTC (Revision 3).

dankarization and others added 2 commits November 13, 2026 10:43
Wait for an approver card in the originating topic before sending a
fallback result. Keep terminal button cleanup for every approver and
send one fallback to the origin only if its card edit fails.

Cover requester-first and requester-second fanout, expiry and deleted
origin cards through the real approval handler.
@obviyus

obviyus commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 13, 2026
@obviyus

obviyus commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 13, 2026
@obviyus
obviyus merged commit 129ccc3 into openclaw:main Nov 13, 2026
161 of 164 checks passed
@obviyus

obviyus commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 14, 2026
…w#198038)

* fix(telegram): keep DM topic approvals in their conversation

* fix(telegram): avoid duplicate terminal approval replies

Wait for an approver card in the originating topic before sending a
fallback result. Keep terminal button cleanup for every approver and
send one fallback to the origin only if its card edit fails.

Cover requester-first and requester-second fanout, expiry and deleted
origin cards through the real approval handler.

---------

Co-authored-by: obviyus <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 14, 2026
* fix(telegram): keep DM topic approvals in their conversation

* fix(telegram): avoid duplicate terminal approval replies

Wait for an approver card in the originating topic before sending a
fallback result. Keep terminal button cleanup for every approver and
send one fallback to the origin only if its card edit fails.

Cover requester-first and requester-second fanout, expiry and deleted
origin cards through the real approval handler.

---------

Co-authored-by: obviyus <[email protected]>
(cherry picked from commit 129ccc3)

Release adaptation: retain the release runtime dependency seams and existing
unit cases; add the private-topic integration regressions as a separate file.
Bring only the prerequisite topic-aware pending-target identity from #137438
(6a6fa4d), using existing routing helpers, rather than its broader changes.
Use the existing async native approval capability so its async Telegram
resolver and runtime are actually invoked; no new storage internals are added.
Companion closure: #192162 fixes forum-origin normalization, not this private
DM numeric origin, and is not required.
Proof: source/route review and node --check passed. Runtime tests are blocked
by missing worktree dependencies; no dependency installation was attempted.

Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
(cherry picked from commit a427f5c9511eb3aa972c8b56d4fcc39efdf02f77)
@dankarization

Copy link
Copy Markdown
Contributor Author

Additional live routing proof — 2026-11-15

The bot owner verified this on a real Telegram bot in a private DM topic: the approval stayed in the conversation that requested it, instead of being sent to the root DM. The owner explicitly asked to preserve this screenshot here as proof.

The screenshot shows the terminal approval/result card in that same topic, alongside the original queue-mode request.

Scope: this confirms the observed conversation routing. The recorded result is Expired, so this is not evidence of successful authorization or execution of that particular configuration change. The running build's exact source ancestry was not independently established.

Live Telegram check: approval result in the requesting DM topic

RomneyDa added a commit that referenced this pull request Nov 15, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Approval leaves the current topic in a private Telegram chat

2 participants