Skip to content

fix(chat): render correct line count under each parallel bash marker#4010

Merged
esengine merged 2 commits into
main-v2from
pr/4003-parallel-bash-marker-count
Jun 11, 2026
Merged

fix(chat): render correct line count under each parallel bash marker#4010
esengine merged 2 commits into
main-v2from
pr/4003-parallel-bash-marker-count

Conversation

@esengine

Copy link
Copy Markdown
Owner

Parallel call_N-style bash tools (DeepSeek schedules several in one turn) were
losing their per-call line count: streamToolOutput reset the active id's
toolLineCount on every switch, and collapseShellSlot's late path could only
recover it from shellOutputs, which is populated for "shell-" ids only. For
call_N ids the count fell through to -1, so each card rendered ⎿ -1 lines
(or a blank slot) instead of its real count.

Fix: streamToolOutput stashes the per-id line count before resetting, and
collapseShellSlot also accepts the ToolResult's final output as a
last-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

CnsMaple and others added 2 commits June 11, 2026 15:29
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.
@esengine esengine requested a review from SivanCola as a code owner June 11, 2026 09:17
@github-actions github-actions Bot added v2 Go rewrite (1.x) — main-v2 branch, active development tui Terminal UI / CLI (internal/cli, internal/control) labels Jun 11, 2026
@esengine esengine merged commit 4924d9f into main-v2 Jun 11, 2026
14 checks passed
@esengine esengine deleted the pr/4003-parallel-bash-marker-count branch June 11, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tui Terminal UI / CLI (internal/cli, internal/control) v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants