Telegram tool-call output is unreadable: preview picks one arbitrary line and strips all context #1485

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

Operator report: 'the output is just horrendous' in the Telegram channel, during turns that run search/read tools.

Observed shape (pasted from Telegram):

\U0001f527 grep — done
```text
/home/sam/.claude/config.json-322-          }
… 194 more lines
```

Reproduced the renderer directly (internal/gateway/stream.go, toolProgressBlock/toolPreview/compactToolPreview). One tool call renders as 86 runes containing NO usable information: a file path, a line number, and a stray closing brace, wrapped in a fenced block under a heading that says only 'grep — done'.

Root causes, all in the render path rather than the transport:

  1. compactToolPreview returns the FIRST line that is not a /pkg/mod/ path, truncated to 120 runes. For grep/find output the first line is an arbitrary match, not a summary. Nothing states what was searched or how many results matched.

  2. The '… N more lines' suffix recomputes N as countNonEmptyOrContentLines(content)-1-skipped, which does not equal what the tool itself already reported. The example above shows the tool saying '194 more lines' and the rendered line saying '… 5 more lines' -- two different numbers for the same result set, so both read as noise.

  3. Every tool call contributes one such block, joined with a blank line. 14 calls measured 1043 runes: the tool block alone consumes ~27% of liveBodyMaxRunes (3900) and grows unbounded within a turn (toolLines has no cap, unlike answerBuf). A tool-heavy turn therefore crowds out the answer and produces a wall of near-identical fenced blocks.

  4. There is no aggregation. 14 sequential calls to the same tool render as 14 separate blocks rather than one summarised entry ('grep ×14, 312 matches'), despite failureLines/failureCounts already implementing exactly that collapse for REPEATED FAILURES.

Direction (see also go-telegram/bot's streaming_draft and edit_message examples, and how our own live.go chose edit-over-draft):

  • Summarise rather than quote: tool name + a count or a one-line description of the result, not a raw match line.
  • Reconcile the two line counts, or drop the tool-reported count and use only our own.
  • Cap and collapse repeated tool calls into one counted entry, the way failures already collapse.
  • Consider collapsing the tool block itself (e.g. an expandable summary) so a tool-heavy turn cannot crowd out the answer.

Note: live.go:54 documents that streaming previously used sendMessageDraft and moved to EditMessageText because drafts are 30-second ephemeral previews. Our lib (go-telegram/bot v1.25.0) does expose SendMessageDraft; the example uses it deliberately with a final SendMessage to settle the message. Worth a re-look now that the concatenation bug is gone, but that is a separate transport question from the rendering defect above.

Close reason

Fixed by PR #838 (884fcd0): arbitrary preview line + contradictory counts. Title defect resolved; two remaining causes split into GitHub #839 (uncapped tool block) and #840 (success collapse).


Imported from beads archie-core-o6w3 · GitHub #837 · type bug · priority P2 · created 2026-09-17 · closed 2026-09-17

Operator report: 'the output is just horrendous' in the Telegram channel, during turns that run search/read tools. Observed shape (pasted from Telegram): \U0001f527 grep — done ```text /home/sam/.claude/config.json-322- } … 194 more lines ``` Reproduced the renderer directly (internal/gateway/stream.go, toolProgressBlock/toolPreview/compactToolPreview). One tool call renders as 86 runes containing NO usable information: a file path, a line number, and a stray closing brace, wrapped in a fenced block under a heading that says only 'grep — done'. Root causes, all in the render path rather than the transport: 1. compactToolPreview returns the FIRST line that is not a /pkg/mod/ path, truncated to 120 runes. For grep/find output the first line is an arbitrary match, not a summary. Nothing states what was searched or how many results matched. 2. The '… N more lines' suffix recomputes N as countNonEmptyOrContentLines(content)-1-skipped, which does not equal what the tool itself already reported. The example above shows the tool saying '194 more lines' and the rendered line saying '… 5 more lines' -- two different numbers for the same result set, so both read as noise. 3. Every tool call contributes one such block, joined with a blank line. 14 calls measured 1043 runes: the tool block alone consumes ~27% of liveBodyMaxRunes (3900) and grows unbounded within a turn (toolLines has no cap, unlike answerBuf). A tool-heavy turn therefore crowds out the answer and produces a wall of near-identical fenced blocks. 4. There is no aggregation. 14 sequential calls to the same tool render as 14 separate blocks rather than one summarised entry ('grep ×14, 312 matches'), despite failureLines/failureCounts already implementing exactly that collapse for REPEATED FAILURES. Direction (see also go-telegram/bot's streaming_draft and edit_message examples, and how our own live.go chose edit-over-draft): - Summarise rather than quote: tool name + a count or a one-line description of the result, not a raw match line. - Reconcile the two line counts, or drop the tool-reported count and use only our own. - Cap and collapse repeated tool calls into one counted entry, the way failures already collapse. - Consider collapsing the tool block itself (e.g. an expandable summary) so a tool-heavy turn cannot crowd out the answer. Note: live.go:54 documents that streaming previously used sendMessageDraft and moved to EditMessageText because drafts are 30-second ephemeral previews. Our lib (go-telegram/bot v1.25.0) does expose SendMessageDraft; the example uses it deliberately with a final SendMessage to settle the message. Worth a re-look now that the concatenation bug is gone, but that is a separate transport question from the rendering defect above. ### Close reason Fixed by PR #838 (884fcd0): arbitrary preview line + contradictory counts. Title defect resolved; two remaining causes split into GitHub #839 (uncapped tool block) and #840 (success collapse). --- _Imported from beads `archie-core-o6w3` · GitHub #837 · type bug · priority P2 · created 2026-09-17 · closed 2026-09-17_
sam added the mediumbug labels 2026-10-27 13:40:35 +00:00
sam self-assigned this 2026-10-27 13:40:35 +00:00
sam closed this issue 2026-10-27 13:40:35 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#1485