Repository navigation
fix(telegram): first DM message lands in root chat when the client creates the topic separately - #169444
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: needs maintainer review before merge. What this changesThis PR associates a threadless first private message with its sender’s newly created Telegram topic and preserves that route through replay. Example: User 1001 creates topic 500, then sends message 501 without message_thread_id in the same second.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR repairs a current Telegram routing bug with no blocking code findings; the failed QA check still needs attribution before landing. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherTelegram polling and webhook updates enter the account ingress monitor, which persists their conversation lane before dispatching them through authorization, session routing, and Telegram delivery. flowchart LR
A[Telegram updates] --> B[Account ingress monitor]
B --> C[Durable spool and topic fact]
C --> D[Thread resolver]
D --> E[Topic authorization]
E --> F[Agent session]
F --> G[Telegram topic reply]
Technical reviewBest possible solution: Keep one account-owned adoption decision in ingress and carry its recorded topic through the existing spool, resolver, authorization, and delivery owners. Do we have a high-confidence way to reproduce the issue? The supplied topic-creation update followed by a threadless message deterministically selects the root DM on current main, and the submitted live before/after run demonstrates the same failure through Telegram; this review ran no target code. Is this the best way to solve the issue? The repair uses the correct ingress owner, retains existing authorization and transport policy, and persists the association needed for replay rather than re-deriving it downstream. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 32527d0af043. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +208, Tests +597, Docs +2, Other +2. Total +809 across 11 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: No label 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 (12 earlier review cycles; latest 8 shown)
Reviewed November 13, 2026, 5:32 AM ET / 10:32 UTC (Revision 13). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
acc470d to
c7bdd28
Compare
…s the topic separately Some Telegram clients in threaded mode send a forum_topic_created service message carrying the new message_thread_id and then deliver the user's first message without any thread id. The resolver treated that message as a root DM, so the reply went to the main chat and the new topic stayed empty. Adopt a root message from the same user into the topic they created within the last 3 seconds; bot-created topics and groups are untouched.
- drop the redundant boolean literal compare flagged by oxlint - type the forum flag in the group-chat test fixture as the literal true
…nd persist it for replay The first version kept the pending/adopted maps in module state shared by every bot account of the process and re-derived the decision on every resolver call, so a topic observed by one account could admit another account's root message, the decision was lost on durable replay after a restart (lane telegram:<chat> no longer matched the stored topic lane and claim inspection rejected the row), and re-inspecting the consumed forum_topic_created update rearmed the adoption window. Decide once in the receiving account's ingress monitor at admission, record the adopted thread on the message and in the spool payload (adoptedDmThreadId), and restore it before lane inspection on replay. The resolver only reads that fact.
… dm topic adopt - document the two type assertions on spooled updates with SAFETY invariants - return a frame outcome from every path of the restart-replay test dispatch
|
Upgrade proof for the remaining compatibility item from the review of Upgrade from latest stable v2026.11.1 (npm) to this head (2026-11-05)Release side: the official npm package Settings, sessions and pending rows written by v2026.11.1
Neither row carries Upgrade
Run note (stand model, not the head): the stand answers with a local LM Studio model on a desktop GPU that was busy with another application during this run, so prompt processing ran at ~20 tokens/s. The first candidate start after the doctor (attempt 1) drained both rows the same way (rows Raw material (release and candidate debug logs, console log, both doctor outputs, spool dumps before/after, config before/after, per-key |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Co-authored-by: obviyus <[email protected]>
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
* fix(ci): keep unused dependency exports module-private The check-dependencies job reported six unused exports. Keep the five unclaimed implementation details private without changing their behavior; PR #198306 by vincentkoc covers the separate release waiver table, which remains untouched here. QA_UX_STREAM_END_MARKER and TELEPORT_PT were introduced by #198293. adoptTelegramDmTopicMessage and TELEGRAM_DM_TOPIC_ADOPT_WINDOW_SEC came from #169444; migrate their direct tests to adoptTelegramDmTopicUpdate and retain the explicit three-second accepted/four-second rejected window. ChatModelRuntimeControl came from #192137 and keeps its local renderer. Pinned formatting passes and independent P0-P2 review is clean. Named tests could not collect without runtime dependencies; scoped lint could not start with a wrapper import outside the requested sparse checkout. Co-authored-by: obviyus <[email protected]> Co-authored-by: steipete <[email protected]> * fix(ci): unused exports fail the dependency check Worked on by: - @obviyus - @steipete Co-authored-by: obviyus <[email protected]> Co-authored-by: steipete <[email protected]> OpenClaw-Publication: 3bcacc77-7216-8f2e-9e43-4c1cf827724f --------- Co-authored-by: obviyus <[email protected]> Co-authored-by: steipete <[email protected]>
…eates the topic separately (openclaw#169444) * fix(telegram): first DM message lands in root chat when client creates the topic separately Some Telegram clients in threaded mode send a forum_topic_created service message carrying the new message_thread_id and then deliver the user's first message without any thread id. The resolver treated that message as a root DM, so the reply went to the main chat and the new topic stayed empty. Adopt a root message from the same user into the topic they created within the last 3 seconds; bot-created topics and groups are untouched. * fix(telegram): satisfy lint and test typing in dm topic adopt - drop the redundant boolean literal compare flagged by oxlint - type the forum flag in the group-chat test fixture as the literal true * fix(telegram): own DM topic adoption in the account ingress monitor and persist it for replay The first version kept the pending/adopted maps in module state shared by every bot account of the process and re-derived the decision on every resolver call, so a topic observed by one account could admit another account's root message, the decision was lost on durable replay after a restart (lane telegram:<chat> no longer matched the stored topic lane and claim inspection rejected the row), and re-inspecting the consumed forum_topic_created update rearmed the adoption window. Decide once in the receiving account's ingress monitor at admission, record the adopted thread on the message and in the spool payload (adoptedDmThreadId), and restore it before lane inspection on replay. The resolver only reads that fact. * fix(telegram): satisfy assertion-safety and consistent-return lint in dm topic adopt - document the two type assertions on spooled updates with SAFETY invariants - return a frame outcome from every path of the restart-replay test dispatch * test(telegram): narrow per-account record keys in DM topic adoption test check-test-types failed with TS2532 under noUncheckedIndexedAccess because the per-account `lanes`/`resolved` records were typed with `string` keys. * fix(telegram): carry the adopted DM topic through inbound message normalization withResolvedTelegramForumFlag spreads a private message without chat.is_forum into a copy before authorization, so a WeakMap keyed by the admitted message object lost the adopted topic and the root message still routed to the root session (or was dropped under requireTopic). Record the decision on the message under a module-private symbol: spread copies keep it, JSON and structuredClone drop it, and durable rows keep carrying it as explicit payload metadata. Regressions run the two-update flow through the real account ingress monitor and inbound handler (topic session and reply thread, requireTopic admit/drop), cover legacy spool rows without adoptedDmThreadId, and pin the normalization and serialization behaviour at the resolver boundary. * test(telegram): pass the payload label to requireRecord in DM topic adoption test * fix(telegram): keep the adopted DM topic for redelivery after a failed durable append Admission consumed the pending topic before the spool append succeeded, so when every append attempt failed and Telegram redelivered the root message as a freshly parsed object, the retry no longer matched a pending topic and routed to the root session (or was dropped under requireTopic). Record each decision per account by chat:message_id as well, so the redelivered copy joins the same topic; the per-account map is bounded like the others. The ingress regression admits the service message, fails every append for the root message, re-admits it as a new object and verifies the topic lane, the persisted adoptedDmThreadId and the resolved thread. The helper-level per-account case was dropped in favour of the two-account ingress test. * fix(telegram): retire the service message once a native topic message clears adoption When the client delivers the first message inside the topic, the pending adoption was cleared but the service message stayed unspent, so a redelivered forum_topic_created update rearmed the window and a later root message within three seconds was adopted. Mark the cleared service message consumed through the existing bounded map. The restart replay regression now waits on owned signals (a dispatch-entered promise and the owner's abort event) instead of polling, and releases its gate and stops the monitor in finally. Helper-level cases duplicated by the ingress and inbound-handler regressions were removed. * test(telegram): adapt DM topic adoption ingress tests to the shared fixture and idle-claim admission The ingress drain test file now hands withTempState a fixture object, and a single durable admission on an idle drain appends through enqueueAndClaim. The adoption tests take stateDir from the fixture and the append-failure regression fails both append paths; scenarios and assertions are unchanged. * test(telegram): move DM topic adoption inbound tests out of the sticker test The rebase onto main placed the adoption describe block inside the sticker regression after upstream dropped the file's outer describe, so the group never registered. Declare it at file level and import describe again. * test(telegram): allocate test lines for DM topic adoption coverage --------- Co-authored-by: obviyus <[email protected]>
* fix(ci): keep unused dependency exports module-private The check-dependencies job reported six unused exports. Keep the five unclaimed implementation details private without changing their behavior; PR openclaw#198306 by vincentkoc covers the separate release waiver table, which remains untouched here. QA_UX_STREAM_END_MARKER and TELEPORT_PT were introduced by openclaw#198293. adoptTelegramDmTopicMessage and TELEGRAM_DM_TOPIC_ADOPT_WINDOW_SEC came from openclaw#169444; migrate their direct tests to adoptTelegramDmTopicUpdate and retain the explicit three-second accepted/four-second rejected window. ChatModelRuntimeControl came from openclaw#192137 and keeps its local renderer. Pinned formatting passes and independent P0-P2 review is clean. Named tests could not collect without runtime dependencies; scoped lint could not start with a wrapper import outside the requested sparse checkout. Co-authored-by: obviyus <[email protected]> Co-authored-by: steipete <[email protected]> * fix(ci): unused exports fail the dependency check Worked on by: - @obviyus - @steipete Co-authored-by: obviyus <[email protected]> Co-authored-by: steipete <[email protected]> OpenClaw-Publication: 3bcacc77-7216-8f2e-9e43-4c1cf827724f --------- Co-authored-by: obviyus <[email protected]> Co-authored-by: steipete <[email protected]>
Closes #169443
What Problem This Solves
Fixes: the first message of a new private bot topic is answered in the main chat, and the new topic stays empty, when the Telegram client creates the topic and sends the message as two separate updates.
User Impact
User impact: a new private topic started from such a client (Telegram for Android, for example) gets its first reply, typing indicator, session and auto label inside that topic. Later messages sent to the main chat still stay in the main chat.
Why This Change Was Made
The bot receives
forum_topic_createdfor the new topic, then the user's first message withoutmessage_thread_id. Nothing linked the two, so the message ran in the main DM session.The receiving account's ingress monitor now links them once, at admission: a threadless private message from the same user, with a larger message id, within 3 seconds of a topic that user created, joins that topic. The decision is stored on the spooled update (
adoptedDmThreadId), so the lane, authorization, session, delivery and restart replay all read the same topic. Bot-created topics, groups and channel direct-message topics are unchanged. Old spool rows without the field replay unchanged.Accepted edge case: if Telegram itself drops the new topic (as during the 2026-11-09 Bot API incident), the reply fails loudly with "message thread not found" instead of silently landing in the main chat. That matches the existing rule not to retry topic sends without topic metadata.
Evidence
createForumTopic, then ~200 ms later sendsPING:adoptto the main chat (the exact two-update shape from [Bug]: Telegram threaded mode: first DM message lands in root chat when the client creates the topic separately #169443).mainat8ebe740925ca: replyPONG:adoptarrived in the main chat; sessionagent:main:main. The new topic stayed empty.cb3709c0e1f3: replyPONG:adoptarrived in the new topic (topicId=199227); model request sessionagent:main:main:thread:<user>:199227. Controls in the same run: a later main-chat messagePING:rootlaterwas answered in the main chat (sessionagent:main:main), andPING:infreshsent inside the new topic was answered in that topic.dm-topic-adopt,thread-spec,telegram-ingress-drain(admission, account isolation, failed-append redelivery, restart replay, legacy rows) and the native-pipeline inbound-handler cases. The restart-replay case fails without the durable restore.main(conflicts with the widget-tap topic preparation from fix(telegram): route widgets in private topics #198022 resolved by keeping both payload fields).requireTopicisolation, disabled-topic replay, upgrade from2026.11.1) remains in the PR history.