Skip to content

fix(telegram): preserve outbound prompt context projections#102469

Merged
steipete merged 2 commits into
openclaw:mainfrom
chenyangjun-xy:fix/issue-102257-telegram-markdown-dedup
Jul 11, 2026
Merged

fix(telegram): preserve outbound prompt context projections#102469
steipete merged 2 commits into
openclaw:mainfrom
chenyangjun-xy:fix/issue-102257-telegram-markdown-dedup

Conversation

@chenyangjun-xy

@chenyangjun-xy chenyangjun-xy commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Telegram follow-up turns could include both the canonical assistant transcript row and one or more Telegram-rendered cache rows for the same reply. Markdown rendering, chunking, rich fallback, media delivery, retries, and streaming make visible-text/timestamp comparison unable to prove that two rows represent the same complete assistant turn.

This addresses #102257 and supersedes the narrower approaches in #102259 and #100333.

Why This Change Was Made

Carry the stable transcript message identity into every concrete Telegram delivery and persist a versioned projection with contiguous part indexes and exactly one terminal part. Prompt assembly suppresses the canonical transcript row only when the complete projected Telegram sequence is present; incomplete, invalid, future-version, hook-mutated, or failed sequences retain the transcript instead.

The maintainer rewrite keeps the contract inside the Telegram plugin, uses the shared SQLite-backed plugin state store, migrates the shipped legacy cache through doctor, and applies the same projection owner across plain, rich-fallback, media, streamed, paginated, and retried delivery paths.

User Impact

Telegram conversations no longer spend context on duplicated Markdown-formatted assistant replies. Multipart and repeated-identical replies retain their exact turn identity, while partial delivery or stale cache state fails safe by preserving the full canonical transcript.

Evidence

  • Blacksmith Testbox: 13 focused Telegram files, 779 tests passed on the rebased branch
  • Blacksmith Testbox: pnpm check:changed passed extension/test typechecks, extension lint, database-first guards, and import-cycle checks
  • oxfmt --check: 28 changed files passed
  • Fresh structured autoreview: clean, no accepted/actionable findings
  • Hosted exact-head CI/Testbox: pending after branch update
  • Live Telegram user proof: pending exact-head run

Contributor credit is retained for @chenyangjun-xy, @consoleaf, and @crabkun.

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 9, 2026
@chenyangjun-xy
chenyangjun-xy force-pushed the fix/issue-102257-telegram-markdown-dedup branch from 32d4ade to e79c7a3 Compare July 9, 2026 06:44
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 9, 2026
@clawsweeper

clawsweeper Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 10, 2026, 8:56 PM ET / July 11, 2026, 00:56 UTC.

Summary
The PR adds transcript-identity projections to Telegram outbound delivery, persists complete multipart projection metadata in plugin state, migrates the legacy cache through doctor, and updates durable, media, fallback, retry, and streaming paths to use the projection owner.

PR surface: Source +195, Tests +3165, Docs +1. Total +3361 across 28 files.

Reproducibility: yes. Current-main source and the linked live instrumentation show that Telegram-rendered plain text can differ from the canonical Markdown transcript and evade the timestamp-qualified dedupe, although this review did not execute a live current-main reproduction.

Review metrics: 3 noteworthy metrics.

  • Projection completeness contract: 3 required properties. A suppressible sequence must be zero-based, contiguous, and have exactly one terminal final part.
  • Persistent state surface: 1 cache record version extended, 1 doctor importer expanded. The change affects upgrade and restart behavior for existing Telegram installations.
  • Exact-head validation: 61 successful checks, 0 failed. Broad automation supports patch quality but cannot replace the missing real Telegram prompt-context proof.

Stored data model
Persistent data-model change detected: migration/backfill/repair: extensions/telegram/src/state-migrations.test.ts, persistent cache schema: extensions/telegram/src/bot.test.ts, serialized state: extensions/telegram/src/bot.test.ts, serialized state: extensions/telegram/src/message-cache.test.ts, serialized state: extensions/telegram/src/prompt-context-projection.ts, serialized state: extensions/telegram/src/session-transcript-context.test.ts, and 8 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #102257
Summary: This PR is the broad candidate fix for the canonical Telegram prompt-context bug and explicitly supersedes the two narrower open text-matching PRs.

