Skip to content

fix(telegram): forum approval drops the topic when the live turn omits it - #192162

Merged
obviyus merged 4 commits into
openclaw:mainfrom
claxman:fix/125166-telegram-forum-approval
Nov 13, 2026
Merged

obviyus merged 4 commits into
openclaw:mainfrom
claxman:fix/125166-telegram-forum-approval

Conversation

@claxman

@claxman claxman commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Closes #125166

What Problem This Solves

With execApprovals.target: "channel", an exec or plugin approval started in a Telegram forum topic is sent to the approver's private DM instead of the topic. The topic shows nothing, so the user in the topic does not see that the tool is waiting.

User Impact

The approval card is posted in the forum topic where the request started, as target: "channel" promises. A live turn from a different topic still does not match the stored route, so no card goes to a topic the request did not come from.

Why This Change Was Made

The origin check compares the live turn target with the stored session route and refuses the origin when they differ. Both carry the same topic, but in different shapes:

  • live turn: parsed to { to: "<chat>", threadId: 3 };
  • stored session route: { to: "telegram:<chat>:topic:3", threadId: 3 }, because the session resolver only ran normalizeTelegramChatId, which rejects the :topic: form.

The pair never matched, the origin resolved to null, and the planner fell back to the approver DM. The live turn does carry its topic, so the omitted-thread theory in the first revision did not match the real flow.

The Telegram adapter now normalizes the live turn and the stored session through one parser (toTelegramOriginTarget). The public reconcileDivergentTargets callback, its core plumbing and docs from the first revision are removed, so there is no SDK change. A stored target that cannot be parsed still has to disagree with the live turn.

Evidence

Live Telegram Test Server E2E, real Gateway + deterministic mock model, leased QA user, run-owned forum (--create-forum), execApprovals: { enabled: true, approvers: [<qa user>], target: "channel" }, tools.exec.mode: "ask". The user sends EXEC:/usr/bin/touch ... in the forum topic and taps Allow Once. The Bot API proxy log shows where each sendMessage went.

  • main at 8ebe740925ca: the card Approval required ... went to the private chat (chat: private, no topic). The topic only got Working / Exec running, and the tap found no button. The same happened for a plugin approval (before_tool_call → requireApproval).
  • A debug build of main logged the origin check inputs: live turn {"to":"-100…","threadId":3}, stored session {"to":"telegram:-100…:topic:3","threadId":3}.
  • This head ff04a839e875: the exec approval card was posted in the forum topic, the Allow Once tap edited that card, the command ran and EXEC_DONE arrived in the topic. A plugin approval (🛡️ Plugin approval required) was also posted in the topic and resolved by a tap there. Nothing went to the private chat.
  • Regression: approval-native.test.ts stores the real telegram:<chat>:topic:<id> route; the same-topic case fails on main and passes here, the different-topic control stays null.
Bot API proxy log (chat kind, topic id, text prefix)

main 8ebe740:

18:10:18  sendMessage      chat=group topic=3  'PONG:warm'
18:10:21  sendMessage      chat=private topic=-  'Approval required.\n\nRun:\n\n<pre><code cla'
18:10:21  sendMessage      chat=group topic=3  '<b>Working</b>\n🛠️ <b>Exec</b> <i>runnin'
18:15:08  editMessageText  chat=group topic=-  '<b>Working</b>\n🛠️ <b>Exec</b>'

This head ff04a83 (exec approval, then plugin approval; the last card is the exec approval that follows the plugin approval, left untapped):

