Skip to content

fix(telegram): suppress duplicate DM transcript windows while preserving delivery-only context - #183190

Merged
obviyus merged 6 commits into
openclaw:mainfrom
salad-maker:fix/telegram-suppress-persisted-dm-session-transcript-context
Nov 14, 2026
Merged

obviyus merged 6 commits into
openclaw:mainfrom
salad-maker:fix/telegram-suppress-persisted-dm-session-transcript-context

Conversation

@salad-maker

@salad-maker salad-maker commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Related: #89855, #112548, #130551, #172711, #179399

What Problem This Solves

In an existing plain Telegram DM, recent assistant turns reach the model twice: once through canonical session replay and again through a supplemental session chat_window. Telegram already suppresses its native DM window in this case, but the shared transcript-context owner then rebuilt the same turns from the session transcript.

User Impact

The model sees already-delivered answers (including Cron announcements) twice in the same request, which encourages repeated or stale answers. A November 8 report on this PR describes a real DM installation re-sending already-delivered finals; its dmHistoryLimit: 0 workaround also drops Cron announcement context.

Why This Change Was Made

  • Telegram keeps its existing plain-DM suppression predicate and passes deliveryOnly: true on SessionTranscriptContext.
  • The shared transcript reader selects its bounded recent window first, then keeps only transcript-only delivery mirrors (Cron direct delivery, message-tool source replies) that normal replay excludes.
  • Fresh DMs, explicit replies, topics and groups keep their current selection. No config, schema or storage change.
  • deliveryOnly is an additive optional field on a type the plugin SDK exposes transitively through BuildChannelInboundEventContextParams.sessionTranscript. It is source-compatible for every existing caller and grants no new authority; maintainers accept it as the narrow Telegram-to-core selection signal.

Evidence

Live Telegram Test Server E2E (real Gateway, TDLib user, deterministic Chat Completions mock that logs each model request). Scenario: DM PING:one, a real Cron job announcing PONG:cronnote, then PING:after. The judged request is the one answering PING:after.

  • main 8ebe740925ca (reproduced): replay contains assistant: PONG:one and assistant: PONG:cronnote, and the same request also carries a "Conversation context" session window repeating both rows (PONG:one x2, PONG:cronnote x2).
  • head 826864b3be9c (built from this exact commit): replay contains both assistant rows once; no supplemental window is added (PONG:one x1, PONG:cronnote x1). The Cron announcement stays in context.
  • Focused tests on this head pass: session-transcript-context.sqlite.test.ts, bot-message-context.prompt-context.test.ts, session-transcript-context.runtime.test.ts. The SQLite regression fails on the original parent and passes with the fix.
  • CI on 826864b3be9c is green.

@clawsweeper

clawsweeper Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: XS labels Oct 25, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 25, 2026
@clawsweeper

clawsweeper Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

Suppresses replayed conversation turns from existing plain Telegram DM windows while retaining delivery-only context.

Example: Send PING:one, receive a Cron announcement PONG:cronnote, then send PING:after.

  • Before: The final model request contains PONG:one and PONG:cronnote twice through replay and supplemental history.
  • After: Both appear once, with the Cron announcement still available.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused, behavior-proven repair with no actionable code findings; unresolved SDK direction limits overall readiness.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Exact-head Telegram Test Server evidence records ordinary and Cron replay once without a supplemental duplicate; retained live-provider traces additionally exercise final-tool restoration and Gateway restarts.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Complete
User problem: Existing Telegram DMs can repeatedly present already-delivered answers as supplemental context, encouraging stale or repeated responses.
Reason: The repair has clear user value and respects existing behavior, but the explicitly requested acceptance of its public SDK carrier remains unverified.

Merge readiness

⛔ Blocked before merge - 1 item remains

This PR addresses a current Telegram context bug with useful runtime evidence and no actionable correctness findings; the previously requested SDK contract acceptance remains unverified.

Priority: P2
Reviewed head: 826864b3be9c5b6c6448579651c491052e5220d1
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Has the SDK owner accepted SessionTranscriptContext.deliveryOnly, or should the Telegram-to-core selection contract change?
  • Recommendation: Accept the optional field: Confirm the recorded acceptance or approve this narrow, source-compatible selection signal through the existing inbound contract.
  • Why: The previous collaborator review explicitly held this boundary for SDK-owner review; the body's acceptance assertion has no attributable approval in the retrieved discussion.

