fix: Telegram replies duplicate recent context after sent replies#98769
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 2, 2026, 1:03 AM ET / 05:03 UTC. Summary PR surface: Source +102, Tests +105. Total +207 across 8 files. Reproducibility: yes. at source level: current main dedupes session and cache prompt rows by timestamp_ms plus body while outbound cache rows use Telegram/cache timing. I did not run a live current-main Telegram repro because this review is read-only. Review metrics: 2 noteworthy metrics.
Stored data model 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:
Mantis proof suggestion Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land this PR or a narrow equivalent after maintainer acceptance of transcript-time cache alignment; leave the linked issue open until the candidate fix merges. Do we have a high-confidence way to reproduce the issue? Yes, at source level: current main dedupes session and cache prompt rows by timestamp_ms plus body while outbound cache rows use Telegram/cache timing. I did not run a live current-main Telegram repro because this review is read-only. Is this the best way to solve the issue? Yes. The patch is the narrowest maintainable fix I found: carry the transcript final timestamp into the matching Telegram outbound cache row instead of adding a broader identity scheme or changing prompt-context policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against b2c507c5f04c. Label changesLabel justifications:
Evidence reviewedPR surface: Source +102, Tests +105. Total +207 across 8 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
|
|
@clawsweeper re-review |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
🦞🧹 I asked ClawSweeper to review this item again. |
3180a0c to
7732e3d
Compare
7732e3d to
9d3439c
Compare
Security-sensitive guard clearedThis PR no longer has blocked security-sensitive file changes. A future security-sensitive change requires a fresh
|
432991d to
467d09b
Compare
|
Merged via squash.
|
Closes #98767
What Problem This Solves
Fixes an issue where Telegram direct-message users could receive duplicated recent prompt context after a visible assistant reply was sent back to Telegram.
Why This Change Was Made
Telegram already reads the current turn transcript when recovering the final assistant text for delivery. This change keeps that same transcript timestamp on the Telegram prompt-context cache entry when the cached outbound text matches the transcript final text, instead of deriving prompt-context order from Telegram send completion time. It does not add new per-message IDs, change delivery behavior, or broaden the prompt-context cache policy.
User Impact
Telegram DM sessions keep cleaner prompt context after sent replies. The shared session transcript and Telegram prompt-context cache no longer describe the same assistant reply with different ordering timestamps, which reduces duplicate recent-context rows and token waste.
Live Proof
Captured on the PR branch in a local Telegram DM using TomServoBotBot. Before the proof run, iMessage and WhatsApp were disabled in the local OpenClaw config and the proof gateway reported both as unavailable/unknown channels; Telegram remained running.
Proof sequence:
oc proof one 2026-07-01-1508: reply with exactly alpha proofalpha proofoc proof two 2026-07-01-1508: report whether the immediately prior assistant reply appears once or more than once in the conversation context for this turnRedacted trajectory extract:
{ "sessionKey": "agent:main:direct:<redacted>", "currentMessageId": "29737", "previousAssistantMessageId": "29736", "previousAssistantContextRows": 1, "redactedContextRows": [ "#29736 <timestamp> OpenClaw: alpha proof" ], "assistantTexts": [ "Once." ] }The live proof was captured before the branch was narrowed and rebased onto current
main; the rebased head contains the same Telegram runtime/test change and no non-Telegram cleanup.Evidence
pnpm docs:listpnpm test extensions/telegram/src/bot-message-dispatch.test.ts --reporter=dotpnpm test extensions/telegram/src/outbound-adapter.test.ts --reporter=dotpnpm test extensions/telegram/src/send.test.ts --reporter=dotpnpm check:test-typespnpm exec oxfmt --check extensions/telegram/src/bot-message-dispatch.ts extensions/telegram/src/bot-message-dispatch.test.ts extensions/telegram/src/outbound-adapter.ts extensions/telegram/src/outbound-adapter.test.ts extensions/telegram/src/send.ts extensions/telegram/src/send.test.ts extensions/telegram/src/outbound-message-context.tsOPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 pnpm check:changed --base openclaw/main --head HEADgit diff --check openclaw/main...HEAD