Skip to content

fix: normalize carriage-return shell output - #36684

Closed
me2seeks wants to merge 2 commits into
anomalyco:devfrom
me2seeks:normalize-shell-output
Closed

fix: normalize carriage-return shell output#36684
me2seeks wants to merge 2 commits into
anomalyco:devfrom
me2seeks:normalize-shell-output

Conversation

@me2seeks

@me2seeksme2seeks commented Jul 13, 2026

Copy link
Copy Markdown

Issue for this PR

Closes#36683

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Completed tool results are expected to be included in subsequent model context. This PR does not change when tool results are included or how long they remain in message history.

The bug is in the shell result content. Commands which redraw one line currently retain \r and ANSI erase-line frames, so the model receives obsolete progress history instead of the terminal-visible output. Output limits keep the result bounded, but these frames still waste space inside that limit and present stale versions of one logical line. In the core Bash path, enough raw refresh data can also reach the 1 MiB capture limit before the command's final output is collected.

This adds an incremental line-oriented terminal reducer and applies it before Bash capture limits in both the core Bash tool and the legacy shell tool. Ordinary newline-delimited text is preserved, while carriage returns, erase-line sequences, backspace, and horizontal cursor updates produce the final visible line. Live shell metadata and the completed result use the same line-update semantics.

The legacy path still writes raw output to disk, but reports it as rawOutputPath when the rendered tool result was not truncated. It also drains the output stream before building the final result so the last chunk cannot race process completion.

This intentionally keeps normal commands on the existing non-PTY path and does not try to emulate a full-screen terminal.

How did you verify your code works?

  • cd packages/core && bun test test/terminal-output.test.ts test/process/process.test.ts test/tool-bash.test.ts (45 passed)
  • cd packages/opencode && bun test test/tool/shell.test.ts (24 passed)
  • bun typecheck from packages/core and packages/opencode, run sequentially with a 3 GiB memory limit
  • A real shell test writes 5,000 ESC[2K + \r frames and verifies that the completed tool result contains only the last visible frame and final marker, while the saved raw log still contains all 5,000 frames

Screenshots / recordings

Not included. The behavior is covered by terminal reducer, process, and shell integration tests.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shell results retain overwritten carriage-return updates

1 participant

@me2seeks