fix(chat): render correct line count under each parallel bash marker#4010
Merged
Conversation
Back-to-back tool dispatches with DeepSeek-style call_N ids rendered
the second and subsequent markers as '⎿ -1 lines' (or, with a prior
defensive guard, a blank slot) because:
* streamToolOutput resets m.toolLineCount whenever it switches to a
new tool id, losing the previous id's count.
* collapseShellSlot's late path was the only place the count could be
recovered, and it derived it from m.shellOutputs[id] — which is
only populated for shell-prefixed ids (string-gated at the
streamToolOutput write site). call_N ids never made it into the
map, so n fell through to -1.
Fix:
* Add a per-id line-count stash (m.toolLineCountByID). When
streamToolOutput is about to switch active id, it captures the
current (toolLineCount + (toolPartial != '')) so the old id's
value survives.
* Thread the ToolResult's final output through collapseToolOutput
and collapseShellSlot as a last-resort source of truth for the
line count. This handles a tool that never streamed (the result
is the only signal) and lets the active path use the larger of
the live line count and the final output (so a slow tool's last
chunk arriving in the same event as the result isn't lost).
* collapseShellSlot's late path now falls back through
shellOutputs -> toolLineCountByID -> resultOutput -> 0, and the
n<0=0 guard replaces the previous '⎿ -1 lines' rendering.
Regression coverage (internal/cli/consecutive_tool_markers_test.go):
* TestParallelBashMarkersKeepOwnLineCount: 3 parallel Bash(ls)
dispatch with 22 lines of streaming output each, verifying each
card's marker slot reports '⎿ 22 lines' and the transcript
contains no '-1 lines'.
* TestNonShellToolLateResultShowsCorrectCount: 2 back-to-back bash
tools with no ToolProgress between them, verifying the result's
own output drives the marker line count.
The new fields are initialized in newChatTUI and the test helper
newTestChatTUI.
Re-align the toolLineCountByID struct field (gofmt) and compress the multi-line collapse/streaming comments to one-line whys. No logic change.
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.
Parallel
call_N-style bash tools (DeepSeek schedules several in one turn) werelosing their per-call line count:
streamToolOutputreset the active id'stoolLineCounton every switch, andcollapseShellSlot's late path could onlyrecover it from
shellOutputs, which is populated for"shell-"ids only. Forcall_Nids the count fell through to-1, so each card rendered⎿ -1 lines(or a blank slot) instead of its real count.
Fix:
streamToolOutputstashes the per-id line count before resetting, andcollapseShellSlotalso accepts theToolResult's final output as alast-resort source. Adds two regression tests.
Supersedes #4003 by @CnsMaple (the original fork branch couldn't take a
maintainer push for the gofmt/comment cleanup). Credit to @CnsMaple for the fix.
Closes #4003