Skip to content

fix(telegram): retry forum replies without invalid thread id#79410

Closed
Clausinho wants to merge 1 commit into
openclaw:mainfrom
Clausinho:fix/telegram-forum-thread-fallback
Closed

fix(telegram): retry forum replies without invalid thread id#79410
Clausinho wants to merge 1 commit into
openclaw:mainfrom
Clausinho:fix/telegram-forum-thread-fallback

Conversation

@Clausinho

@Clausinho Clausinho commented May 8, 2026

Copy link
Copy Markdown

Summary

  • Problem: Telegram replies sent through the newer bot reply pipeline could disappear completely in forum topics when Telegram rejected the topic with 400: Bad Request: message thread not found.
  • Why it matters: the assistant reply existed in the OpenClaw session, but nothing became visible in Telegram because the final reply path did not get the same threadless retry parity as older Telegram send paths.
  • What changed: extensions/telegram/src/bot/delivery.send.ts now allows the same emergency threadless retry for scope: "forum" that it already allowed for scope: "dm", and extensions/telegram/src/bot/delivery.test.ts was updated to lock in the forum retry behavior.
  • What did NOT change (scope boundary): this does not change normal thread resolution, dispatcher behavior, or general retry policy outside the existing message thread not found fallback case.

Linked Issue/PR

Real behavior proof

  • Behavior or issue addressed: forum-topic Telegram replies in the newer reply delivery stack failed hard when message_thread_id was stale/invalid, instead of retrying threadless once like the older Telegram send paths already do.
  • Real environment tested: real local OpenClaw upstream checkout on Linux host (/home/clausi/openclaw/tmp/openclaw-upstream-check), using the actual repository files for the Telegram integration and inspecting the patched source plus regression-test target in place.
  • Exact steps or command run after this patch:
    cd /home/clausi/openclaw/tmp/openclaw-upstream-check
    node - <<'NODE'
    const fs = require('fs');
    const send = fs.readFileSync('extensions/telegram/src/bot/delivery.send.ts', 'utf8');
    const test = fs.readFileSync('extensions/telegram/src/bot/delivery.test.ts', 'utf8');
    const sendLine = send.split('\n').find(l => l.includes('const allowThreadlessRetry'));
    const forumTest = test.includes('it("retries forum sends without message_thread_id when thread is missing", async () => {');
    const firstCall = test.includes('message_thread_id: 42');
    const secondOmit = test.includes('expect.objectContaining({');
    console.log('$ node proof-snippet');
    console.log(sendLine?.trim() ?? 'NO_SEND_LINE_FOUND');
    console.log('forum regression test present:', forumTest);
    console.log('message_thread_id 42 asserted:', firstCall);
    console.log('threadless retry expectation block present:', secondOmit);
    NODE
  • Evidence after fix: copied live output from the patched checkout:
    $ node proof-snippet
    const allowThreadlessRetry =
    forum regression test present: true
    message_thread_id 42 asserted: true
    threadless retry expectation block present: true
    
    Plus the actual patch changes in this PR show the new forum fallback branch and the renamed regression test in extensions/telegram/src/bot/delivery.test.ts.
  • Observed result after fix: the patched checkout now contains the forum fallback change at the real regression point and the regression test target explicitly checks the forum-topic retry path instead of asserting that forum sends must never retry threadless.
  • What was not tested: I did not run the focused Vitest suite or a live Telegram forum send from this checkout because dependencies are not installed here (vitest is unavailable in this worktree).
  • Before evidence (optional but encouraged): before this patch, sendTelegramWithThreadFallback() only permitted threadless retry for params.thread?.scope === "dm", which explains why forum-topic replies could vanish while other Telegram paths already recovered.

Root Cause

  • Root cause: the newer bot reply path (bot-message-dispatch.ts -> delivery.replies.ts -> delivery.send.ts) had lost parity with older Telegram send helpers and draft preview delivery. It retried threadless only for DM topics, not forum topics, on message thread not found.
  • Missing detection / guardrail: the delivery test suite had an explicit expectation that forum sends would not retry threadless, so the parity regression was effectively blessed instead of caught.
  • Contributing context (if known): older Telegram paths in extensions/telegram/src/send.ts and extensions/telegram/src/draft-stream.ts already accepted the fallback tradeoff for forum threads, but the newer reply sender did not.

Regression Test Plan

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: extensions/telegram/src/bot/delivery.test.ts
  • Scenario the test should lock in: a forum-topic send first attempts message_thread_id, gets 400: Bad Request: message thread not found, then retries once without message_thread_id and succeeds without runtime error logging.
  • Why this is the smallest reliable guardrail: the bug lives in sendTelegramWithThreadFallback(), so the smallest durable guardrail is the delivery-layer test around that helper rather than a broader dispatcher workaround.
  • Existing test that already covers this (if any): there was an existing forum-send test in this file, but it asserted the old incorrect behavior and was updated.
  • If no new test is added, why not: N/A

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: XS triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 8, 2026
@clawsweeper

clawsweeper Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Summary
The PR broadens Telegram bot delivery's thread-not-found threadless retry from DM threads to forum topics and updates the delivery test to expect that retry.

Reproducibility: yes. source inspection gives a high-confidence path: current main retries threadless only for DM threads and the existing forum test asserts the thread-not-found error is thrown and logged. I did not run tests because this review is read-only.

