Repository navigation
fix(telegram): stop resending earlier messages to the model on every turn in DM topics - #207684
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. |
|
Codex review: blocked before merge. What this changesSuppress supplemental history for existing Telegram DM topics whose earlier turns already arrive through their own session replay. Example: Send four messages in one private Telegram bot topic using a Claude CLI agent.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains This PR fixes a current-main Telegram context-duplication bug with no identified correctness defects; required CI awaits workflow approval. Reviewed head: Before merge
FindingsNone. Agent review detailsHow this fits togetherTelegram inbound routing selects a session, then context assembly combines the current message, native Telegram history, and supplemental transcript context for the agent. flowchart TD
A[Telegram topic message] --> B[Conversation routing]
B --> C[Target session]
C --> D[Telegram context selection]
E[Native message history] --> D
D --> F[Shared transcript preparation]
F --> G[Agent session replay and model request]
Technical reviewBest possible solution: Land the focused Telegram context-selection fix once required CI passes. Do we have a high-confidence way to reproduce the issue? Current-main source shows that an independent DM-topic session replays its turns while retaining both supplemental history paths; the contributor also supplies a live before/after reproduction, which this review did not rerun. Is this the best way to solve the issue? The patch fixes selection at its existing Telegram owner, shares routing facts, and preserves contextual exceptions without adding configuration, persistence, or a public API. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 3586700dbad1. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +25, Tests +28. Total +53 across 5 files. Added test files: 0. 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. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel 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 (1 earlier review cycle)
Reviewed November 28, 2026, 6:29 PM ET / 23:29 UTC (Revision 2). |
|
@clawsweeper re-review Added real-Telegram proof to the description: Telegram Test Server, upstream telegram-e2e-userbot runner with |
|
🦞👀 Re-review progress:
|
|
Maintainer proof for #207684 on head |
|
Maintainer override: the only red job on
|
|
Landed in 987f7b9. Thanks @stealthybear for the report, the live Telegram proof and the fix. In a Telegram DM topic that has its own session, each turn no longer re-sends the topic's earlier messages in the Conversation context block; session replay carries them once, as in plain DMs. A fresh topic's first turn, explicit replies and threads that share the DM session keep their context. |
…or baseline * commit '2f2edbf36836a8ddc6758dfdcce872d4414a3a92': (520 commits) chore(doctor): hold expired doctor migrations as removal-pending (#207865) fix: show ended one-time automations in History (#201280) chore(release): update appcast for 2026.11.11 (#207504) fix: let updates back up deeply nested databases (#207756) fix(telegram): stop resending earlier messages to the model on every turn in DM topics (#207684) feat(workboard): choose which sessions appear on a board (#207781) fix: acknowledge updates when the Gateway first becomes ready (#207819) chore: stop the cron recovery test from failing CI on slow runners (#207837) fix: queue follow-ups when session creation reuses an active chat (#207800) feat(clawrouter): consume qualified native memory embeddings (#191874) fix: save the account for main-session prompts and converted reminders (#207776) test(infra): measure worker Buffer storage directly (#207663) feat(workboard): hide sessions and filter subagents per board (#207744) chore(i18n): refresh native locales (#207796) fix: name safe recovery when agent schema markers disagree (#207705) improve(ui): show only setup warnings on skill pages (#203750) fix(gateway): keep Linux legacy lock recovery explicit (#207340) fix: deliver a saved child answer after a Gateway crash (#207706) fix(ui): fold background command wakes into chat activity (#207305) fix: restore the Feishu proxy transport tests (#207782) ...
…aseline * commit '2f2edbf36836a8ddc6758dfdcce872d4414a3a92': (520 commits) chore(doctor): hold expired doctor migrations as removal-pending (#207865) fix: show ended one-time automations in History (#201280) chore(release): update appcast for 2026.11.11 (#207504) fix: let updates back up deeply nested databases (#207756) fix(telegram): stop resending earlier messages to the model on every turn in DM topics (#207684) feat(workboard): choose which sessions appear on a board (#207781) fix: acknowledge updates when the Gateway first becomes ready (#207819) chore: stop the cron recovery test from failing CI on slow runners (#207837) fix: queue follow-ups when session creation reuses an active chat (#207800) feat(clawrouter): consume qualified native memory embeddings (#191874) fix: save the account for main-session prompts and converted reminders (#207776) test(infra): measure worker Buffer storage directly (#207663) feat(workboard): hide sessions and filter subagents per board (#207744) chore(i18n): refresh native locales (#207796) fix: name safe recovery when agent schema markers disagree (#207705) improve(ui): show only setup warnings on skill pages (#203750) fix(gateway): keep Linux legacy lock recovery explicit (#207340) fix: deliver a saved child answer after a Gateway crash (#207706) fix(ui): fold background command wakes into chat activity (#207305) fix: restore the Feishu proxy transport tests (#207782) ...
…aseline * commit '2f2edbf36836a8ddc6758dfdcce872d4414a3a92': (520 commits) chore(doctor): hold expired doctor migrations as removal-pending (#207865) fix: show ended one-time automations in History (#201280) chore(release): update appcast for 2026.11.11 (#207504) fix: let updates back up deeply nested databases (#207756) fix(telegram): stop resending earlier messages to the model on every turn in DM topics (#207684) feat(workboard): choose which sessions appear on a board (#207781) fix: acknowledge updates when the Gateway first becomes ready (#207819) chore: stop the cron recovery test from failing CI on slow runners (#207837) fix: queue follow-ups when session creation reuses an active chat (#207800) feat(clawrouter): consume qualified native memory embeddings (#191874) fix: save the account for main-session prompts and converted reminders (#207776) test(infra): measure worker Buffer storage directly (#207663) feat(workboard): hide sessions and filter subagents per board (#207744) chore(i18n): refresh native locales (#207796) fix: name safe recovery when agent schema markers disagree (#207705) improve(ui): show only setup warnings on skill pages (#203750) fix(gateway): keep Linux legacy lock recovery explicit (#207340) fix: deliver a saved child answer after a Gateway crash (#207706) fix(ui): fold background command wakes into chat activity (#207305) fix: restore the Feishu proxy transport tests (#207782) ...
…line * commit '652611b9d924c754ac7a18d0081cce6e1ec765df': (527 commits) refactor(infra): simplify audit recovery write progress (#157141) fix: show restart blockers in service logs (#207879) test(infra): exercise group identity in session roundtrip (#207671) test(infra): exercise live owner expiry policy (#207672) feat: let Knowledge learn from your Gmail through Composio (#207266) test: stop the history-worker overload test from failing CI on slow runners (#207862) test(auth): assert SecretRef plaintext is absent from storage (#207698) chore(doctor): hold expired doctor migrations as removal-pending (#207865) fix: show ended one-time automations in History (#201280) chore(release): update appcast for 2026.11.11 (#207504) fix: let updates back up deeply nested databases (#207756) fix(telegram): stop resending earlier messages to the model on every turn in DM topics (#207684) feat(workboard): choose which sessions appear on a board (#207781) fix: acknowledge updates when the Gateway first becomes ready (#207819) chore: stop the cron recovery test from failing CI on slow runners (#207837) fix: queue follow-ups when session creation reuses an active chat (#207800) feat(clawrouter): consume qualified native memory embeddings (#191874) fix: save the account for main-session prompts and converted reminders (#207776) test(infra): measure worker Buffer storage directly (#207663) feat(workboard): hide sessions and filter subagents per board (#207744) ...
…turn in DM topics (openclaw#207684) Root cause: `extensions/telegram/src/bot-message-context.session.ts:406` drops Telegram's native chat window for an existing private session only when `dmThreadId == null`, so a DM topic with its own session gets its earlier turns again in the "Conversation context" block on every turn, on top of session replay. Fixes openclaw#207657 Thanks @stealthybear for reporting this and for the fix. ## What Problem This Solves In a Telegram private chat where the bot has topics turned on, each topic has its own session. Every turn in such a topic sends the model the topic's earlier messages again in the "Conversation context" block, once as Telegram `#<message id>` rows and once as `#session:` transcript rows, although the session already replays those turns. The copies stay in history, so they pile up turn after turn. ## User Impact DM topics that route to their own session get the same per-turn context as plain DMs: earlier turns arrive once, through session replay. Fresh topics and explicit replies keep their context. A DM thread that shares the DM session (a bot without topics) or is bound to another session keeps the Telegram window it needs to tell its own messages apart. No config or migration. ## Why This Change Was Made openclaw#89855 drops Telegram's native window for plain DMs whose session replays the earlier turns, and left DM threads out. Neither openclaw#89855 nor openclaw#183190 gives a reason; the likely one (our inference) is that a DM thread can share its session with the rest of the DM, and then the window is what tells the thread's messages apart. That reason holds only when the thread has no session of its own. So the rule now keys on that property: `hasTelegramDmThreadSession` in `conversation-route.ts` decides whether a DM thread routes to its own session (no binding selects one, and the bot uses DM topic sessions). Session routing and the context builder both use it, so they can't disagree. Routing itself doesn't change: bindings already returned before that check. ## Evidence **Live, before and after:** real Telegram (Telegram Test Server, upstream's `telegram-e2e-userbot` runner at `2e58ed939a1` with `--dm --create-dm-topic`, a real test user and bot, and the real Claude CLI model): fresh gateways from each packed build. The user sends four messages ("Message i: remember the code word marker-i-live. Reply with only: noted-i") into a new DM topic. Both runs route to the topic's own session (`agent:main:main:thread:<user>:<topic>`), get all four replies in the topic, and end with `testDmTopic.cleanup.status: restored`. Measured: the "Conversation context" window the model receives each turn, from the Claude CLI transcript. | Turn | Released 2026.12.1-beta.1 | This PR | | --- | --- | --- | | 2 | 204 B, 2 Telegram rows | 0 B, no rows | | 3 | 368 B, 4 Telegram rows | 0 B, no rows | | 4 | 532 B, 6 Telegram rows: messages 2 and 3 and their replies, already in session replay | 0 B, no rows | <details><summary>Fourth turn, released build: the window the model got (timestamps cut)</summary> ``` Conversation context (chronological, selected for current message): ⟦openclaw:ctx⟧ #3 OpenClaw QA bot (you): Working #4 OpenClaw QA bot (you): noted-1 #5 A: Message 2: remember the code word marker-2-live. Reply with only: noted-2 openclaw#6 OpenClaw QA bot (you): noted-2 openclaw#7 A: Message 3: remember the code word marker-3-live. Reply with only: noted-3 openclaw#8 OpenClaw QA bot (you): noted-3 ``` With this PR the fourth turn has no window; the earlier turns reach the model once, through session replay. </details> **Controls, before and after:** stub Telegram Bot API and stub model, which also cover the plain DM and a shared reply thread. One script sends four messages ("Message i: remember the code word …") and measures the fourth request. | Fourth turn | Released 2026.12.1-beta.1 | This PR | | --- | --- | --- | | DM topic with its own session | context block 530 B: 2 Telegram + 3 transcript rows; message 2 sent 3 times, message 3 twice | 0 B, no rows; each message once | | Plain DM (control) | 0 B, each message once | unchanged | | Reply thread sharing the DM session, bot without topics (control) | 1,046 B: 3 Telegram + 7 transcript rows | unchanged, on purpose (below) |  Tested on 3a8bd09. Request proof: on every chat turn of the three fix runs, the user text sent to the model byte-equals the transcript (`ocfix proof sent`; the topic-label side request, which carries no chat turn, was left out). - Review: `autoreview` (Claude engine), `fad9fac5c23..3a8bd09`, P0-P2: clean, no findings. - Tests: three new cases in the existing table of `bot-message-context.prompt-context.test.ts` (99 s wall, `--maxWorkers=1`): an existing DM topic with its own session (fails on main, passes with the fix), a fresh DM topic, and a reply thread that shares the DM session. The DM-session, bot-threads, session-route and `bot.test.ts` suites pass. Typecheck and lint clean. **Maintainer re-run on `3a8bd0974c5`:** Telegram Test Server, repo `telegram-e2e-userbot` runner, `--dm --create-dm-topic`, mock provider, fresh Gateways built from main (`fad9fac5c23`, the merge base) and from this head, each side twice. Four messages into a new DM topic; all four replies arrive in the topic on every run, and every run ends with `testDmTopic.cleanup.status: restored` and Threaded Mode off. | Turn | main, run 1 | main, run 2 | this PR, run 1 | this PR, run 2 | | --- | --- | --- | --- | --- | | 2 | 84 B, 1 Telegram row | 84 B, 1 row | 0 B | 0 B | | 3 | 302 B, 3 rows | 302 B, 3 rows | 0 B | 0 B | | 4 | 520 B, 5 rows | 520 B, 5 rows | 0 B | 0 B | Stub Telegram Bot API controls, both builds: a fresh topic session's first turn keeps its window; an explicit reply to message 1 keeps the window and reply target; a plain DM stays at 0 B; a reply thread that shares the DM session (bot without topics) keeps its growing window. Proof lines: openclaw#207684 (comment) <details><summary>Not covered</summary> - A DM thread that shares the DM session or is bound still gets the native window plus merged `#session:` rows (the "shared reply thread" row above). That path is the one openclaw#89855 and openclaw#183190 kept on purpose; deduplicating it inside the merge is a separate change. - A topic that has its own session, is then bound to another session, then unbound: messages sent while it was bound are in neither the topic's replay nor its window after the unbind. Plain DMs have the same gap. It is rare and recoverable (reply to or quote the message), so this PR does not code for it. - Forum topics in groups are unchanged: group windows carry room messages that never became turns. </details> Co-authored-by: Ayaan Zaidi <[email protected]>
…turn in DM topics (#207684) Root cause: `extensions/telegram/src/bot-message-context.session.ts:406` drops Telegram's native chat window for an existing private session only when `dmThreadId == null`, so a DM topic with its own session gets its earlier turns again in the "Conversation context" block on every turn, on top of session replay. Fixes #207657 Thanks @stealthybear for reporting this and for the fix. ## What Problem This Solves In a Telegram private chat where the bot has topics turned on, each topic has its own session. Every turn in such a topic sends the model the topic's earlier messages again in the "Conversation context" block, once as Telegram `#<message id>` rows and once as `#session:` transcript rows, although the session already replays those turns. The copies stay in history, so they pile up turn after turn. ## User Impact DM topics that route to their own session get the same per-turn context as plain DMs: earlier turns arrive once, through session replay. Fresh topics and explicit replies keep their context. A DM thread that shares the DM session (a bot without topics) or is bound to another session keeps the Telegram window it needs to tell its own messages apart. No config or migration. ## Why This Change Was Made #89855 drops Telegram's native window for plain DMs whose session replays the earlier turns, and left DM threads out. Neither #89855 nor #183190 gives a reason; the likely one (our inference) is that a DM thread can share its session with the rest of the DM, and then the window is what tells the thread's messages apart. That reason holds only when the thread has no session of its own. So the rule now keys on that property: `hasTelegramDmThreadSession` in `conversation-route.ts` decides whether a DM thread routes to its own session (no binding selects one, and the bot uses DM topic sessions). Session routing and the context builder both use it, so they can't disagree. Routing itself doesn't change: bindings already returned before that check. ## Evidence **Live, before and after:** real Telegram (Telegram Test Server, upstream's `telegram-e2e-userbot` runner at `a1ced09cd7f` with `--dm --create-dm-topic`, a real test user and bot, and the real Claude CLI model): fresh gateways from each packed build. The user sends four messages ("Message i: remember the code word marker-i-live. Reply with only: noted-i") into a new DM topic. Both runs route to the topic's own session (`agent:main:main:thread:<user>:<topic>`), get all four replies in the topic, and end with `testDmTopic.cleanup.status: restored`. Measured: the "Conversation context" window the model receives each turn, from the Claude CLI transcript. | Turn | Released 2026.12.1-beta.1 | This PR | | --- | --- | --- | | 2 | 204 B, 2 Telegram rows | 0 B, no rows | | 3 | 368 B, 4 Telegram rows | 0 B, no rows | | 4 | 532 B, 6 Telegram rows: messages 2 and 3 and their replies, already in session replay | 0 B, no rows | <details><summary>Fourth turn, released build: the window the model got (timestamps cut)</summary> ``` Conversation context (chronological, selected for current message): ⟦openclaw:ctx⟧ #3 OpenClaw QA bot (you): Working #4 OpenClaw QA bot (you): noted-1 #5 A: Message 2: remember the code word marker-2-live. Reply with only: noted-2 #6 OpenClaw QA bot (you): noted-2 #7 A: Message 3: remember the code word marker-3-live. Reply with only: noted-3 #8 OpenClaw QA bot (you): noted-3 ``` With this PR the fourth turn has no window; the earlier turns reach the model once, through session replay. </details> **Controls, before and after:** stub Telegram Bot API and stub model, which also cover the plain DM and a shared reply thread. One script sends four messages ("Message i: remember the code word …") and measures the fourth request. | Fourth turn | Released 2026.12.1-beta.1 | This PR | | --- | --- | --- | | DM topic with its own session | context block 530 B: 2 Telegram + 3 transcript rows; message 2 sent 3 times, message 3 twice | 0 B, no rows; each message once | | Plain DM (control) | 0 B, each message once | unchanged | | Reply thread sharing the DM session, bot without topics (control) | 1,046 B: 3 Telegram + 7 transcript rows | unchanged, on purpose (below) |  Tested on 3a8bd09. Request proof: on every chat turn of the three fix runs, the user text sent to the model byte-equals the transcript (`ocfix proof sent`; the topic-label side request, which carries no chat turn, was left out). - Review: `autoreview` (Claude engine), `68e792edca4..3a8bd09`, P0-P2: clean, no findings. - Tests: three new cases in the existing table of `bot-message-context.prompt-context.test.ts` (99 s wall, `--maxWorkers=1`): an existing DM topic with its own session (fails on main, passes with the fix), a fresh DM topic, and a reply thread that shares the DM session. The DM-session, bot-threads, session-route and `bot.test.ts` suites pass. Typecheck and lint clean. **Maintainer re-run on `3a8bd0974c5`:** Telegram Test Server, repo `telegram-e2e-userbot` runner, `--dm --create-dm-topic`, mock provider, fresh Gateways built from main (`68e792edca4`, the merge base) and from this head, each side twice. Four messages into a new DM topic; all four replies arrive in the topic on every run, and every run ends with `testDmTopic.cleanup.status: restored` and Threaded Mode off. | Turn | main, run 1 | main, run 2 | this PR, run 1 | this PR, run 2 | | --- | --- | --- | --- | --- | | 2 | 84 B, 1 Telegram row | 84 B, 1 row | 0 B | 0 B | | 3 | 302 B, 3 rows | 302 B, 3 rows | 0 B | 0 B | | 4 | 520 B, 5 rows | 520 B, 5 rows | 0 B | 0 B | Stub Telegram Bot API controls, both builds: a fresh topic session's first turn keeps its window; an explicit reply to message 1 keeps the window and reply target; a plain DM stays at 0 B; a reply thread that shares the DM session (bot without topics) keeps its growing window. Proof lines: #207684 (comment) <details><summary>Not covered</summary> - A DM thread that shares the DM session or is bound still gets the native window plus merged `#session:` rows (the "shared reply thread" row above). That path is the one #89855 and #183190 kept on purpose; deduplicating it inside the merge is a separate change. - A topic that has its own session, is then bound to another session, then unbound: messages sent while it was bound are in neither the topic's replay nor its window after the unbind. Plain DMs have the same gap. It is rare and recoverable (reply to or quote the message), so this PR does not code for it. - Forum topics in groups are unchanged: group windows carry room messages that never became turns. </details> Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 987f7b9) Co-authored-by: RomneyDa <[email protected]>
…turn in DM topics (#207684) Root cause: `extensions/telegram/src/bot-message-context.session.ts:406` drops Telegram's native chat window for an existing private session only when `dmThreadId == null`, so a DM topic with its own session gets its earlier turns again in the "Conversation context" block on every turn, on top of session replay. Fixes #207657 Thanks @stealthybear for reporting this and for the fix. ## What Problem This Solves In a Telegram private chat where the bot has topics turned on, each topic has its own session. Every turn in such a topic sends the model the topic's earlier messages again in the "Conversation context" block, once as Telegram `#<message id>` rows and once as `#session:` transcript rows, although the session already replays those turns. The copies stay in history, so they pile up turn after turn. ## User Impact DM topics that route to their own session get the same per-turn context as plain DMs: earlier turns arrive once, through session replay. Fresh topics and explicit replies keep their context. A DM thread that shares the DM session (a bot without topics) or is bound to another session keeps the Telegram window it needs to tell its own messages apart. No config or migration. ## Why This Change Was Made #89855 drops Telegram's native window for plain DMs whose session replays the earlier turns, and left DM threads out. Neither #89855 nor #183190 gives a reason; the likely one (our inference) is that a DM thread can share its session with the rest of the DM, and then the window is what tells the thread's messages apart. That reason holds only when the thread has no session of its own. So the rule now keys on that property: `hasTelegramDmThreadSession` in `conversation-route.ts` decides whether a DM thread routes to its own session (no binding selects one, and the bot uses DM topic sessions). Session routing and the context builder both use it, so they can't disagree. Routing itself doesn't change: bindings already returned before that check. ## Evidence **Live, before and after:** real Telegram (Telegram Test Server, upstream's `telegram-e2e-userbot` runner at `a1ced09cd7f` with `--dm --create-dm-topic`, a real test user and bot, and the real Claude CLI model): fresh gateways from each packed build. The user sends four messages ("Message i: remember the code word marker-i-live. Reply with only: noted-i") into a new DM topic. Both runs route to the topic's own session (`agent:main:main:thread:<user>:<topic>`), get all four replies in the topic, and end with `testDmTopic.cleanup.status: restored`. Measured: the "Conversation context" window the model receives each turn, from the Claude CLI transcript. | Turn | Released 2026.12.1-beta.1 | This PR | | --- | --- | --- | | 2 | 204 B, 2 Telegram rows | 0 B, no rows | | 3 | 368 B, 4 Telegram rows | 0 B, no rows | | 4 | 532 B, 6 Telegram rows: messages 2 and 3 and their replies, already in session replay | 0 B, no rows | <details><summary>Fourth turn, released build: the window the model got (timestamps cut)</summary> ``` Conversation context (chronological, selected for current message): ⟦openclaw:ctx⟧ #3 OpenClaw QA bot (you): Working #4 OpenClaw QA bot (you): noted-1 #5 A: Message 2: remember the code word marker-2-live. Reply with only: noted-2 #6 OpenClaw QA bot (you): noted-2 #7 A: Message 3: remember the code word marker-3-live. Reply with only: noted-3 #8 OpenClaw QA bot (you): noted-3 ``` With this PR the fourth turn has no window; the earlier turns reach the model once, through session replay. </details> **Controls, before and after:** stub Telegram Bot API and stub model, which also cover the plain DM and a shared reply thread. One script sends four messages ("Message i: remember the code word …") and measures the fourth request. | Fourth turn | Released 2026.12.1-beta.1 | This PR | | --- | --- | --- | | DM topic with its own session | context block 530 B: 2 Telegram + 3 transcript rows; message 2 sent 3 times, message 3 twice | 0 B, no rows; each message once | | Plain DM (control) | 0 B, each message once | unchanged | | Reply thread sharing the DM session, bot without topics (control) | 1,046 B: 3 Telegram + 7 transcript rows | unchanged, on purpose (below) |  Tested on 3a8bd09. Request proof: on every chat turn of the three fix runs, the user text sent to the model byte-equals the transcript (`ocfix proof sent`; the topic-label side request, which carries no chat turn, was left out). - Review: `autoreview` (Claude engine), `68e792edca4..3a8bd09`, P0-P2: clean, no findings. - Tests: three new cases in the existing table of `bot-message-context.prompt-context.test.ts` (99 s wall, `--maxWorkers=1`): an existing DM topic with its own session (fails on main, passes with the fix), a fresh DM topic, and a reply thread that shares the DM session. The DM-session, bot-threads, session-route and `bot.test.ts` suites pass. Typecheck and lint clean. **Maintainer re-run on `3a8bd0974c5`:** Telegram Test Server, repo `telegram-e2e-userbot` runner, `--dm --create-dm-topic`, mock provider, fresh Gateways built from main (`68e792edca4`, the merge base) and from this head, each side twice. Four messages into a new DM topic; all four replies arrive in the topic on every run, and every run ends with `testDmTopic.cleanup.status: restored` and Threaded Mode off. | Turn | main, run 1 | main, run 2 | this PR, run 1 | this PR, run 2 | | --- | --- | --- | --- | --- | | 2 | 84 B, 1 Telegram row | 84 B, 1 row | 0 B | 0 B | | 3 | 302 B, 3 rows | 302 B, 3 rows | 0 B | 0 B | | 4 | 520 B, 5 rows | 520 B, 5 rows | 0 B | 0 B | Stub Telegram Bot API controls, both builds: a fresh topic session's first turn keeps its window; an explicit reply to message 1 keeps the window and reply target; a plain DM stays at 0 B; a reply thread that shares the DM session (bot without topics) keeps its growing window. Proof lines: #207684 (comment) <details><summary>Not covered</summary> - A DM thread that shares the DM session or is bound still gets the native window plus merged `#session:` rows (the "shared reply thread" row above). That path is the one #89855 and #183190 kept on purpose; deduplicating it inside the merge is a separate change. - A topic that has its own session, is then bound to another session, then unbound: messages sent while it was bound are in neither the topic's replay nor its window after the unbind. Plain DMs have the same gap. It is rare and recoverable (reply to or quote the message), so this PR does not code for it. - Forum topics in groups are unchanged: group windows carry room messages that never became turns. </details> Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 987f7b9) Companion audit: #190121 changes WhatsApp reactions, unrelated to Telegram own-session replay suppression. Co-authored-by: RomneyDa <[email protected]>
Root cause:
extensions/telegram/src/bot-message-context.session.ts:406drops Telegram's native chat window for an existing private session only whendmThreadId == null, so a DM topic with its own session gets its earlier turns again in the "Conversation context" block on every turn, on top of session replay.Fixes #207657
Thanks @stealthybear for reporting this and for the fix.
What Problem This Solves
In a Telegram private chat where the bot has topics turned on, each topic has its own session. Every turn in such a topic sends the model the topic's earlier messages again in the "Conversation context" block, once as Telegram
#<message id>rows and once as#session:transcript rows, although the session already replays those turns. The copies stay in history, so they pile up turn after turn.User Impact
DM topics that route to their own session get the same per-turn context as plain DMs: earlier turns arrive once, through session replay. Fresh topics and explicit replies keep their context. A DM thread that shares the DM session (a bot without topics) or is bound to another session keeps the Telegram window it needs to tell its own messages apart. No config or migration.
Why This Change Was Made
#89855 drops Telegram's native window for plain DMs whose session replays the earlier turns, and left DM threads out. Neither #89855 nor #183190 gives a reason; the likely one (our inference) is that a DM thread can share its session with the rest of the DM, and then the window is what tells the thread's messages apart. That reason holds only when the thread has no session of its own. So the rule now keys on that property:
hasTelegramDmThreadSessioninconversation-route.tsdecides whether a DM thread routes to its own session (no binding selects one, and the bot uses DM topic sessions). Session routing and the context builder both use it, so they can't disagree. Routing itself doesn't change: bindings already returned before that check.Evidence
Live, before and after: real Telegram (Telegram Test Server, upstream's
telegram-e2e-userbotrunner ata1ced09cd7fwith--dm --create-dm-topic, a real test user and bot, and the real Claude CLI model): fresh gateways from each packed build. The user sends four messages ("Message i: remember the code word marker-i-live. Reply with only: noted-i") into a new DM topic. Both runs route to the topic's own session (agent:main:main:thread:<user>:<topic>), get all four replies in the topic, and end withtestDmTopic.cleanup.status: restored. Measured: the "Conversation context" window the model receives each turn, from the Claude CLI transcript.Fourth turn, released build: the window the model got (timestamps cut)
With this PR the fourth turn has no window; the earlier turns reach the model once, through session replay.
Controls, before and after: stub Telegram Bot API and stub model, which also cover the plain DM and a shared reply thread. One script sends four messages ("Message i: remember the code word …") and measures the fourth request.
Tested on 3a8bd09. Request proof: on every chat turn of the three fix runs, the user text sent to the model byte-equals the transcript (
ocfix proof sent; the topic-label side request, which carries no chat turn, was left out).autoreview(Claude engine),68e792edca4..3a8bd0974c5, P0-P2: clean, no findings.bot-message-context.prompt-context.test.ts(99 s wall,--maxWorkers=1): an existing DM topic with its own session (fails on main, passes with the fix), a fresh DM topic, and a reply thread that shares the DM session. The DM-session, bot-threads, session-route andbot.test.tssuites pass. Typecheck and lint clean.Maintainer re-run on
3a8bd0974c5: Telegram Test Server, repotelegram-e2e-userbotrunner,--dm --create-dm-topic, mock provider, fresh Gateways built from main (68e792edca4, the merge base) and from this head, each side twice. Four messages into a new DM topic; all four replies arrive in the topic on every run, and every run ends withtestDmTopic.cleanup.status: restoredand Threaded Mode off.Stub Telegram Bot API controls, both builds: a fresh topic session's first turn keeps its window; an explicit reply to message 1 keeps the window and reply target; a plain DM stays at 0 B; a reply thread that shares the DM session (bot without topics) keeps its growing window. Proof lines: #207684 (comment)
Not covered
#session:rows (the "shared reply thread" row above). That path is the one fix(telegram): avoid duplicate dm chat window context #89855 and fix(telegram): suppress duplicate DM transcript windows while preserving delivery-only context #183190 kept on purpose; deduplicating it inside the merge is a separate change.