19:20:36  sendMessage      chat=group topic=3  'PONG:warm'
19:20:38  sendMessage      chat=group topic=3  'Approval required.\n\nRun:\n\n<pre><code cla'
19:20:39  editMessageText  chat=group topic=-  '✅ Approval resolved here\nRecorded result'
19:20:40  sendMessage      chat=group topic=3  'EXEC_DONE:(no output)'
19:20:41  editMessageText  chat=group topic=-  '✅ Exec approval resolved\nRecorded result'
19:21:35  sendMessage      chat=group topic=3  '<b>Working</b>\n🛠️ <b>Exec</b> <i>runnin'
19:21:36  sendMessage      chat=group topic=3  '🛡️ Plugin approval required\nTitle: Prob'
19:21:37  editMessageText  chat=group topic=-  '✅ Approval resolved here\nRecorded result'
19:21:38  editMessageText  chat=group topic=-  '✅ Plugin approval resolved\nRecorded resu'
19:21:39  sendMessage      chat=group topic=3  'Approval required.\n\nRun:\n\n<pre><code cla'
Captured Telegram events at this head (TDLib recorder on the QA user)
    0.4s  user  message topic 3      msg#145729  PING:warm
   13.1s  bot   message topic 3      msg#242880  PONG:warm
   13.3s  user  message topic 3      msg#242881  EXEC:/usr/bin/touch /tmp/c-topics-forum-exec
   15.4s  bot   message topic 3      msg#340032  Approval required. /  / Run: /  / /approve 6d8a2770-6381-4c09-a102-038
   15.8s  user  tap     Allow Once -> completed
   16.4s  bot   edit    topic 3      msg#340032  ✅ Approval resolved here / Recorded result: Allowed once / ID: 6d8a277
   17.4s  bot   message topic 3      msg#388608  EXEC_DONE:(no output)
   18.4s  bot   edit    topic 3      msg#340032  ✅ Exec approval resolved / Recorded result: Allowed once / Resolved by
   70.2s  user  message topic 3      msg#388609  EXEC:/usr/bin/true PLUGINAPPROVE
   72.7s  bot   message topic 3      msg#485760  Working / 🛠️ Exec running
   73.7s  bot   message topic 3      msg#534336  🛡️ Plugin approval required / Title: Probe approval / Description: Pro
   74.1s  user  tap     Allow Once -> completed
   74.7s  bot   edit    topic 3      msg#534336  ✅ Approval resolved here / Recorded result: Allowed once / ID: plugin:
   75.7s  bot   edit    topic 3      msg#534336  ✅ Plugin approval resolved / Recorded result: Allowed once / Resolved 
   76.7s  bot   message topic 3      msg#582912  Approval required. /  / Run: /  / /approve e2bde095-d09e-452b-8095-9b0

A plugin approval started in a Telegram forum topic can carry the group on the live turn and the topic only on the stored session. Exact origin matching treated the missing thread as a conflict and dropped the origin, so the prompt went to the approver DM.

When the chat matches and only one side has a thread, keep that thread. Two different threads still do not route.
The new resolver option is part of the public origin helper, so the channel approvals doc lists it with the other options. The core comment no longer describes Telegram threads, and the hook is passed through without normalizing targets a second time.
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: telegram Channel integration: telegram size: S labels Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Security-sensitive guard cleared

Current revision: ff04a839e875893e95a4f94110f3be98867364ab

This PR no longer changes files in the maintainer security-review tier.

Separate CODEOWNERS requirements still apply to security policy and enforcement files.

@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. labels Nov 3, 2026
@clawsweeper

clawsweeper Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR normalizes live and stored Telegram topic routes through the same parser before approval-origin matching.

Example: An approval originates in group -1003841603622, topic 928, with a stored route of telegram:-1003841603622:topic:928.

  • Before: Equivalent route representations disagree, so the approval card falls back to the approver DM.
  • After: The card stays in topic 928; a live topic of 111 still fails origin matching.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct adapter repair with discriminating regression coverage and strong production-entry-point delivery traces.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): Exact-head logs exercise a real Gateway, Telegram Test Server, QA-user callbacks, and the production transport with a deterministic model: exec and plugin cards reach forum topic 3, resolve there, and exec completion returns there without private-chat delivery; the inspected private-DM screenshot is separate contextual evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An approval card leaves its originating Telegram forum topic even when channel delivery is configured.
Reason: The change restores documented topic delivery without adding configuration, SDK contracts, or a competing routing owner.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR repairs a current forum approval-routing defect with a focused Telegram-local change and convincing delivery evidence; the earlier SDK finding is resolved.

Priority: P2
Reviewed head: ff04a839e875893e95a4f94110f3be98867364ab

Before merge

None.

Findings

None.

Agent review details

How this fits together

Telegram's approval adapter interprets live request metadata and stored session delivery routes, then supplies a destination to the shared approval planner and Telegram transport.

flowchart TD
 A[Live approval request] --> C[Telegram target parser]
 B[Stored session route] --> C
 C --> D[Shared account and origin matching]
 D --> E[Native delivery planner]
 E --> F[Telegram forum topic]
 E --> G[Approver DM fallback]
Loading

Technical review

Best possible solution:

Land the Telegram-local normalization repair while retaining shared account eligibility and exact topic-conflict rejection.

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

Current-main source establishes the route-representation mismatch, and supplied Gateway-to-Telegram traces demonstrate its DM fallback; this read-only review executed no target code.

Is this the best way to solve the issue?

