Skip to content

fix(chat): clear accumulated shell output on re-run of !commands#4020

Closed
CnsMaple wants to merge 1 commit into
esengine:main-v2from
CnsMaple:fix/shell-output-cumulative
Closed

fix(chat): clear accumulated shell output on re-run of !commands#4020
CnsMaple wants to merge 1 commit into
esengine:main-v2from
CnsMaple:fix/shell-output-cumulative

Conversation

@CnsMaple

@CnsMaple CnsMaple commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Problem

Repeated !pwd (or any ! shell command) accumulates output lines across runs instead of showing only the current run's output.

Before (3× !pwd):

  › !pwd

  ● Bash(pwd)
  ⎿  /d/about_fish/ProgramProtable/DeepSeek-Reasonix

  › !pwd

  ● Bash(pwd)
  ⎿  /d/about_fish/ProgramProtable/DeepSeek-Reasonix
     /d/about_fish/ProgramProtable/DeepSeek-Reasonix

  › !pwd

  ● Bash(pwd)
  ⎿  /d/about_fish/ProgramProtable/DeepSeek-Reasonix
     /d/about_fish/ProgramProtable/DeepSeek-Reasonix
     /d/about_fish/ProgramProtable/DeepSeek-Reasonix

Root Cause

controller.RunShell generates a fixed tool ID for each ! command (e.g. "shell-pwd"). streamToolOutput appends output with m.shellOutputs[id] += chunk, but beginToolRunning never cleared the map entry, so every subsequent run added to the previous output. collapseShellSlot then rendered all accumulated lines.

Fix

Clear m.shellOutputs[id] in beginToolRunning so each re-run of the same tool ID starts with a clean slate. This is a one-line delete with a comment.

After (3× !pwd):

  › !pwd

  ● Bash(pwd)
  ⎿  /d/about_fish/ProgramProtable/DeepSeek-Reasonix

  › !pwd

  ● Bash(pwd)
  ⎿  /d/about_fish/ProgramProtable/DeepSeek-Reasonix

  › !pwd

  ● Bash(pwd)
  ⎿  /d/about_fish/ProgramProtable/DeepSeek-Reasonix

When a !command (e.g. !pwd) is run multiple times, the tool ID is
fixed (e.g. "shell-pwd") so streamToolOutput appends each run's
output to the same shellOutputs key. Without clearing, collapseShellSlot
renders all accumulated lines from every run.

Fix by deleting shellOutputs[id] in beginToolRunning, so each run
starts with a clean slate.

Before (3x !pwd):
  ⎿  /d/about_fish/ProgramProtable/DeepSeek-Reasonix
     /d/about_fish/ProgramProtable/DeepSeek-Reasonix
     /d/about_fish/ProgramProtable/DeepSeek-Reasonix

After (3x !pwd):
  ⎿  /d/about_fish/ProgramProtable/DeepSeek-Reasonix
  ⎿  /d/about_fish/ProgramProtable/DeepSeek-Reasonix
  ⎿  /d/about_fish/ProgramProtable/DeepSeek-Reasonix
@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

Copy link
Copy Markdown
Owner

Thanks @CnsMaple — clean catch and the fix is correct. I traced the chain: RunShell derives a stable shell-<cmd> id, and streamToolOutput accumulates into shellOutputs[id], so clearing it in beginToolRunning is exactly the right spot (runs on each dispatch, before the new run accumulates).

I've re-landed your commit on top of the latest main-v2 with a regression test (three identical !pwd runs must leave one run's output, not three — verified it fails without your delete) in #4025, which will close this. Your authorship is preserved on the fix commit. 🙏

@CnsMaple CnsMaple deleted the fix/shell-output-cumulative branch June 12, 2026 02:12
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