Members:

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

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🦞 diamond lobster
Result: blocked until real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Add after-fix proof from a real setup, such as a short recording, terminal output, linked artifact, or redacted logs.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The exact-head PR body says live Telegram proof is pending; tests, mocks, CI, formatting, and autoreview do not show the changed hidden prompt context in a real setup. Add redacted terminal output, runtime logs, live output, or a linked artifact, update the PR body, and ask a maintainer for @clawsweeper re-review if automatic review does not run.

Risk before merge

  • [P1] The PR changes a persisted Telegram cache record and the rule that suppresses canonical assistant transcript rows, so fresh-state tests alone do not settle upgrade and restart behavior.
  • [P1] The reviewed head is behind current main; although a merge-tree check found no textual conflict, the XL delivery rewrite needs semantic refresh against newer Telegram changes.
  • [P1] No inspectable exact-head real setup currently demonstrates that a complete multipart reply produces one hidden assistant context sequence while interrupted or migrated state preserves the canonical transcript.

Maintainer options:

  1. Refresh and prove the exact head (recommended)
    Rebase onto current main, remove the changelog edit, and attach redacted live hidden-context plus legacy migration/restart evidence before merge.
  2. Pause the broad rewrite
    If exact-head parity or upgrade proof cannot be established, keep the canonical issue open rather than accepting ambiguous transcript suppression.

Next step before merge

  • [P1] Continue normal maintainer review; ClawSweeper found no patch-correctness issue.

Security
Cleared: No concrete security or supply-chain regression was found; the diff adds no dependency, workflow, permission, secret-access, or downloaded-code surface.

Review details

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

Yes. Current-main source and the linked live instrumentation show that Telegram-rendered plain text can differ from the canonical Markdown transcript and evade the timestamp-qualified dedupe, although this review did not execute a live current-main reproduction.

Is this the best way to solve the issue?

Yes at the design level. Stable transcript identity plus durable proof of a complete multipart projection is narrower and safer than stripping Markdown or matching body text, but exact-head runtime and upgrade proof remain required.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 1a9d09a23833.

Label changes

Label justifications:

  • P2: The PR fixes recurring Telegram prompt duplication, token waste, and model-context confusion with channel-limited impact.
  • merge-risk: 🚨 compatibility: The patch extends persisted cache values and doctor migration while the branch is behind current main.
  • merge-risk: 🚨 session-state: Persisted projection completeness determines whether canonical assistant history is removed from later model prompts.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦞 diamond lobster.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The exact-head PR body says live Telegram proof is pending; tests, mocks, CI, formatting, and autoreview do not show the changed hidden prompt context in a real setup. Add redacted terminal output, runtime logs, live output, or a linked artifact, update the PR body, and ask a maintainer for @clawsweeper re-review if automatic review does not run.
Evidence reviewed

PR surface:

Source +195, Tests +3165, Docs +1. Total +3361 across 28 files.

View PR surface stats
Area Files Added Removed Net
Source 15 1616 1421 +195
Tests 12 3757 592 +3165
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 28 5374 2013 +3361

What I checked:

  • Current-main bug remains: Current main still uses timestamp-qualified visible-text comparison for assistant transcript/cache dedupe, so Markdown-rendered text can remain unmatched and duplicated. (extensions/telegram/src/bot-handlers.runtime.ts:198, 1a9d09a23833)
  • Fail-safe completeness contract: The rewrite suppresses a transcript identity only when projection indexes are zero-based and contiguous and exactly the final indexed part is terminal; invalid or incomplete groups remain unsuppressed. (extensions/telegram/src/prompt-context-projection.ts:154, dc1f0847a925)
  • Prompt assembly owner: Telegram prompt assembly removes an assistant transcript row by stable transcript id only when the cached projection sequence is complete, while retaining the shipped timestamp-based rule solely for legacy rows. (extensions/telegram/src/bot-handlers.runtime.ts:1479, dc1f0847a925)
  • Upgrade behavior: The doctor import validates legacy cache rows, canonicalizes their keys, strips projection-like fields that older storage could not authoritatively own, and imports versioned plugin-state records. (extensions/telegram/src/state-migrations.ts:143, dc1f0847a925)
  • Focused regression coverage: The branch includes direct Telegram coverage for complete Markdown projections, invalid metadata, distinct identical replies, markerless provenance safety, retained streaming pages, media, and retry behavior. (extensions/telegram/src/bot.test.ts, dc1f0847a925)
  • Exact-head checks: GitHub reports 61 successful checks and no failed checks for the reviewed head; automated checks remain supplemental to the required live proof. (dc1f0847a925)

