Repository navigation
fix(telegram): coalesce native drafts and preserve growing text - #133842
Open
Rinta13795 wants to merge 2 commits into
Open
Rinta13795 wants to merge 2 commits into
Rinta13795 wants to merge 2 commits into
Conversation
13 of 19 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Telegram native previews currently burst after crossing the cumulative buffer threshold, rewrite unfinished Markdown, and abandon draft transport on a short flood cooldown. This change coalesces native previews into stable cumulative text and shares Telegram's draft/typing quota, while preserving the existing complete formatted final answer.
Why
A native client can animate appended characters when the same draft ID is updated. Repeated snapshot rewrites and excess requests work against that behavior. The unchanged base reproduces six calls in 250 ms with an 800 ms interval, plus cursor/fence changes to already displayed code.
Related Issue
Fixes #133841.
Related: #133804 (restart documentation), #54817 / #26157 (client flicker).
Prior work overlaps: #112949 handles interval enforcement; #53865 / #54286 handle draft flood cooldowns. This PR combines a native-draft-only cadence gate with raw prefix stability and the shared draft/typing quota. It leaves ordinary-edit cadence, default transport selection, and hard-error fallback unchanged. #110611's ordinary-message activity feature is outside this scope.
Type of Change
Changes Made
What
gateway/stream_consumer*.py: coalesce native draft updates at elapsed cadence; omit synthetic fence closures/cursors for prefix-stable adapters; keep deferred previews pending without claiming delivery or disabling draft transport.plugins/platforms/telegram/telegram_drafts.py: extract draft delivery, retain raw UTF-16-bounded prefixes, reserve actual rich/plain draft and typing requests against normalized per-chat 20/5s and 40/30s windows, and retain native transport duringRetryAfter.plugins/platforms/telegram/adapter.py: use the extracted mixin and the shared quota for typing; omit redundant typing while a recent native draft is visible.Design / Thinking
The user's local A/B prototypes throttled ordinary editable previews to 30 characters/second. The second replayed all remaining text after generation, making long answers slow. They are preserved locally for rollback and are not included in this PR.
The chosen design separates receiving content from displaying it, as client-side streaming interfaces do: retain the latest cumulative text and delegate character animation to Telegram. It adds no fixed character playback cap or completion drain. Raising ordinary edit frequency alone would still show discrete snapshots and would spend a different send/edit allowance.
A quota deferral returns a marked skipped result, not a delivered frame. A genuine endpoint rejection still uses the existing edit fallback. The complete final bypasses preview-only cooldown and uses the existing MarkdownV2/Rich Message renderer.
References: Telegram streaming and shared action quotas, sendMessageDraft.
How to Test
Result
Before: on pristine base
3b4a8911741a, the three added regression files yield 13 failing and 2 passing tests, covering cadence, prefix rewrites, UTF-16 length, shared quota, and cooldown handling.After:
tests/gateway/test_telegram_thread_fallback.py::test_send_image_upload_fallback_blocks_connect_time_rebindfails identically on pristine base and the changed branch; the initial broader run had 273 passes and that one failure. No image-upload behavior is changed here.python scripts/check: 11 checks passed, no blocking/advisory health findings.Run the focused contracts through the canonical isolated runner:
To inspect the UI, enable
streaming.enabled: true,streaming.transport: draft, andedit_interval: 0.8for a private chat, restart the gateway, and request a multi-paragraph reply containing code. Compare growing text and the completed formatted message. Usetransport: editfor a client that renders native drafts poorly.Trade-offs
Plain previews display raw Markdown temporarily; the persistent final keeps existing formatting. Telegram owns animation, so the transport tests cannot prove identical smoothness across clients. Drafts remain private-chat-only and preview text is length-bounded; the existing final delivery retains the full answer. No model, prompt, or generation-budget change is introduced by this diff.
Follow-up
Compare native animation on the user's actual Telegram client. Immediate status/activity indicators are outside this change. Ordinary edit cadence and default selection remain with the related PRs above.
Checklist
Code
python scripts/checkpassesDocumentation & Housekeeping
Screenshots / Logs
Only deterministic fake-transport receipts and sanitized deployment state are summarized above. Credentials, private conversations, and local configuration backups are excluded.