Repository navigation
fix: format telegram mirrored replies, results and notices - #47866
winnythedev wants to merge 2 commits into
Conversation
The dashboard reply mirror, the cron and sub-agent completion leg and the compaction notice share messaging.egress, whose send step called the plain transport.send_message. Their text is the agent's own markdown, so on Telegram bold, inline code, fences and links arrived literally, while a reply to a message typed in Telegram arrives formatted. send_channel_parts now calls transport.send_markdown. Telegram's override renders to Telegram HTML, re-splits by rendered length and falls back to the plain send on a refusal or an over-cap render; every other transport inherits the base send_markdown, which is its send_message, so their bytes are unchanged. The test doubles that define only send_message get the same delegator real transports inherit, and the messaging spec says which legs call send_markdown. Fixes #47832
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. The change adds one opt-in flag to the existing egress step and reuses the guarded [DESIGN-REVIEWED] 74d6329 Description read[DESCRIPTION-READ] a3739956a32debed53b0cca457ca7319e85a4d75f022ea5231ed0c6d726e0778 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The fix routes agent markdown through the existing Notes
What this change shipsInventory (6 items) — 6 justifiedIntent: Telegram users get agent replies, results and notices that arrive with no renderer formatted, not as raw markdown. This is a FIX (#47832, with tests that fail on base).
[FIRST-PRINCIPLES-REVIEWED] 74d6329 Description read[DESCRIPTION-READ] 024008241a56c6f24505c8548cdd1790a74ed98c1e006dd38fbe58276316268d That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Review detailsNo findings. Notes:
[OPUS-REVIEWED] 74d6329 Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
A cron failure alert's plain twin reaches send_channel_parts through the same origin leg as an agent's result, so rendering every part as markdown rewrote a traceback on Telegram: __init__ turned bold and 2**10 lost its stars. send_channel_parts now takes markdown (default False). The reply mirror, an agent's cron result, a sub-agent completion and the fixed compaction notice pass True; failure, crash and pause alerts, task-run and approval notices, the memory-guard notice and the mirror's image notes keep send_message and arrive as written. A cron's pinned destination honours the same flag. Refs #47832
|
Problem / Motivation
Goal: On Telegram, a dashboard reply mirrored to a linked chat, a cron or sub-agent result and a compaction notice arrive formatted, like a reply to a message typed in Telegram, instead of as raw markdown.
Today those messages show
**bold**, backticks, code fences and[text](url)literally on Telegram. The same Bot's reply to a message typed in Telegram arrives formatted, because the Telegram reply renderer converts it to Telegram HTML.Root cause: the dashboard reply mirror (
_deliver_cross_surface_reply), the completion leg for cron, sub-agent and task-run output (_deliver_channel_reply) and the compaction and memory-guard notices all end insend_channel_parts(src/kiro_crew/messaging/egress.py). That function always calledtransport.send_message, the plain send, which passes noparse_modeon Telegram.Why it matters
Anyone who links a Telegram chat to a dashboard session, or gets cron and sub-agent results in Telegram, reads every one of those messages with the markup showing. Code blocks and links are the hardest to read, and those are common in agent output.
Not a goal
TelegramTransport.send_markdownitself or the Telegram renderer.send_messagetool'sformatoption. Plain stays its default.transport.send_messagedirectly: the mirror-link backfill of past answers, the disconnect note and the user-message echo.send_markdown.What changed (motivation → approach → change)
send_channel_partsused the plain send for everything. A guarded markdown send already exists:TelegramTransport.send_markdownconverts withmd_to_telegram_html_safe, sendsparse_mode=HTML, re-splits by rendered length and falls back to the plain send on a 400 or an over-cap render. The proactivesend_messagetool already uses it forformat="markdown".send_channel_partstakesmarkdown(defaultFalse). With it, each part goes throughtransport.send_markdown; without it, throughsend_messageas before. Every other transport inheritsMessagingTransport.send_markdown, which is itssend_message, so only Telegram's output changes. No second markdown path is added.markdown=True):_deliver_cross_surface_reply), the reply text only;subagent_injection->_deliver_channel_reply);_deliver_cron_agent_result) and a cron's post-sub-agent response (_deliver_cron_response), through_deliver_cron_to_channel(markdown=True), which honours the flag on the origin leg and on a job's pin (_send_to_channel_target(markdown=...));_deliver_via_transportwhen it renders its own wording).cron_failure.py), cron reminders, script and command output, task-run and approval notices (service_boot.py), the memory-guard notice (deliver_channel_text) and the mirror's image notes. A traceback or stderr there arrives as written._deliver_channel_replyand_deliver_cron_to_channelcarry the flag down (defaultFalse); their pinned signatures intest_slack_gateway_composition_contract.pyare updated.egress.pymodule docstring and the owning specs say so: the "Markdown send" bullet and two wording fixes indocs/system-specs/modules/messaging.md, and the_deliver_channel_replychain indocs/system-specs/modules/subagent.md.Backwards compatibility
Compatible: every leg's default is the plain send it used before, so host text is unchanged everywhere. On every channel except Telegram,
send_markdownissend_messagewith the same arguments, so the bytes sent are unchanged on the markdown legs too. On Telegram a refused or over-cap render falls back to the plain send that went out before. A timeout or 5xx on the HTML send reports the part unconfirmed, as the plain send did, sorequire_confirmationstill stops a half-delivered message.Removes nothing: the change adds an opt-in keyword to one send step and its two carriers; no path, key, record or public function is hidden, renamed or deleted.
Tests
test/test_mirror_telegram_markdown.py(new) drives the real legs against the realTelegramTransportandTelegramClient, with only the Bot API faked on loopback (telegram_wire_helpers), plus the cron orchestrator with a double whose two sends are separate mocks. It checks:_and a fence holding<dir>goes out as the exact Telegram HTML withparse_mode=HTML;**or fences;markdown=Truesends the same text as a directsend_markdown;__init__and2**10) reaches Telegram byte for byte with noparse_mode;parse_mode=HTML, and memory-guard text on the same leg goes out as written;send_markdown, on the origin leg and on a job's pinned destination;_deliver_failure_alertreachessend_messagebyte for byte and neversend_markdown, on the origin leg and on a pin.test_slack_gateway_subagent_delivery.pygains a test that a sub-agent's synthesized reply takessend_markdown.send_messageget the one-linesend_markdowndelegator real transports inherit. Two negative-assert doubles (test_autonudge_firing.py,test_cron_channel_target.py) share one mock for both sends, so their "nothing was sent" asserts still catch a regression; the autonudge double also admits the peer so only the capability refusal can stop the send (checked by disabling that refusal: the test goes red).Proof: PROVEN test/test_mirror_telegram_markdown.py::test_mirrored_reply_is_sent_as_telegram_html, test/test_mirror_telegram_markdown.py::test_prose_around_a_mirrored_table_is_formatted, test/test_mirror_telegram_markdown.py::test_a_long_mirrored_reply_keeps_every_part_formatted, test/test_mirror_telegram_markdown.py::test_the_compaction_notice_is_sent_as_markdown, test/test_mirror_telegram_markdown.py::test_a_cron_agent_result_is_sent_as_markdown (head 74d6329)
Manual verification
N/A: no live Telegram account and no gateway were used. The Telegram Bot API is faked on loopback and the real transport and client run against it, which is the surface the fix changes. No live dashboard run was done.
Real-machine verification
Machine: Linux x86_64, local developer host, pytest with the Telegram Bot API faked on loopback (no live Telegram account, no gateway).
Before (main 8aecf44):
python -m pytest -q -n 0 test/test_mirror_telegram_markdown.py(first four tests) ->4 failed, e.g.assert [None] == ['HTML']and the raw**Done.** Theretryflag ...text handed to the Bot API.After (head 74d6329):
python -m pytest -q -n 0 test/test_mirror_telegram_markdown.py->12 passed.Cleanup: own host; nothing to tear down (loopback servers close with each test).
Related Issues
Fixes #47832
Overlap: no other open PR changes
src/kiro_crew/messaging/egress.pyexcept #12829 (autonomous goal suggestions), which touches a different part of it. Several open PRs edit other sections ofdocs/system-specs/modules/messaging.md(#47847, #47842, #47805, #47772, #47358, #46931) anddocs/system-specs/modules/subagent.md(#47837, #47739, #47719, #46712, #46706); this PR changes single lines there, so whichever lands second rebases. Our #47847 (iMessage spaced asterisks) also editsmessaging.md, in the iMessage section.Sibling sweep
Swept:
git grep -n 'send_channel_parts\|_deliver_channel_reply(\|_deliver_cron_to_channel(' src/Sibling: src/kiro_crew/dashboard/chat_turn/recipient.py -- changed here -- reply passes markdown=True, image notes stay plain
Sibling: src/kiro_crew/slack/gateway_runtime/subagent_injection.py -- changed here -- sub-agent completion passes markdown=True
Sibling: src/kiro_crew/slack/gateway_runtime/cron_delivery.py -- changed here -- LLM cron result passes markdown=True; the reminder stays plain
Sibling: src/kiro_crew/slack/gateway_runtime/result_egress.py -- changed here -- post-sub-agent cron response passes markdown=True
Sibling: src/kiro_crew/dashboard/chat_compaction_notice.py -- changed here -- fixed notice renders, caller text stays plain
Sibling: src/kiro_crew/slack/gateway_runtime/cron_failure.py -- not affected -- failure, crash and pause alerts keep the plain default
Sibling: src/kiro_crew/slack/gateway_runtime/cron_exec.py -- not affected -- script and command output keep the plain default
Sibling: src/kiro_crew/slack/gateway_runtime/service_boot.py -- not affected -- task-run and approval notices keep the plain default
Pattern harvest
Not generalizable: the markdown send already existed and was opt-in by design for the proactive tool; this leg now opts in per caller, at the one send step, with plain as the default.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commitsReview (multi-model interrogate)
First push: independent reviewers read the full diff. Found and fixed: two negative-assert test doubles that would have passed vacuously after the switch; a stale
send_messagename for this leg insubagent.mdand in twomessaging.mdsentences; docstring and spec wording about which text on the leg is markdown. Dismissed: one reviewer read the late-binding lambda delegator as capturingsend_messageearly (it resolves the attribute at call time); one flagged the new test's imports as unverified (they resolve and the test runs).This push answers the CI Opus lane's block: a cron failure alert's plain twin rode the same origin leg and was rendered as markdown. The flag now defaults to the plain send and only agent-authored text and the fixed compaction notice opt in. A re-check of the repair found and this push fixes: a job's pinned destination ignored the flag (agent results there were still plain), the sub-agent and post-sub-agent cron legs had no test that fails when their flag is dropped, one spec sentence and one comment. Accepted, not changed: the
Cron: <name>caption and fixed refusal or warning lines ride the markdown leg with the agent's result, so a job named__x__would show bold; they hold no traceback (raised errors go to the plain failure alert).Local gate: black, isort, flake8, comment-history, brand, agent-SDK boundary, file-line cap, docs-lint, flake-pattern ratchet, wait-discipline ratchet (with the new test) and semgrep 1.78.0 pass; the 97 related test files pass (2,109 and 1,772 passed, 1 skipped).
scripts/local-gate.py --tree-scansran its related set to green on the first commit (20,273 passed, 27 skipped); its whole-tree guard pass was still running on a shared host and is left to CI. On the repair: the 97 related files passed before its last fix (2,160 and 1,772 passed, 1 skipped); on this head the six files that fix touches or exercises (494 passed),test/test_facade_mirror_guards.py, the wait and flake ratchets, semgrep and docs-lint pass. mypy reports six errors in files this PR does not touch (missing third-party stubs, an aiohttp generic), from the local venv's site packages.Base reds: main is red since 695f379 (#47829, the settings registry's guidable flag): Build Wheel, Build Desktop, E2E shards, Frontend Tests (settingsRegistry.test.ts), Backend Tests (3.12, 3) and Coverage Gate are expected red on this merge ref and are not caused by this diff.
Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license.