Likely related people:

  • steipete: Authored the exact-head rewrite across projection identity, dispatch, streaming, cache persistence, and migration, and is assigned to the PR. (role: feature rewrite owner; confidence: high; commits: 8fe9b5bc6b23, dc1f0847a925; files: extensions/telegram/src/prompt-context-projection.ts, extensions/telegram/src/bot-message-dispatch.ts, extensions/telegram/src/draft-stream.ts)
  • lsr911: Recent current-main history introduced the Telegram plugin-state message-cache foundation and migration path extended by this PR. (role: recent persistence contributor; confidence: medium; commits: 9dee9ebffa58; files: extensions/telegram/src/message-cache.ts, extensions/telegram/src/state-migrations.ts, extensions/telegram/src/bot-handlers.runtime.ts)
  • momothemage: Authored the merged directive-aware prompt-context dedupe predecessor that established the timestamp-qualified legacy behavior retained by this rewrite. (role: prior dedupe contributor; confidence: medium; commits: 8a3b4c254911, 5c4cc7245ef0, e0d23cfc5a26; files: extensions/telegram/src/bot-handlers.runtime.ts, extensions/telegram/src/bot-message-dispatch.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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 keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (19 earlier review cycles; latest 8 shown)
  • reviewed 2026-07-09T12:01:30.796Z sha 735fcd4 :: needs real behavior proof before merge. :: [P2] Type the test helper parameter
  • reviewed 2026-07-09T12:35:17.187Z sha ca52ded :: needs real behavior proof before merge. :: [P2] Remove the unrelated workspace metadata file
  • reviewed 2026-07-09T12:45:08.553Z sha ca52ded :: needs real behavior proof before merge. :: [P2] Remove the unrelated workspace metadata file
  • reviewed 2026-07-09T13:14:31.189Z sha 83ad940 :: needs real behavior proof before merge. :: [P1] Restore the Telegram dispatch module | [P2] Remove the unrelated ignored metadata path
  • reviewed 2026-07-09T13:36:03.595Z sha dbdc319 :: needs real behavior proof before merge. :: [P2] Anchor fenced-code stripping to real fence lines | [P2] Remove the unrelated ignored workspace path
  • reviewed 2026-07-09T14:24:55.338Z sha 1e7676b :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-09T15:15:41.561Z sha 1e7676b :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-10T09:13:16.618Z sha 90a18d3 :: needs real behavior proof before merge. :: [P1] Normalize links through Telegram's visible-text path

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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 9, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 9, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jul 9, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 9, 2026
@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 9, 2026
@chenyangjun-xy
chenyangjun-xy force-pushed the fix/issue-102257-telegram-markdown-dedup branch from d74803c to 8779ae8 Compare July 9, 2026 07:43
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 9, 2026
@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. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 9, 2026
@chenyangjun-xy
chenyangjun-xy requested a review from a team as a code owner July 9, 2026 12:48
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Security-sensitive guard cleared

This PR no longer has blocked security-sensitive file changes. A future security-sensitive change requires a fresh /allow-security-sensitive-change comment after the guard blocks that new head SHA.

  • Current SHA: dc1f0847a925bb5bd9a11e3d00c33dc9a712867c

@chenyangjun-xy
chenyangjun-xy force-pushed the fix/issue-102257-telegram-markdown-dedup branch from 83ad940 to dbdc319 Compare July 9, 2026 13:23
@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 9, 2026
@chenyangjun-xy

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@openclaw-mantis

Copy link
Copy Markdown
Contributor

Mantis Telegram Desktop Proof

Summary: Mantis captured native Telegram Desktop before/after GIFs showing repeated long Telegram replies in chat.

Main screenshot This PR screenshot
Baseline native Telegram Desktop screenshot Candidate native Telegram Desktop screenshot
Main This PR
Baseline native Telegram Desktop proof GIF Candidate native Telegram Desktop proof GIF

Motion-trimmed clips:

Raw QA files: https://artifacts.openclaw.ai/mantis/telegram-desktop/pr-102469/run-29133087432-1/index.json

@steipete

Copy link
Copy Markdown
Contributor

Land-ready maintainer proof for exact head dc1f0847a925bb5bd9a11e3d00c33dc9a712867c:

The Mantis candidate lane passed at the exact PR SHA and published native Telegram Desktop screenshots, GIFs, MP4s, and its raw evidence manifest. The focused suite covers stable source identities, multipart projection completeness, streamed/fallback/media delivery, reply ownership, business identities, and durable SQLite projection state.

@steipete

Copy link
Copy Markdown
Contributor

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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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: XL 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.

2 participants