The revised patch fixes normalization at the existing Telegram adapter, removes the earlier public reconciliation callback, and preserves the shared consistency invariant.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Telegram topic interpretation keeps the original intent (ab3c646: Preserve approval topics by parsing topic-bearing live destinations with explicit thread precedence.)
  • Shared origin consistency keeps the original intent (aa6cf87: Centralize origin resolution and reject inconsistent live and stored bindings.)
  • Stored-target adapter keeps the original intent (561ffbf: Consolidate Telegram transport preparation without changing routing behavior.)
  • Direct Messages topic encoding keeps the original intent (cd35859: Deliver delegated system-agent approvals through the canonical channel approval path while preserving Telegram destination kinds.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +10, Tests +41, Other +2. Total +53 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 29 19 +10
Tests 1 41 0 +41
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 3 72 19 +53

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: fixed_by_candidate
Canonical: #125166
Summary: This PR repairs the canonical forum approval-card placement problem; private-DM targeting and terminal-result delivery are adjacent, separate paths.

Members:

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

Labels

Label changes:

  • add P2: Forum-topic approval prompts reach an available approver DM instead of their configured conversation, disrupting a limited Telegram workflow.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Forum-topic approval prompts reach an available approver DM instead of their configured conversation, disrupting a limited Telegram workflow.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster 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 (1 earlier review cycle)
  • reviewed 2026-11-03T18:31:03.027Z sha 0428b7b :: needs real behavior proof before merge. :: [P1] [P1] Recover the thread through the existing session-conversation API

Reviewed November 13, 2026, 2:28 PM ET / 19:28 UTC (Revision 2).

Copy link
Copy Markdown
Contributor

Related private-DM case: #197907 has the original Telegram screenshot and a sanitized incident report. The request came from a topic inside the approver's own private chat, but the card appeared outside that topic; the topic then said the approval had been sent to DMs “not this chat.”

This is a system-agent approval, and its source route already carried a topic. That differs from the missing group-forum thread in this PR, so I am not claiming this change fixes our case. We are tracing the configured approver-DM target separately and keeping other approvers and group privacy unchanged.

Copy link
Copy Markdown
Contributor

Opened the complementary private bot-topic fix in #198038. This case already has an origin topic, but the same user's approver-DM destination loses it. The patch keeps the topic only for the same numeric private chat and confirmed bot account, and avoids the misleading root-DM notice. It does not replace this PR's missing-forum-origin fix.

The original screenshot and 59 passing focused tests are in the new PR; no live post-fix client result is claimed.

obviyus and others added 2 commits November 14, 2026 00:20
The approval origin check compared the live turn, parsed to the bare chat
id, with the stored session route, which keeps the `telegram:<chat>:topic:<id>`
form. The pair never matched, so approvals from a forum topic with
`execApprovals.target: "channel"` fell back to the approver DM.

Normalize both sides through one Telegram origin-target parser and drop the
public reconcileDivergentTargets callback: the live turn does carry the topic.

Co-authored-by: obviyus <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot removed the docs Improvements or additions to documentation label 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 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. and removed clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. 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
@clawsweeper clawsweeper Bot added the status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. label Nov 13, 2026
@obviyus
obviyus merged commit 6e60479 into openclaw:main Nov 13, 2026
131 of 134 checks passed
@obviyus

obviyus commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 14, 2026
…s it (openclaw#192162)

* fix(telegram): keep forum topic when an approval turn omits the thread

A plugin approval started in a Telegram forum topic can carry the group on the live turn and the topic only on the stored session. Exact origin matching treated the missing thread as a conflict and dropped the origin, so the prompt went to the approver DM.

When the chat matches and only one side has a thread, keep that thread. Two different threads still do not route.

* fix(telegram): document the omitted-thread approval hook

The new resolver option is part of the public origin helper, so the channel approvals doc lists it with the other options. The core comment no longer describes Telegram threads, and the hook is passed through without normalizing targets a second time.

* fix(telegram): match stored forum topic routes for approval origins

The approval origin check compared the live turn, parsed to the bare chat
id, with the stored session route, which keeps the `telegram:<chat>:topic:<id>`
form. The pair never matched, so approvals from a forum topic with
`execApprovals.target: "channel"` fell back to the approver DM.

Normalize both sides through one Telegram origin-target parser and drop the
public reconcileDivergentTargets callback: the live turn does carry the topic.

Co-authored-by: obviyus <[email protected]>

---------

Co-authored-by: Ayaan Zaidi <[email protected]>
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)
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 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: S 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]: Plugin Approval from a Telegram forum topic falls back to approver DM

3 participants