telegram: escape tool output before composing it into the rich Markdown body #1126

Closed
opened 2026-10-27 13:39:07 +00:00 by sam · 0 comments
Owner

The tool line (🔧 name + params + ' — ' + Summary()) is composed unescaped into the same InputRichMessage{Markdown: body} as the model reply (live.go:172). Summary() returns the tool's raw first output line (no escaping), and the JSON params can carry '*' / '_' / backticks. A single stray markdown metacharacter unbalances the rich body: mid-stream it lags a frame, but in the final message the rich edit is rejected and the plain-text fallback is terminal — permanently stripping the model reply's markdown formatting. go-telegram/bot v1.23.0 ships EscapeMarkdown; nothing in the repo uses it.

Failure: the shell tool prints a grep hit containing '*' or '_'; the finished answer's bold/italic/code blocks render as raw markers, and the tool line itself displays as broken markup.

Design

Escape the tool name/params/summary (or the whole tool line) before inserting it into the Markdown body, while preserving the model reply's own markdown — the two share one body, so escaping must be scoped to the tool line only.

Acceptance criteria

A tool whose output contains *, _, or backticks does not break the final message's markdown; a test feeds such output through a live reply and asserts the finished body still renders.

Close reason

Fixed in internal/channels/telegram/live.go and telegram.go: finalize/abandon strip context cancellation before sending (mirroring each other), ToolCall escapes Markdown metacharacters via bot.EscapeMarkdown, splitLongMessage splits on rune boundaries. All new/changed tests verified red-then-green; task check clean; adversarial review pass found no blocking issues.


Imported from beads archie-core-7o11 · GitHub #483 · type bug · priority P1 · created 2026-08-14 · closed 2026-08-14

The tool line (🔧 name + params + ' — ' + Summary()) is composed unescaped into the same InputRichMessage{Markdown: body} as the model reply (live.go:172). Summary() returns the tool's raw first output line (no escaping), and the JSON params can carry '*' / '_' / backticks. A single stray markdown metacharacter unbalances the rich body: mid-stream it lags a frame, but in the final message the rich edit is rejected and the plain-text fallback is terminal — permanently stripping the model reply's markdown formatting. go-telegram/bot v1.23.0 ships EscapeMarkdown; nothing in the repo uses it. Failure: the shell tool prints a grep hit containing '*' or '_'; the finished answer's bold/italic/code blocks render as raw markers, and the tool line itself displays as broken markup. ### Design Escape the tool name/params/summary (or the whole tool line) before inserting it into the Markdown body, while preserving the model reply's own markdown — the two share one body, so escaping must be scoped to the tool line only. ### Acceptance criteria A tool whose output contains *, _, or backticks does not break the final message's markdown; a test feeds such output through a live reply and asserts the finished body still renders. ### Close reason Fixed in internal/channels/telegram/live.go and telegram.go: finalize/abandon strip context cancellation before sending (mirroring each other), ToolCall escapes Markdown metacharacters via bot.EscapeMarkdown, splitLongMessage splits on rune boundaries. All new/changed tests verified red-then-green; task check clean; adversarial review pass found no blocking issues. --- _Imported from beads `archie-core-7o11` · GitHub #483 · type bug · priority P1 · created 2026-08-14 · closed 2026-08-14_
sam added the highbug labels 2026-10-27 13:39:07 +00:00
sam self-assigned this 2026-10-27 13:39:07 +00:00
sam closed this issue 2026-10-27 13:39:07 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#1126