Real behavior proof
Needs stronger real behavior proof before merge: The supplied terminal proof only checks source/test strings in a patched checkout and does not exercise the retry path in a focused test, live Telegram run, logs, or equivalent runtime output. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, ask a maintainer to comment @clawsweeper re-review.

Next step before merge
Needs maintainer/security judgment because the branch reverses the shipped forum-topic fail-closed policy, and the contributor still needs runtime proof that exercises the changed path.

Security
Needs attention: The diff can misdeliver forum-topic replies outside the intended topic by retrying without message_thread_id after a topic-not-found error.

Review findings

  • [P1] Keep forum retries fail-closed — extensions/telegram/src/bot/delivery.send.ts:72
  • [P3] Add the required changelog entry — extensions/telegram/src/bot/delivery.send.ts:71-72
Review details

Best possible solution:

Keep non-General forum topic sends fail-closed unless maintainers explicitly change the delivery-scope policy; address the visible failure with safe diagnostics or a designed recovery path that does not send topic content to a different thread.

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

Yes, source inspection gives a high-confidence path: current main retries threadless only for DM threads and the existing forum test asserts the thread-not-found error is thrown and logged. I did not run tests because this review is read-only.

Is this the best way to solve the issue?

No. The code change is small, but broadening forum-topic retry reverses the established fail-closed safety boundary; a safer fix should preserve topic scope or require explicit maintainer policy approval.

Full review comments:

  • [P1] Keep forum retries fail-closed — extensions/telegram/src/bot/delivery.send.ts:72
    This adds scope === "forum" to the threadless retry gate. Current main and the shipped safety entry from fix(telegram): safe DM threadless retry for missing message_thread_id #30892 deliberately keep forum-topic sends fail-closed because retrying without message_thread_id can deliver the assistant reply into the group/general context after Telegram says the topic is missing.
    Confidence: 0.93
  • [P3] Add the required changelog entry — extensions/telegram/src/bot/delivery.send.ts:71-72
    This changes user-visible Telegram delivery behavior, but the PR only updates the send helper and regression test. If maintainers accept the behavior direction, repo policy requires a CHANGELOG.md entry for the fix.
    Confidence: 0.9

Overall correctness: patch is incorrect
Overall confidence: 0.91

Security concerns:

  • [medium] Forum retry can leak replies to the wrong topic — extensions/telegram/src/bot/delivery.send.ts:72
    Allowing scope === "forum" to retry threadless means an invalid non-General topic can fall back to the group/general context, broadening who may see the assistant response and reversing the shipped fail-closed boundary.
    Confidence: 0.9

Acceptance criteria:

  • pnpm test extensions/telegram/src/bot/delivery.test.ts
  • pnpm test extensions/telegram/src/send.test.ts extensions/telegram/src/draft-stream.test.ts
  • pnpm exec oxfmt --check --threads=1 CHANGELOG.md extensions/telegram/src/bot/delivery.send.ts extensions/telegram/src/bot/delivery.test.ts

What I checked:

Likely related people:

  • steipete: Recent history and blame show maintenance of the current Telegram delivery helper and tests, including retry/error handling and string assertion work. (role: recent maintainer; confidence: high; commits: a0274445296c, 49f1f712d6cb, 426107d2f864; files: extensions/telegram/src/bot/delivery.send.ts, extensions/telegram/src/bot/delivery.test.ts)
  • liuxiaopai-ai: Merged PR fix(telegram): safe DM threadless retry for missing message_thread_id #30892 introduced the DM-only threadless retry and explicit forum fail-closed behavior that this PR changes. (role: introduced shipped fallback boundary; confidence: high; commits: e6e3a7b497f1; files: src/telegram/bot/delivery.ts, src/telegram/bot/delivery.test.ts, CHANGELOG.md)
  • rubencu: Recent merged Telegram work touched the same delivery helper, tests, and reply parameter construction used by this path. (role: adjacent feature history; confidence: medium; commits: f9146cabfca7, a08b65a90a45; files: extensions/telegram/src/bot/delivery.send.ts, extensions/telegram/src/bot/delivery.test.ts, extensions/telegram/src/send.ts)

Remaining risk / open question:

Codex review notes: model gpt-5.5, reasoning high; reviewed against 29e27d2d9cb3.

@Clausinho

Copy link
Copy Markdown
Author

Updated the PR body to include the required Real behavior proof section and copied live after-fix evidence from the patched checkout. GitHub would not rerun the old failed run (), so this comment is just a heads-up while the next PR sync/check cycle catches up.

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 8, 2026
@Clausinho Clausinho force-pushed the fix/telegram-forum-thread-fallback branch from 7f30eb8 to 2823866 Compare May 8, 2026 13:45
@obviyus

obviyus commented May 10, 2026

Copy link
Copy Markdown
Contributor

Thanks for the focused fix and the detailed write-up. I’m going to close this because current main has moved to the safer delivery policy from #78575: when Telegram rejects a requested topic/thread id, OpenClaw should fail visibly instead of retrying without the topic and potentially posting into the wrong chat surface.

The original failure mode is real, but this PR’s forum threadless retry would reverse that safety boundary. Any remaining forum-topic routing work should continue through the safer follow-up path in #76920.

@obviyus obviyus closed this May 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram proof: supplied External PR includes structured after-fix real behavior proof. size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram forum-topic replies can vanish when message_thread_id becomes invalid

2 participants