-
-
Notifications
You must be signed in to change notification settings - Fork 80.7k
Telegram DMs duplicate recent conversation context despite persistent session transcript #87566
Copy link
Copy link
Closed
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.ClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Description
Metadata
Metadata
Assignees
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.ClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Type
Fields
Priority
None yet
Summary
Telegram direct messages inject a
Conversation context (untrusted, chronological, selected for current message)block into every inbound user turn. That block contains roughly the last 10 Telegram messages, even when the Telegram DM is routed into a persistent OpenClaw session that already includes the full prior transcript.This duplicates conversation history inside each new user message and significantly increases token usage.
Example
A Telegram DM user message is sent to the model with content like:
The prior messages in
Conversation contextare already present in the persistent session transcript, so the model receives duplicated history.Expected behavior
For a Telegram private DM that routes to an existing persistent session, OpenClaw should not inject a recent chat-window context block by default. The persistent session transcript should be the source of conversation history.
Recent chat-window context may still make sense for groups, topics, replies, fresh sessions, or non-persistent routing, but it should not be unconditionally added to normal 1:1 DMs.
Actual behavior
Telegram DMs include a supplemental
Conversation contextblock on every inbound message.Setting
channels.telegram.dmHistoryLimit: 0does not disable it, because this appears to be a separate code path from DM history seeding.Environment
2026.5.25-beta.1 (f5b52bd)directagent:main:mainSuspected code path
The block appears to be created in the Telegram provider:
In
buildPromptContextForMessage(...), Telegram calls:and wraps it as:
That supplemental context is then attached as:
Later it is mapped to
UntrustedStructuredContextand formatted into the prompt text byformatChatWindowStructuredContext(...).Why this matters
In long-lived DM sessions, every user turn already carries the session transcript. Adding the last ~10 Telegram messages into the new user message duplicates context and causes unnecessary token/cache-write/cache-read cost. In active Telegram sessions this can become very expensive.
Suggested fix
Do not build Telegram chat-window prompt context for private DMs when the target route is already a persistent session.
A minimal fix might be:
A more nuanced fix would only include this context when needed, such as:
It would also help to expose a config knob for this, separate from
dmHistoryLimit, sincedmHistoryLimit: 0currently does not disable this behavior.