fix(chat): clear accumulated shell output on !command re-run (+ regression test)#4025
Merged
Merged
Conversation
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
A re-run of the same "!" command reuses its command-derived id, so without the clearing fix streamToolOutput appended each run's output to the last. Pin the regression: three identical runs must leave one run's output, not three.
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.
Lands @CnsMaple's fix from #4020 with an added regression test.
Closes #4020
Problem
Repeated
!pwd(or any!command) accumulated output across runs.RunShellderives a stable tool id from the command text (
shell-pwd), andstreamToolOutputdoesm.shellOutputs[id] += chunk—beginToolRunningnevercleared the entry, so each re-run appended to the prior run's output and
collapseShellSlotrendered all of it.Fix (@CnsMaple, #4020)
Clear
m.shellOutputs[id]inbeginToolRunning, which runs on eachToolDispatch— before the new run accumulates and after the previous run already collapsed
into the transcript. One
delete, both render modes.Added here
TestRepeatedShellCommandDoesNotAccumulateOutput: three identicalshell-pwdruns must leave one run's output in
shellOutputs, not three. Verified it failswithout the fix (
"…\n…\n…\n") and passes with it.Test
go test ./internal/cli/— pass