fix: collapse tool calls during streaming to prevent truncation hiding agent text#253
Merged
thepagent merged 2 commits intoopenabdev:mainfrom Apr 15, 2026
Merged
Conversation
…g agent text - Add streaming mode to compose_display() that collapses finished tool entries into a summary line when count exceeds TOOL_COLLAPSE_THRESHOLD (3). Threshold justified: 3 lines ≈ 120-240 chars (6-13% of 1900-char budget), also the practical 'glanceable' limit. - Running tools shown individually; guarded with same threshold for parallel tool call edge case (shows last N + '🔧 X more running'). - Tail-priority truncation as defense-in-depth: streaming edit keeps last 1900 chars instead of first, with '…(truncated)' indicator. - Final message uses full expansion (non-streaming) since split_message() handles multi-message delivery without truncation risk. - Added 7 unit tests covering threshold boundary, mixed completed/failed counts, parallel running guard, non-streaming mode, and multi-byte character safety. Fixes openabdev#242
14e8bec to
d083496
Compare
thepagent
approved these changes
Apr 15, 2026
This was referenced Apr 15, 2026
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.
Summary
Fixes #242 — streaming truncation hides agent interaction prompts, causing thread deadlock.
Changes
Single file:
src/discord.rs+ removal of unusedtruncate_charsinsrc/format.rs1. Threshold-based tool collapsing in
compose_display()Added a
streamingmode that collapses finished tool entries when count exceedsTOOL_COLLAPSE_THRESHOLD(3):✅ N tool(s) completed(one line)✅ 3 · ❌ 2 tool(s) completed🔧 N more running)Why 3? A tool line averages 40–80 chars. 3 lines ≈ 120–240 chars = 6–13% of the 1900-char budget, leaving 1660+ for agent text. Also the practical "glanceable" limit.
2. Tail-priority truncation (defense-in-depth)
Streaming edit now keeps the last 1900 chars instead of the first, with
…(truncated)indicator. Even if collapsing isn't enough, the user always sees the most recent agent output.3. Final message unchanged
Final edit uses full expansion (
streaming: false) —split_message()handles multi-message delivery, so truncation isn't a risk. Collapsing is only for the streaming phase.Test results
7 new unit tests added (33 total, all passing):
Screenshots
2 tools — individual display (below threshold):
15 tools — collapsed + agent text visible:
18 tools — collapsed: