Repository navigation
fix(telegram): preserve long replies and bound chunk retries - #3747
Conversation
|
merge-train: held back from today's train. Thanks for this; the fix is sound, the splitter also fixes an existing hang on nested markup, and 31 of the 51 new tests fail on
Minor: log |
|
@vybe Addressed in 6055cfdb9, with a caller-level regression/clarification in e1957b7d4:
165 affected checks passed, plus a new full-caller regression for existing automatic channel fallback. Independent review found no remaining blocking source finding. The docs now explicitly limit no-replay to the Telegram channel attempt: auto mode can resend the complete message through another channel after a partial Telegram send. Live Telegram acceptance remains unverified. Please re-review the updated head when convenient. |
obasilakis
left a comment
There was a problem hiding this comment.
Review + validate-pr: approve. No blockers. CI green, no conflicts against current dev.
The three points from the 2026-10-17 review are fixed: the 30s wait cap is restored and longer or malformed waits fail without retrying, the dead sendDocument path is gone, and the API description is logged with the token and URLs redacted.
Execution coverage. Each source file reverted on its own, then tests/unit/test_3746_telegram_long_replies.py re-run:
message_router.pyreverted: 7 tests fail.telegram_adapter.pyreverted: 17+ tests fail, thentest_large_nested_markup_falls_back_without_loopinghangs in the old_split_message. Reopening 1500<b>tags makes each remainder longer than the chunk it removed, which is thedevbug this PR fixes. That test has no timeout, so a regression shows up as a hung CI job. Apytest.mark.timeout(or running the split in a thread with a deadline) would make it fail fast.proactive_message_service.pyreverted: 3 tests fail.
249 related Telegram, proactive, completion-report and router tests pass.
Non-blocking, all in src/backend/adapters/telegram_adapter.py
_send_message, bareexcept Exception:: the log line is fixed text and drops the exception, so aKeyError, a non-JSON 5xx body and a timeout all look the same. Logtype(e).__name__; that keeps the token out and says what failed._send_message:body = resp.json()runs before the status check, so a non-JSON error page (a proxy's HTML 502) throws before the status is logged. Parse in a try with a{}fallback, and logresp.status_code._split_message, "cut landed inside a tag" fallbacksplit_at = limit:limitcounts UTF-16 units and is used here as a character index, so emoji-heavy text can overshoot. Theunits(chunk) > MAXcheck catches it and falls back to plain text, so nothing is lost. Reuse the UTF-16-slicedsplit_atcomputed above.
Info
4. Proactive auto mode re-sends the whole message through Slack or web after a partial Telegram failure. The docs and PR body say so.
Fixes #3746.
The shared router extracts recognized fenced blocks into files and replaces their contents with
(see attached: response_1.txt). Telegram ignores those files and sends only the reference. A 6,000-character fenced reply reproduces the loss on unmodified official dev77d98132b55594cd47dcb31334104581ac54f0fa.Telegram now keeps reply code blocks inline and splits them in order. Slack and WhatsApp retain their existing file extraction. The splitter preserves HTML entities and open formatting tags, uses a conservative UTF-16 budget including markup, and drops pathological formatting when necessary to preserve text. No document-upload subsystem is added.
Each chunk requires an acknowledged message ID. A single rate-limit retry honors waits of 0–30 seconds; longer or malformed waits stop delivery without retrying early. HTML parse failures fall back to plain text, which can still use that chunk's one rate-limit retry. An unconfirmed chunk stops both ordinary replies and proactive sends; proactive delivery reports failure instead of treating a later successful chunk as complete delivery. Safe API reasons remain in logs with token and URL removal; request exceptions containing URLs are not logged.
Validation against official dev
c0ba81e16:Confirmed chunks are not replayed within one Telegram channel attempt. This does not add durable per-chunk deduplication: a separate retry or crash recovery retains the existing effect-level behavior and can repeat earlier chunks. Automatic proactive channel selection retains its existing fallback: after a partial Telegram failure, it can send the full message via Slack or web within the same call; only the successful channel is persisted in outbound history. A new caller-level regression verifies this policy. Fresh independent review found no new blocking source defect; this limitation is explicit rather than an exactly-once claim. Full upstream CI for the new revision remains pending.
Journey Impact: none: Telegram long-reply delivery is not represented in the current journey catalog.
Mutation: the stock router emits only the attachment reference for the 6,000-character fenced reply; the patched router delivers its full content. New bounded-wait and proactive partial-delivery regressions fail on the preceding PR head and pass after correction.