fix(executor): append newline when shell command stdout lacks trailing newline#2979
Merged
tusharmath merged 1 commit intomainfrom Apr 13, 2026
Merged
fix(executor): append newline when shell command stdout lacks trailing newline#2979tusharmath merged 1 commit intomainfrom
tusharmath merged 1 commit intomainfrom
Conversation
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
Fix a display bug where forge's LLM response text was concatenated onto the same line as shell command output when the command did not emit a trailing newline.
Context
When running a shell command that produces output without a trailing newline (e.g.
printf 'abc'), the terminal cursor is left mid-line. Because forge streams command stdout directly to the printer — bypassing theStreamingWriter'sends_with_newlinetracker — forge had no awareness that the cursor was mid-line. As a result, the LLM's response text would immediately follow the command output on the same line, producing garbled output like:Changes
execute_command_internal(crates/forge_infra/src/executor.rs), after streaming non-silent stdout, check if the last byte written was not a newline and the buffer is non-empty. If so, write a\nto the printer to move the cursor to a fresh line before any subsequent forge output.Key Implementation Details
The fix is in
ForgeCommandExecutorService::execute_command_internal. After thetokio::try_join!that streams stdout/stderr, the captured stdout buffer (result.1) is inspected. If its last byte is not\nand the buffer is non-empty, a newline is written directly to theoutput_printer. This is intentionally done at the infrastructure layer — right after the raw bytes are streamed — so every code path that renders shell output benefits automatically, regardless of which agent or tool triggered the command.Use Cases
printf 'abc',echo -n foo, custom scripts) will now produce clean, separated output.abcThe command ran successfully.Testing
cargo run -- -p "Use the shell command to print abc without a new line"Expected output (after fix):
The response text should appear on a new line after
abc, not concatenated to it.