Skip to content

[Bug]: Telegram prompt context includes duplicate assistant entries from session transcript + channel cache #99117

Description

@mooresoftware

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

In Telegram direct chats, the same assistant reply appears twice in prompt context — once from the session transcript (with a synthetic #session:<id> id and [[reply_to_current]] directive tag) and once from the Telegram message cache — because the dedupe key uses exact timestamp_ms:body matching that fails when the two copies differ in tags and timestamps.

Steps to reproduce

  1. Use a Telegram direct chat with OpenClaw
  2. Send a message
  3. Have the assistant reply using [[reply_to_current]]
  4. Send another follow-up message
  5. Inspect the prompt context / conversation context block for the follow-up
  6. Observe both a #session:<id> assistant line containing the directive tag and a normal Telegram message id line with the same visible reply

Expected behavior

Only one normalized assistant message should appear in prompt context for a given delivered reply, matching how the session transcript path already excludes delivery-mirror rows.

Actual behavior

Conversation context included duplicate pairs such as:

  • #session:6325109d ... OpenClaw: [[reply_to_current]]Yep — I'm here now...
  • #736 ... OpenClaw: Yep — I'm here now...

and:

  • #session:697cdaed ... OpenClaw: [[reply_to_current]]Status looks good...
  • #740 ... OpenClaw: Status looks good...

The same assistant reply appears twice: once from session transcript history and once from Telegram-delivered history.

OpenClaw version

2026.6.11 (e085fa1)

Operating system

macOS 26.3.1 (Apple Silicon, arm64)

Install method

npm global install (npm i -g openclaw), gateway run as LaunchAgent

Model

openai/gpt-5.4

Provider / routing chain

Direct OpenAI API (api.openai.com/v1/responses), no proxy or router

Additional provider/model setup details

Single-agent setup, Telegram channel only. Node 25.8.0. Codex plugin disabled after it previously hijacked the runtime; current runtime is OpenClaw default with the OpenAI provider.

Logs

Screenshots, recordings, and evidence

Source analysis (bundled dist filenames from 2026.6.11; build hashes may differ, function names should be searchable):

  • dist/bot-CBwSxkGA.js: toSessionTranscriptPromptMessage(...) adds synthetic session:<id> ids; buildTelegramSessionTranscriptPromptMessages(...); merge of sessionPromptMessages + cachePromptMessages; resolvePromptContextTextDedupeKey(...) returns timestamp_ms:body
  • dist/transcript-CSsWGO8o.js: parseRecentConversationText(...) excludes transcript-only assistant models; readRecentUserAssistantTextForSession(...) — delivery-mirror rows are already filtered, so this is not delivery-mirror leakage

Impact and severity

  • Affected: Telegram direct-chat users whose assistant replies use directive tags like [[reply_to_current]]
  • Severity: annoying — adds prompt noise; may slightly distort follow-up reasoning
  • Frequency: consistent when the transcript copy contains a directive tag the delivered message lacks
  • Consequence: duplicated assistant context and synthetic #session:<id> ids visible in prompt context

Additional information

Suggested fixes: (1) normalize assistant transcript text before dedupe (strip directive tags, normalize whitespace); (2) dedupe on normalized visible text rather than exact timestamp_ms:body, or prefer cache entries over transcript entries when text is substantially identical; (3) avoid exposing transcript-only synthetic ids when a cache-backed equivalent exists.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.bugSomething isn't workingclawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, 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.no-staleExclude from stale automation

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions