Skip to content

fix(telegram): avoid replaying long streamed replies#87657

Merged
obviyus merged 2 commits into
mainfrom
codex/fix-86519-telegram-duplicates
May 28, 2026
Merged

fix(telegram): avoid replaying long streamed replies#87657
obviyus merged 2 commits into
mainfrom
codex/fix-86519-telegram-duplicates

Conversation

@obviyus
Copy link
Copy Markdown
Contributor

@obviyus obviyus commented May 28, 2026

Summary

  • Finalize already-streamed long Telegram replies instead of falling back to a fresh durable send from byte zero.
  • Send only the missing suffix when a final response extends the streamed prefix.
  • Add regression coverage for full replay, pending flush, suffix-only follow-up, and inline-button preservation.

Refs #86519.

Verification

  • node scripts/run-vitest.mjs extensions/telegram/src/lane-delivery.test.ts -- --reporter=verbose -> 32 passed
  • Telegram bot-to-bot E2E with mocked SSE: one-delta long response -> bugExists: false, mockRequests: 1, restartedReplyIds: []
  • Telegram bot-to-bot E2E with mocked SSE: multi-delta long response -> bugExists: false, mockRequests: 1, restartedReplyIds: []
  • pnpm check:changed currently fails in untouched src/plugin-sdk/approval-reaction-runtime.ts:300 on latest origin/main (ApprovalActionView.kind), outside this diff.

Behavior addressed: duplicate Telegram replay after long streamed replies
Real environment tested: real Telegram bot-to-bot group with mocked OpenAI SSE
Exact steps or command run after this patch: focused Vitest, changed check, Telegram E2E long-response probes
Evidence after fix: no restarted segment-01 reply in either E2E run
Observed result after fix: long replies continue as Telegram chunks without replaying the beginning
What was not tested: full suite / Testbox

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: M maintainer Maintainer-authored PR labels May 28, 2026
@obviyus obviyus force-pushed the codex/fix-86519-telegram-duplicates branch from 3a89c60 to 911a17a Compare May 28, 2026 13:51
@clawsweeper
Copy link
Copy Markdown
Contributor

clawsweeper Bot commented May 28, 2026

Codex review: needs maintainer review before merge. Reviewed May 28, 2026, 9:58 AM ET / 13:58 UTC.

Summary
The PR changes Telegram lane text delivery to finalize already streamed long replies, send only a missing final suffix, and cover replay/button cases in regression tests.

PR surface: Source +71, Tests +131. Total +202 across 2 files.

Reproducibility: yes. the linked issue has a 2026-05-28 current-main Telegram bot-to-bot E2E repro with a long streamed response replaying as multiple Telegram replies. Source inspection of current main shows the finalization path falls back when delivered stream text has advanced beyond the first chunk.

Review metrics: 1 noteworthy metric.

  • Real Telegram probes: 2 after-fix bot-to-bot E2E probes reported. Telegram maintainer notes ask for real Telegram proof for streaming changes, and the PR body reports one-delta and multi-delta long-response probes.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

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

Rank-up moves:

  • [P2] Clear or document the current head CI failures and pending critical-quality shard before merge.

Mantis proof suggestion
A real Telegram transcript would materially confirm the duplicate-reply behavior this PR changes. A maintainer can ask Mantis to capture proof by posting a new PR comment that starts with the OpenClaw Mantis account mention, followed by:

telegram live: verify that a long streamed Telegram reply is not replayed from the beginning and only the missing suffix is sent.

Risk before merge

  • [P1] Head CI is not fully green: public check-runs show failures in build-artifacts, check-lint, check-prod-types, check-test-types, check-guards, and extension checks, plus one critical-quality shard still in progress.
  • [P1] The linked duplicate report also contains broader cross-channel/session-state symptoms, so this PR should be treated as a narrow Telegram long-stream replay fix rather than a complete closure of all duplicate-message reports.

Maintainer options:

  1. Decide the mitigation before merge
    Land the narrow Telegram long-stream replay fix after CI is clean, and keep the broader duplicate-report thread open until non-Telegram/session symptoms are separately proven fixed or ruled out.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P2] No narrow automated repair is indicated; maintainers need to review the protected Telegram PR and resolve or classify the current CI failures before landing.

Security
Cleared: The diff only changes Telegram delivery logic and tests, with no dependency, workflow, credential, package, lockfile, or release-surface change.

Review details

Best possible solution:

Land the narrow Telegram long-stream replay fix after CI is clean, and keep the broader duplicate-report thread open until non-Telegram/session symptoms are separately proven fixed or ruled out.

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

Yes: the linked issue has a 2026-05-28 current-main Telegram bot-to-bot E2E repro with a long streamed response replaying as multiple Telegram replies. Source inspection of current main shows the finalization path falls back when delivered stream text has advanced beyond the first chunk.

Is this the best way to solve the issue?

Yes for the Telegram long streamed reply replay path: the PR fixes the owner-local finalization logic instead of adding a second delivery path. It is not, by itself, the complete solution for the broader cross-channel duplicate symptoms in the linked issue.

AGENTS.md: found and applied where relevant.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 8ba71e4afffc.

Label changes

Label changes:

  • add P1: The PR targets an urgent user-visible Telegram duplicate-reply regression affecting normal channel delivery.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides after-fix real Telegram bot-to-bot group proof with mocked OpenAI SSE and observed no restarted long-response segment.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides after-fix real Telegram bot-to-bot group proof with mocked OpenAI SSE and observed no restarted long-response segment.
  • add mantis: telegram-visible-proof: Mantis should capture Telegram visible proof. The PR changes visible Telegram reply delivery behavior that can be demonstrated in a short Telegram transcript or Desktop recording.

Label justifications:

  • P1: The PR targets an urgent user-visible Telegram duplicate-reply regression affecting normal channel delivery.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides after-fix real Telegram bot-to-bot group proof with mocked OpenAI SSE and observed no restarted long-response segment.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides after-fix real Telegram bot-to-bot group proof with mocked OpenAI SSE and observed no restarted long-response segment.
  • mantis: telegram-visible-proof: Mantis should capture Telegram visible proof. The PR changes visible Telegram reply delivery behavior that can be demonstrated in a short Telegram transcript or Desktop recording.
Evidence reviewed

PR surface:

Source +71, Tests +131. Total +202 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 80 9 +71
Tests 1 131 0 +131
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 211 9 +202

What I checked:

  • Current main fallback path: Current main compares the delivered stream text to only the first final chunk and returns undefined when the delivered text has advanced beyond that chunk, which sends the caller down the normal durable-final fallback path. (extensions/telegram/src/lane-delivery-text-deliverer.ts:343, 8ba71e4afffc)
  • PR delivered-prefix path: The PR adds delivered-prefix detection before updating the stream, then finalizes the existing Telegram preview and sends only the missing suffix when the final text extends the delivered prefix. (extensions/telegram/src/lane-delivery-text-deliverer.ts:282, 911a17aa3731)
  • Regression coverage: The PR adds tests for no replay, suffix-only follow-up, stop-time flushing, and inline button preservation on already streamed long finals. (extensions/telegram/src/lane-delivery.test.ts:666, 911a17aa3731)
  • Linked issue reproduction: A linked issue comment reports a current-main Telegram bot-to-bot E2E reproduction with one 13,480-character streamed model response, one model request, four Telegram reply messages, and one edit, matching the replay shape this PR targets.
  • Telegram review policy: Telegram maintainer notes say streaming owns one visible preview message, should edit it forward, and Telegram streaming changes need real Telegram proof; this matches the PR's fix direction and proof expectation. (.agents/maintainer-notes/telegram.md:8, 8ba71e4afffc)
  • CI status snapshot: Public check-runs for the PR head include successful real behavior proof and many passing checks, but also failures in build/lint/type/extension lanes and one in-progress critical-quality shard. (911a17aa3731)

Likely related people:

  • obviyus: Ayaan Zaidi authored recent current-main Telegram draft-stream overflow/finalization commits and also authored this PR branch, so this is a strong routing candidate for the streaming replay path. (role: recent area contributor; confidence: high; commits: e856932600a3, 8677310fb59a, bda924b6390e; files: extensions/telegram/src/draft-stream.ts, extensions/telegram/src/draft-stream.test.ts, extensions/telegram/src/lane-delivery-text-deliverer.ts)
  • steipete: Peter Steinberger has the highest sampled commit count across the central Telegram dispatch/delivery files and recent adjacent bot dispatch/refactor history. (role: heavy adjacent contributor; confidence: medium; commits: 27ae826f6525, 03a43fe23157, ab96520bbad5; files: extensions/telegram/src/bot-message-dispatch.ts, extensions/telegram/src/lane-delivery-text-deliverer.ts, extensions/telegram/src/lane-delivery.test.ts)
  • vincentkoc: Vincent Koc recently touched Telegram/channel streaming configuration and reasoning preview behavior, which are adjacent to the delivery path reviewed here. (role: recent adjacent contributor; confidence: medium; commits: 0fdf9e874b7e, 4954d025e21e, 337fa8c956e9; files: extensions/telegram/src/bot-message-dispatch.ts, extensions/telegram/src/lane-delivery-text-deliverer.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.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. mantis: telegram-visible-proof Mantis should capture Telegram visible proof. P1 High-priority user-facing bug, regression, or broken workflow. labels May 28, 2026
@obviyus obviyus force-pushed the codex/fix-86519-telegram-duplicates branch from 911a17a to 26d3a4c Compare May 28, 2026 14:03
@obviyus obviyus merged commit 844d263 into main May 28, 2026
82 of 91 checks passed
@obviyus obviyus deleted the codex/fix-86519-telegram-duplicates branch May 28, 2026 14:03
@obviyus
Copy link
Copy Markdown
Contributor Author

obviyus commented May 28, 2026

Merged with rebase. Proof before merge:

  • node scripts/run-vitest.mjs extensions/telegram/src/lane-delivery.test.ts -- --reporter=verbose -> 1 file passed, 32 tests passed.
  • Live PR state before merge: MERGEABLE at 26d3a4c774.
  • Landed on main: 27d57af127 fix, 844d263af0 regression test.

Known gap: no broad changed gate rerun here; earlier broad check was blocked by an unrelated current-main type error outside the Telegram files.

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

Labels

channel: telegram Channel integration: telegram maintainer Maintainer-authored PR mantis: telegram-visible-proof Mantis should capture Telegram visible proof. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant