Skip to content

fix(telegram): normalize directive tags in prompt context dedupe key#100571

Closed
tzy-17 wants to merge 1 commit into
openclaw:mainfrom
tzy-17:fix/99117-telegram-dedup-tags
Closed

fix(telegram): normalize directive tags in prompt context dedupe key#100571
tzy-17 wants to merge 1 commit into
openclaw:mainfrom
tzy-17:fix/99117-telegram-dedup-tags

Conversation

@tzy-17

@tzy-17 tzy-17 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes #99117: In Telegram direct chats, the same assistant reply appeared twice in prompt context — once from the session transcript (with [[reply_to_current]] directive tags and #session:<id> synthetic IDs) and once from the Telegram message cache (without tags). The dedupe key used exact timestamp_ms:body.trim() matching which failed because the two copies differed in both body and timestamp.

Why This Change Was Made

resolvePromptContextTextDedupeKey compared exact timestamp_ms:body, but:

  • Transcript copies have directive tags ([[reply_to_current]], [[reply_to:<id>]], [[audio_as_voice]]) prepended; cache copies don't
  • Timestamps differ between the two sources
  • #session:<id> synthetic IDs only appear in transcript copies

The fix normalizes the body by stripping directive tags and #session:<id> prefixes before computing the dedupe key, so transcript and cache copies of the same visible reply are recognized as duplicates.

User Impact

  • Telegram DM users no longer see duplicate assistant entries in prompt context
  • Removes prompt noise that could distort follow-up reasoning
  • Backward compatible: messages without directive tags dedupe identically to before

Evidence

  • Source analysis confirms resolvePromptContextTextDedupeKey at bot-handlers.runtime.ts:187 as the single dedupe point
  • pnpm test extensions/telegram/src/bot-handlers.runtime.test.ts — 4 tests pass
  • pnpm test extensions/telegram/src/bot-message-context.prompt-context.test.ts — 4 tests pass
  • pnpm test extensions/telegram/src/session-transcript-context.test.ts — 6 tests pass
  • oxlint passes on changed file

🤖 Generated with Claude Code

@clawsweeper

clawsweeper Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I did a careful shell check against current main, and this is already implemented.

Close: current main already fixes the central Telegram directive-tag duplicate prompt-context problem through the merged timestamp-preserving implementation in #100573, while this branch remains a broader body-only dedupe path that should not be a landing candidate.

Root-cause cluster
Relationship: superseded
Canonical: #100573
Summary: The current PR is an overlapping candidate for the Telegram duplicate assistant prompt-context bug, but the merged replacement PR is now the canonical current-main fix.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

So I’m closing this as already implemented rather than keeping a duplicate issue open.

Review details

Best possible solution:

Keep the merged timestamp-preserving directive-strip implementation from #100573 on current main and close this overlapping body-only branch.

Do we have a high-confidence way to reproduce the issue?

Yes. The linked issue gives concrete duplicate Telegram prompt-context rows, and current main now has a handler regression that exercises the directive-tag transcript row plus cache row path.

Is this the best way to solve the issue?

No. This branch is no longer the best fix because current main already landed a narrower implementation that normalizes directive tags while preserving timestamp alignment.

Security review:

Security review cleared: No concrete security or supply-chain concern found; the diff is limited to Telegram runtime code and adds no dependencies, workflows, permissions, credentials, downloads, or lifecycle hooks.

AGENTS.md: found and applied where relevant.

What I checked:

Likely related people:

  • momothemage: Authored the merged replacement PR that now fixes this exact Telegram directive-tag prompt-context issue on main and approved the ClawSweeper automerge path. (role: current main fix author / likely follow-up owner; confidence: high; commits: 5c4cc7245ef0, e0d23cfc5a26; files: extensions/telegram/src/bot-handlers.runtime.ts, extensions/telegram/src/bot-message-dispatch.ts, extensions/telegram/src/bot.test.ts)
  • mikasa0818: Authored the merged direct Telegram session-transcript prompt-context work that introduced the session/cache merge and dedupe surface involved here. (role: feature introducer; confidence: high; commits: ec7a548062d3; files: extensions/telegram/src/bot-handlers.runtime.ts, extensions/telegram/src/session-transcript-context.ts, extensions/telegram/src/bot.test.ts)
  • rabsef-bicrym: Authored the merged outbound prompt-context timestamp-alignment fix that the current-main directive-tag fix builds on. (role: adjacent fix author; confidence: high; commits: c8dba85b5d41; files: extensions/telegram/src/bot-message-dispatch.ts, extensions/telegram/src/message-cache.ts, extensions/telegram/src/outbound-message-context.ts)
  • obviyus: Merged the session-transcript context PR and has recent Telegram prompt-context/transcript-area commits. (role: recent area contributor and merger; confidence: medium; commits: ec7a548062d3, 3ad465d32b3b, 13613ecaf10f; files: extensions/telegram/src/bot-handlers.runtime.ts, extensions/telegram/src/session-transcript-context.ts, src/config/sessions/transcript.ts)
  • jalehman: Merged the adjacent timestamp-alignment PR for the same Telegram session/cache prompt-context contract. (role: adjacent merger and reviewer; confidence: medium; commits: c8dba85b5d41; files: extensions/telegram/src/bot-message-dispatch.ts, extensions/telegram/src/message-cache.ts, extensions/telegram/src/outbound-message-context.ts)

Codex review notes: model internal, reasoning high; reviewed against 2a741bebb54f; fix evidence: commit e0d23cfc5a26, main fix timestamp 2026-07-06T08:11:08Z.

@tzy-17
tzy-17 force-pushed the fix/99117-telegram-dedup-tags branch from 3834a45 to 249d882 Compare July 6, 2026 03:16
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 6, 2026
resolvePromptContextTextDedupeKey used exact timestamp_ms:body matching,
which failed when the same assistant reply appeared with
[[reply_to_current]] tags in the session transcript copy but
without them in the Telegram cache copy. This produced duplicate
assistant entries in prompt context.

Fix: strip inline directive tags and #session:<id> synthetic ids
from the body before computing the dedupe key, so transcript and
cache copies of the same visible reply are recognized as duplicates.

Fixes openclaw#99117
@tzy-17
tzy-17 force-pushed the fix/99117-telegram-dedup-tags branch from 249d882 to 9916a11 Compare July 6, 2026 10:44
@clawsweeper

clawsweeper Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant