fix(telegram): send_clarify budgets the HTML-escaped rendering - #115533
Open
EloquentBrush0x wants to merge 1 commit into
Open
EloquentBrush0x wants to merge 1 commit into
EloquentBrush0x wants to merge 1 commit into
Conversation
send_clarify escaped the question and each choice individually with no total length budget, unlike the exec-approval and slash-confirm cards fixed earlier today (b502504, edd9fd6). A long, model-controlled question or many/long choices can expand past Telegram's 4096-char cap once HTML-escaped, and Telegram answers "Message is too long" instead of sending the prompt at all — the same failure mode those two cards were just fixed for. Reuses the shared _ea_fit bisection (gateway/platforms/base.py) the same way send_slash_confirm does, including reserving budget for both the header and _ea_fit's own "..." truncation suffix (which rides outside the budget it's given, per its docstring) — an oversight caught by the new tests before this was accounted for. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Contributor
|
Independent verification on the PR head (c8684b2): clarify-buttons suite 7/7 green on Linux. Budgeting the escaped rendering (not the raw text) is the correct measuring point: escaping only expands, so raw budgeting undercounts exactly when it matters, and matching the exec-approval cards keeps one policy. No findings. |
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?
send_clarifyescapes the question and each choice individually with no total length budget on the rendered card. Earlier today two sibling prompt cards were fixed for the exact same failure mode:_send_exec_approval_prompt(b502504) andsend_slash_confirm(edd9fd6) both now budget their HTML/MarkdownV2-escaped rendering against Telegram's 4096-char cap using the shared_ea_fitbisection — because escaping expands text (&→&,<→<), a raw-length cut (or no cut at all) can still overflow the cap after escaping, and Telegram answers "Message is too long" instead of delivering the prompt.send_clarifynever got the same treatment. A long, model-controlled clarify question or many/long choices (tools/clarify_tool.pyplaces no upstream length limit on either) can overflow the cap the same way, silently failing to deliver the clarify prompt.Related Issue
None found. Related but non-overlapping: open PR #111093 explicitly scopes itself to "Slack, Discord, Google Chat and the relay" for a different readability concern (long choices becoming unreadable, not exceeding a hard length cap) and its file list confirms it never touches
plugins/platforms/telegram/adapter.py.Scope note: open PR #104081 touches the same
send_clarify.build()function (replacingstr(c)with achoice_label(c)helper to support{label, description}choice objects) — same lines, unrelated concern, no semantic conflict. Applying itschoice_label()extraction on top of this PR'sbody-based restructuring is a one-line change (swapcforchoice_label(c)in the choice-joining comprehension); this PR does not depend on or block that one.Type of Change
Changes Made
plugins/platforms/telegram/adapter.py—send_clarify: question + choices are now assembled as one rawbody, fit through the shared_ea_fitbisection (same helpersend_slash_confirmuses) measured after HTML-escaping, then escaped once. Budget reserves room for both the"❓ "header and_ea_fit's own"..."truncation suffix (which rides outside the budget it's given, per its docstring) — this reservation was missing from my first pass and caught by the new tests before commit.tests/gateway/test_telegram_clarify_buttons.py— new: an oversized escaped choice-set test and an emoji-dense (UTF-16 unit) test, mirroring the sibling tests intest_telegram_approval_buttons.py.How to Test
pytest tests/gateway/test_telegram_clarify_buttons.py -v→ 7 passedpytest tests/gateway/test_telegram_approval_buttons.py tests/gateway/test_telegram_error_redaction.py -q→ 21 passed6009 <= 4096assertion, i.e. the unbudgeted card is ~1.5x the cap), confirming they exercise the real defect.Checklist
Code
Documentation & Housekeeping
cli-config.yaml.example— N/ACONTRIBUTING.md/AGENTS.md— N/A🤖 Generated with Claude Code