feat(gateway): stream Telegram edits safely — salvage of #22264#22518
Merged
Conversation
Nikita Nosov (nik1t7n, PR #22264) — first-time contributor email and noreply alias.
Contributor
🔎 Lint report:
|
| Rule | Count |
|---|---|
invalid-argument-type |
3 |
First entries
run_agent.py:6822: [invalid-argument-type] invalid-argument-type: Argument to function `build_anthropic_client` is incorrect: Expected `str`, found `str | dict[Unknown, Unknown] | Any | ... omitted 3 union elements`
run_agent.py:12818: [invalid-argument-type] invalid-argument-type: Argument to function `_is_oauth_token` is incorrect: Expected `str`, found `str | dict[Unknown, Unknown] | Any | ... omitted 3 union elements`
run_agent.py:12821: [invalid-argument-type] invalid-argument-type: Argument to function `len` is incorrect: Expected `Sized`, found `(str & ~AlwaysFalsy) | (dict[Unknown, Unknown] & ~AlwaysFalsy) | (Any & ~AlwaysFalsy) | ... omitted 3 union elements`
✅ Fixed issues (3):
| Rule | Count |
|---|---|
invalid-argument-type |
3 |
First entries
run_agent.py:6822: [invalid-argument-type] invalid-argument-type: Argument to function `build_anthropic_client` is incorrect: Expected `str`, found `str | dict[Unknown | str, Unknown | str | dict[str, str]] | Any | ... omitted 3 union elements`
run_agent.py:12821: [invalid-argument-type] invalid-argument-type: Argument to function `len` is incorrect: Expected `Sized`, found `(str & ~AlwaysFalsy) | (dict[Unknown | str, Unknown | str | dict[str, str]] & ~AlwaysFalsy) | (Any & ~AlwaysFalsy) | ... omitted 3 union elements`
run_agent.py:12818: [invalid-argument-type] invalid-argument-type: Argument to function `_is_oauth_token` is incorrect: Expected `str`, found `str | dict[Unknown | str, Unknown | str | dict[str, str]] | Any | ... omitted 3 union elements`
Unchanged: 4171 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
23 tasks
1 task
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.
Summary
Salvage of #22264 by @nik1t7n — cherry-picked onto current
mainwith authorship preserved, plus AUTHOR_MAP entry.What this PR does
Makes non-final Telegram streaming edits (
edit_message) send content as plain text instead of going throughformat_message()+ MarkdownV2. During token-by-token streaming, partial markdown (e.g.,**boldwithout closing**) frequently triggers Telegram's MarkdownV2 parser rejection. The old code would catch the rejection, then retry as plain text — doubling API calls per intermediate edit with zero benefit.The fix: intermediate edits (
finalize=False) bypassformat_message()andparse_mode=MarkdownV2, sending content directly as plain text. Final edits (finalize=True) still go through the full MarkdownV2 + fallback-to-plain path, preserving rich formatting for the completed message.How this was verified
finalize=FalseIS passed by the streaming consumer (stream_consumer.py:926-930) — the PR code path is actively exercised, not dead code.format_message()does only MarkdownV2 conversion + character escaping — no sanitization, truncation, or routing logic is skipped.try/exceptas the old path, somessage_too_long, flood control, and generic errors are handled identically.send_progress_messagesingateway/run.py:13472and_try_strip_cursor/_send_fallback_finalinstream_consumer.pyalso take the plain-text path — all correct since they send status lines / cursor-stripped already-rendered text.Diff
gateway/platforms/telegram.py+8,tests/gateway/test_telegram_format.py+41,cli-config.yaml.example+120nik.nosov21@gmail.comand90299797+nik1t7n@users.noreply.github.com→nik1t7nTest plan
bash scripts/run_tests.sh tests/gateway/test_telegram_format.py→ 90 passedCloses
Closes #22264.
Credit to @nik1t7n (Nikita Nosov) for the fix.