fix(telegram): avoid duplicate dm chat window context#89855
Conversation
|
Codex review: needs maintainer review before merge. Reviewed June 21, 2026, 8:24 AM ET / 12:24 UTC. Summary PR surface: Source +17, Tests +78. Total +95 across 3 files. Reproducibility: yes. at source level. Current main builds recent Telegram Review metrics: none identified. Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land this narrow session-aware Telegram filter after maintainer and CI gates, or re-check it against #95390 if the broader direct-session recency change lands first. Do we have a high-confidence way to reproduce the issue? Yes, at source level. Current main builds recent Telegram Is this the best way to solve the issue? Yes. Filtering at Telegram inbound context assembly is the narrowest maintainable fix because that layer has the route session key, previous-session timestamp, DM-topic state, and visible reply/group context needed to avoid over-suppression. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 12c34fc3a951. Label changesLabel justifications:
Evidence reviewedPR surface: Source +17, Tests +78. Total +95 across 3 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
|
Co-authored-by: Cornna <[email protected]>
Co-authored-by: Cornna <[email protected]>
Co-authored-by: Cornna <[email protected]>
Co-authored-by: Cornna <[email protected]>
Summary
Telegram private DMs already route into a persistent OpenClaw session transcript, but the inbound prompt also injected the recent Telegram
chat_windowcontext on every plain DM turn. That duplicated prior messages inside each new user message and increased token usage for ongoing DM conversations.This patch filters Telegram
chat_windowprompt context only for existing unthreaded private DM sessions. Fresh DMs still receive the bootstrap chat window, and replies/topics/groups keep their contextual windows because those surfaces need explicit surrounding context.Fixes #87566.
Real behavior proof (required for external PRs)
openclaw/openclawmain, Node 22, running the current Telegram inbound message-context construction path from this branch.NO_COLOR=1 node --import tsx --input-type=module -from the repo root. The command built one existing private DM turn and one fresh private DM turn with the same Telegramchat_windowprompt-context entry, then counted thesource=telegram,type=chat_windowentries present in the emitted inbound context payload.Tests and validation
node scripts/run-vitest.mjs extensions/telegram/src/bot-message-context.prompt-context.test.ts --reporter=dot-> 1 file / 3 tests passed.node scripts/run-vitest.mjs extensions/telegram/src/bot-message-context.prompt-context.test.ts extensions/telegram/src/bot-message-context.dm-threads.test.ts --reporter=dot-> 2 files / 18 tests passed.node scripts/run-vitest.mjs extensions/telegram/src/bot.test.ts --reporter=dot -t "adds live chat and reply-target windows"-> 1 passed / 74 skipped.npx oxfmt --check extensions/telegram/src/bot-message-context.session.ts extensions/telegram/src/bot-message-context.test-harness.ts extensions/telegram/src/bot-message-context.prompt-context.test.ts-> clean.node scripts/run-oxlint.mjs extensions/telegram/src/bot-message-context.session.ts extensions/telegram/src/bot-message-context.test-harness.ts extensions/telegram/src/bot-message-context.prompt-context.test.ts-> exit 0.node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.extensions.test.json-> exit 0.git diff --check-> exit 0.Risk
The filter is deliberately narrow: it only removes
source: "telegram"+type: "chat_window"entries when the route is an existing unthreaded private DM without a visible reply target or reply chain. Group chats, topics, reply-context turns, and fresh DMs keep the existing context behavior.