fix(telegram): exclude bot messages from DM chat window to prevent duplicate assistant entries#100580
Conversation
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
2c70a1c to
c7ded4c
Compare
|
Codex review: needs real behavior proof before merge. Reviewed July 6, 2026, 2:06 AM ET / 06:06 UTC. Summary PR surface: Source +5, Tests +97. Total +102 across 2 files. Reproducibility: yes. source-reproducible: current main builds raw session transcript rows and cache rows, then dedupes by exact timestamp/body, so directive-tagged transcript text can survive beside a visible-equivalent cache row. I did not run a live Telegram scenario in this read-only review. Review metrics: 1 noteworthy metric.
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:
Proof guidance:
Mantis proof suggestion Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Keep this PR open until a linked canonical PR proves it covers this PR's unique work, or a maintainer confirms closure. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible: current main builds raw session transcript rows and cache rows, then dedupes by exact timestamp/body, so directive-tagged transcript text can survive beside a visible-equivalent cache row. I did not run a live Telegram scenario in this read-only review. Is this the best way to solve the issue? Yes. Normalizing the body inside the existing timestamp-preserving session/cache dedupe key is narrower than filtering cache messages or dropping timestamps, and it preserves the cache-row preference because cache keys are built before session rows are filtered. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 241c761d0036. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +5, Tests +97. Total +102 across 2 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
Review history (2 earlier review cycles)
|
3ba5d20 to
0f9e093
Compare
0f9e093 to
936136a
Compare
Summary
Problem: In Telegram DM conversations, the same assistant reply appears twice in the prompt context — once from the session transcript (with directive tags like
[[reply_to_current]]) and once from the Telegram message cache (the plain delivered message). The existing deduplication uses rawtimestamp_ms:bodywhich fails when the two copies differ in directive tags.Solution: Normalize body text in
resolvePromptContextTextDedupeKeyby stripping inline directive tags viastripInlineDirectiveTagsForDeliverybefore building the dedupe key. This allows the existing session/cache merge logic to deduplicate on visible text while preserving timestamp alignment — the cache-backed Telegram row wins over the synthetic transcript row.What changed: Modified
resolvePromptContextTextDedupeKeyto strip directive tags from the body before computing the dedupe key. Added a handler-level regression test that writes assistant transcript context with tagged text, exercises the full Telegram inbound handler path, and asserts a single deduplicated cache entry.What did NOT change: The session/cache merge logic, timestamp alignment, message ordering, group context building, and all non-dedupe code paths.
Fixes #99117
What Problem This Solves
Users in Telegram DMs see duplicated assistant context in the prompt when the assistant used directive tags:
After the fix, the session transcript entry (with
[[reply_to_current]]) and the cache entry (plain text) produce the same dedupe keytimestamp_ms:Yep — I'm here now., so the cache-backed Telegram row survives and the synthetic transcript row is filtered out.Root Cause
resolvePromptContextTextDedupeKeyusedmessage.body.trim()directly as the text component of the dedupe key without stripping directive tags. Session transcript entries carry inline directive tags (e.g.[[reply_to_current]]) that the delivered Telegram message lacks. The:bodyportion of the dedupe key differed, so the two entries were treated as distinct and both appeared in the merged prompt context.Real behavior proof
Behavior addressed: Assistant messages with directive tags are deduplicated against cache entries with the same visible text.
Real environment tested: Linux x64, Node v24.13.1, openclaw/openclaw main
Exact steps or command run after this patch:
The regression test exercises the full handler path:
[[reply_to_current]]-tagged textreply_to_messagemessage_idAfter-fix evidence:
The test expects exactly one message matching the visible reply text, no directive tags in the final payload, and no
session:-prefixed ids:Observed result after the fix: The handler-level regression test passes, confirming that the session transcript entry with
[[reply_to_current]]Yep — I'm here now.is deduplicated against the cache entry withYep — I'm here now.. Only one message remains in the conversation context, it uses the cache-backedmessage_id: "736"(not a syntheticsession:id), and no directive tags appear in the final payload.What was not tested: Live Telegram bot end-to-end scenario — not available in this environment. The regression test exercises the full handler-to-prompt-context path with real session store and message cache fixtures.
Risk checklist
merge-risk: Low
stripInlineDirectiveTagsForDeliveryalready used across the codebase