Before merge

  • Await maintainer action - The SDK owner must confirm acceptance of deliveryOnly or specify the alternative requested by the earlier collaborator review.

Findings

None.

Agent review details

How this fits together

Telegram selects supplemental context, core merges bounded transcript history, and the resulting context accompanies canonical conversation replay into the model request.

flowchart LR
  A[Telegram DM] --> B[Telegram context selection]
  B --> C[Shared prepared turn]
  D[Session transcript] --> E[Bounded recent text reader]
  E --> C
  C --> F[Supplemental context]
  D --> G[Canonical replay]
  F --> H[Model request]
  G --> H
Loading

Technical review

Best possible solution:

Retain Telegram's existing suppression decision and core's bounded delivery-only projection, with explicit acceptance of the optional SDK contract.

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

Current-main source shows the duplicate reconstruction path, and supplied Telegram request traces reproduce it; this review executed no target code.

Is this the best way to solve the issue?

The patch uses the existing Telegram predicate and shared transcript owner, preserves window bounds and delivery exceptions, and adds no competing state or unnecessary production layer.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against edc6bf994da2.

Provenance checked

  • Existing plain-DM suppression keeps the original intent (2100ee7: Avoid duplicating persistent conversation history while retaining fresh, reply, topic and group windows.)
  • Core transcript restoration keeps the original intent (5e651d5: Restore bounded canonical context after restart through one shared prepared-turn owner.)
  • Final message-tool delivery context keeps the original intent (ca3f743: Keep confirmed delivered answers visible when normal replay excludes their bookkeeping mirrors.)
  • Snapshot and window bounds keeps the original intent (681c9c8: Select recent context within one transcript snapshot so concurrent appends do not shift pagination.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +16, Tests +199. Total +215 across 6 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 37 21 +16
Tests 2 199 0 +199
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 236 21 +215

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Inbound SDK expansion 1 optional selection field deliveryOnly is exposed transitively through BuildChannelInboundEventContextParams.sessionTranscript; existing callers remain source-compatible.

Labels

Label changes:

  • add status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.

Label justifications:

  • P2: Duplicate supplemental history can encourage repeated answers in ongoing Telegram DMs, with a bounded channel-specific blast radius.
  • merge-risk: 🚨 compatibility: The patch expands a public SDK parameter contract, and the explicit SDK-owner review request has not been verifiably resolved.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (6 earlier review cycles)
  • reviewed 2026-10-25T03:35:29.332Z sha 89ac840372ae2aec62e4d48cd724f03d9675e701 :: needs real behavior proof before merge. :: [P2] Preserve delivery-only context when suppressing duplicate DM history
  • reviewed 2026-10-25T04:08:41.385Z sha 1e9e77245a93abaa5bd242a8f98c78595df1f5e6 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-25T05:15:00.143Z sha 57a4cb1 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-25T17:14:49.232Z sha 57a4cb1 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-27T01:01:54.378Z sha 09618b3 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-10T00:41:01.873Z sha df37768 :: blocked before merge. :: none

Reviewed November 14, 2026, 12:08 AM ET / 05:08 UTC (Revision 7).

@salad-maker
salad-maker force-pushed the fix/telegram-suppress-persisted-dm-session-transcript-context branch from 89ac840 to 1e9e772 Compare October 25, 2026 04:03
@salad-maker salad-maker changed the title fix(telegram): keep existing plain DMs from re-injecting transcript chat windows fix(telegram): suppress duplicate DM transcript windows while preserving delivery-only context Oct 25, 2026
@salad-maker

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 25, 2026
@salad-maker
salad-maker force-pushed the fix/telegram-suppress-persisted-dm-session-transcript-context branch from 1e9e772 to 57a4cb1 Compare October 25, 2026 05:08
@salad-maker

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@frankdilo

Copy link
Copy Markdown

Note

🤖 Claude Opus 5.5 responding on behalf of @frankdilo

Hitting this on a real install, and the current releases don't fix it, so this PR is still needed.

Setup: OpenClaw 2026.10.8, Telegram DM, Codex app-server runtime (openai/gpt-6-sol). Every final answer goes out through the message tool ("Final assistant text is not automatically delivered in this run").

What happens: the per-turn Conversation context (chronological, selected for current message) block contains only the user turns and the model's short progress lines. It never contains the delivered final answers, which are stored as delivery mirrors:

"provider": "openclaw", "model": "delivery-mirror",
"openclawDeliveryMirror": { "kind": "message-tool-source-reply", "final": true, "toolCallId": "…", "sourceTurnId": "channel-user:v1:…" }

extractRecentConversationText drops them through isTranscriptOnlyOpenClawAssistantMessage. The window then reads as a list of unkept promises, for example:

User: <asks for a link to an email draft>
OpenClaw: I'll save it as a draft and send you the link.
User: <unrelated request: log 2 hours in a timesheet>
OpenClaw: Logging 2 more hours, then I'll check the monthly total.

The link and the total were both delivered, but only these progress lines reach the next turn. On every later turn the model re-sends an answer it already delivered, at one point saying it "still owes" the link, until the promise scrolls out of the 10-message window. In one day it re-attached the same draft link to four unrelated replies and repeated the timesheet total on two more.

Why 2026.10.10 and 2026.11.1 don't fix it (from reading the built packages, not tested): #179399 added includeMessageToolSourceReplies, but mergeSessionTranscriptContext only passes it when windows.length === 0 && options?.chatWindow === true. A Telegram DM always builds its own chat_window (buildPromptContextForMessage in the Telegram bot handler), so that branch never runs and the mirrors stay filtered. 2026.11.5-beta.1 has the same condition on this path. Our mirrors meet every field includeTerminalSourceReply checks, so the deliveryOnly restore in this PR looks like the right fix for our case.

Workarounds we tried:

  • An AGENTS.md instruction explaining that the block omits delivered replies and that answered requests are settled. It was confirmed loaded in the Codex thread but didn't stop the repeats: over the next two days the model kept repeating whatever stale promises were in the block.
  • channels.telegram.dmHistoryLimit: 0, which we're using now. The Codex thread already holds the user turns and the message tool calls, so normal history is unaffected. The cost: automation-result messages (e.g. a daily check-in from a cron job) never enter the Codex thread on their own, so with the window off the model sees them only when the user answers with Telegram's reply ([reply target]).

Copy link
Copy Markdown
Contributor Author

The PR description is now updated with passing CI for df377682122984deb56e11e8d0e2ec4bdf929911, the November 8 user report, and the outstanding SDK contract decision. The live Telegram proof remains explicitly labeled as prior-head evidence; no new runtime run is claimed.

Following up on the October 28 review: could this be routed to the responsible SDK owner to accept the optional SessionTranscriptContext.deliveryOnly field (exposed through BuildChannelInboundEventContextParams.sessionTranscript) or specify a preferred core-only alternative? This design decision remains open independently of CI and the requested bot review.

Current-head CI and the aggregate/security gates pass. GitHub reports the branch mergeable, and maintainer edits are enabled.

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 10, 2026
@roboclaw-bot roboclaw-bot added the clawtributors PR from a clawtributor label Nov 10, 2026
@obviyus

obviyus commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 14, 2026
@obviyus

obviyus commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

Maintainer decision on SessionTranscriptContext.deliveryOnly: accepted as proposed.

  • It is an optional, additive field on the inbound session-transcript context. Existing channel plugins that never set it keep today's selection, so the change is source-compatible and needs no migration.
  • It is the narrowest signal that lets Telegram say "this persisted DM only needs delivery-only rows" without core learning Telegram's DM rules. Moving that policy into core would add a channel-specific branch there instead.
  • Live proof at this head (826864b3be9c) is in the PR body: Telegram Test Server DM, PING:one then a Cron announcement. On main the next turn carries PONG:one and PONG:cronnote twice (replay plus a duplicate session chat window); on this head they appear once in replay and the window is gone.

@obviyus
obviyus merged commit 0acdb20 into openclaw:main Nov 14, 2026
145 checks passed
@obviyus

obviyus commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

Merged via squash.

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

Labels

channel: telegram Channel integration: telegram clawtributors PR from a clawtributor merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants