fix(telegram): preserve forum topic routing#76920
Conversation
|
Codex review: needs maintainer review before merge. Reviewed May 27, 2026, 7:39 PM ET / 23:39 UTC. Summary PR surface: Source +216, Tests +97. Total +313 across 8 files. Reproducibility: yes. Source inspection and the PR's base-fails/head-passes test proof identify the threadless-fallback boundary, and the live Telegram proof exercises invalid and valid forum-topic sends on the PR head. Review metrics: 2 noteworthy metrics.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Mantis proof suggestion Risk before merge
Maintainer options:
Next step before merge Security Review detailsBest possible solution: Land the focused routing fix after maintainer acceptance of the fail-closed compatibility behavior and automatic-notice route preservation semantics. Do we have a high-confidence way to reproduce the issue? Yes. Source inspection and the PR's base-fails/head-passes test proof identify the threadless-fallback boundary, and the live Telegram proof exercises invalid and valid forum-topic sends on the PR head. Is this the best way to solve the issue? Yes, pending maintainer acceptance. Centralizing the fallback predicate in Telegram send/draft paths and seeding explicit cron delivery context is a maintainable fix for the observed routing bug, with the main tradeoff being intentional fail-closed compatibility behavior. AGENTS.md: found and applied where relevant. Codex review notes: model gpt-5.5, reasoning high; reviewed against da279041aba2. Label changesLabel justifications:
Evidence reviewedPR surface: Source +216, Tests +97. Total +313 across 8 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
|
Follow-up pushed in Addressed the prior review items:
Verification run locally:
|
This comment was marked as low quality.
This comment was marked as low quality.
d40225f to
54b7b0d
Compare
|
Rebased and refreshed this PR on current Current head: Updates in this refresh:
Local verification:
GitHub check status after push: mergeable, 88 checks passing, 20 skipped, 0 pending. The only failed check is still |
Test-based reproduction proofThis is automated reproduction evidence for the threadless-fallback boundary in this PR. It is not a live Telegram forum smoke, so it should not be treated as replacing the remaining Base reproduces the bug boundaryBase: I added a temporary failing regression test to a clean base worktree: pnpm test extensions/telegram/src/draft-stream.test.ts -- -t "reproduction: does not retry forum message preview sends without thread when thread is not found"Result: failed as expected. Base retries a forum/topic preview send without Key failure: That proves the pre-fix behavior still has a threadless retry path for explicit forum sends. PR head passes the fixed behaviorHead: The same behavior is covered by the committed PR test: pnpm test extensions/telegram/src/draft-stream.test.ts -- -t "does not retry forum message preview sends without thread when thread is not found"Result: So the current PR head proves base-fails/head-passes for the explicit forum send retry case: when a forum/topic send has a Residual: I still have not run a live Telegram forum bot smoke against this PR head. The local tests prove the fallback bug boundary; they do not prove end-to-end production Telegram delivery into a real forum topic. |
7fe0c05 to
bee6adf
Compare
|
@clawsweeper re-review Rebased this branch onto current
Local checks run after the update: I could not run local OpenGrep because |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Added live Telegram Bot API proof to the PR body and linked a public redacted transcript: https://gist.github.com/kesslerio/ed41189511d354a6e4fbe4470ec73bc8 What the proof exercises on PR branch head
The proof uses the branch's The remaining live limitation is cron/heartbeat full-gateway proof. Existing focused tests still cover cron delivery context and heartbeat route reconstruction, while this live proof covers the transport-sensitive send fallback behavior that was blocking the PR. @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Live Telegram forum-topic proof, head
|
|
@clawsweeper re-review |
|
🦞👀 Command router queued. I will update this comment with the next step. Re-review progress:
|
|
Heads up: this PR needs to be updated against current |
Summary
message_thread_id=1), while failing closed for explicit non-General forum topic sends and direct/private topic sends.Change Type
Scope
Telegram extension outbound delivery, shared heartbeat target resolution, isolated cron session delivery metadata, and one test-only
memory-coremock compatibility update for the current subagent runtime contract.Linked Issue / PR
message_thread_idon outbound Telegram forum sends and was closed as duplicate/superseded by the same topic-routing work.message_thread_idpass-through now present onmain; this PR keeps the broader fail-closed and async-route preservation behavior.Root Cause
The Telegram sender retried
400: message thread not foundby removingmessage_thread_idtoo broadly. That is safe only for General-topic recovery, but unsafe for explicit non-General forum topics and direct/private topic sends because Telegram can then deliver into the wrong root context.A separate async path could reconstruct heartbeat/completion delivery from incomplete session metadata. Topic-scoped Telegram sessions and explicit cron announce jobs could lose the thread id before later automatic notices were sent.
Regression Test Plan
telegram:group:<id>:topic:<thread>fail closed.deliveryContextororigin.chatTypecarries the topic context.Real behavior proof
Behavior or issue addressed: Telegram topic sends must not silently retry without
message_thread_idafter Telegram reportsmessage thread not found; async heartbeat/completion delivery must preserve the intended topic route instead of falling back to a group/default route.Real environment tested: Disposable OpenClaw staging gateway on NixOS Linux, PR worktree
/tmp/openclaw-pr76920-merge, headf515e5d36ac1166b955838c21489390dbfd9dbe2, using@kesslerClawBotin a real Telegram forum group (-1003908474243). The staging gateway was started from this PR head, and the proof script used the PR's built Telegram runtime,sendMessageTelegramfromdist/extensions/telegram/runtime-api.js.Exact steps or command run after this patch: Started the disposable gateway with
OPENCLAW_CONFIG_PATH=/home/art/.local/state/openclaw-staging/disposable/openclaw.jsonandOPENCLAW_STATE_DIR=/home/art/.local/state/openclaw-staging/disposable/state, then ran a redacted proof script from/tmp/openclaw-pr76920-mergethat exercised: root chat-scoped send to-1003908474243, explicit General topic-1003908474243:topic:1, invalid explicit non-General topic-1003908474243:topic:999999, and valid explicit non-General topic-1003908474243:topic:16.Evidence after fix (screenshot, recording, terminal capture, console output, redacted runtime log, linked artifact, or copied live output): Copied live output from the staging gateway/proof run. Full PR comment: fix(telegram): preserve forum topic routing #76920 (comment)
Key copied output:
Observed result after fix: Root chat-scoped send succeeded without a topic/thread id; General topic delivery succeeded and remained chat-scoped; an invalid explicit non-General forum topic failed closed and did not retry threadless; a valid explicit non-General forum topic sent with
threadId=16, proving delivery stayed in the requested forum topic.What was not tested: I did not run a full live cron or heartbeat follow-up through the gateway in this proof pass. Existing focused tests still cover cron session delivery context and heartbeat topic-route reconstruction.
Proof limitations or environment constraints: The live proof covers the real Telegram transport and topic send path. Cron/heartbeat route reconstruction remains covered by focused regression tests rather than a scheduled end-to-end cron/heartbeat run.
Before evidence (optional but encouraged): ClawSweeper's current-main/source review for this PR identifies the pre-patch failure mode: explicit Telegram topic sends could retry threadless after
message thread not found, and async follow-up routing could lose topic context. The after-fix proof above shows the explicit send path no longer retries threadless for an invalid non-General topic.Verification
Current head
75acdc52684b07c8355966394f5ad5347a713e0awas refreshed against latestorigin/main, trimmed back to the intended nine-file effective diff, and pushed after the commands above passed locally.Security Impact
Reduces cross-topic message leakage in Telegram forum groups and private/direct topic contexts by failing closed when an explicit thread is stale or invalid, and by preserving topic context for automatic follow-up notices.
Compatibility / Migration
No config migration. Non-General forum topic and direct/private topic sends now surface the Telegram error instead of silently retrying threadless. Explicit cron announce routes now persist the intended delivery context for later automatic notices.
Risks
If an operator intentionally relied on stale explicit topic sends falling back to a root chat, those sends now fail. That behavior was the leakage bug this PR is meant to prevent.
The cron/session change is intentionally limited to resolved explicit delivery targets; bare
delivery.mode: nonejobs still avoid implicit last-target resolution.AI Assistance
AI-assisted refresh, simplification, validation, and PR-body update.