Skip to content

fix: prevent UTF-8 corruption when stdout and stderr interleave - #36665

Closed
me2seeks wants to merge 1 commit into
anomalyco:devfrom
me2seeks:decode-shell-streams
Closed

fix: prevent UTF-8 corruption when stdout and stderr interleave#36665
me2seeks wants to merge 1 commit into
anomalyco:devfrom
me2seeks:decode-shell-streams

Conversation

@me2seeks

Copy link
Copy Markdown

Issue for this PR

Closes#36655

Type of change

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

What does this PR do?

Bash output currently merges raw stdout and stderr bytes before UTF-8 decoding. If stdout ends a chunk in the middle of a multibyte character and stderr writes before the remaining bytes arrive, both pipes are fed through the same decoder state and the output contains replacement characters.

This changes text output consumers to decode stdout and stderr with separate streaming decoders, then merge the decoded text. Raw combined output remains available for byte-oriented callers. The same text-safe path is used by the current shell tool, direct session shell execution, and the Core Bash implementation.

Cross-stream ordering remains best-effort, as it was before this change.

How did you verify your code works?

  • Added a deterministic stream test that splits one emoji across stdout chunks with a stderr chunk in between.
  • Added subprocess regression coverage for AppProcess, the shell tool, and direct session shell execution.
  • Ran the affected Core and OpenCode test files.
  • Ran Core and OpenCode typechecks serially with Turbo concurrency limited to 1.
  • Ran Prettier and Oxlint on all changed files.

Screenshots / recordings

Not applicable; this changes captured shell text without changing the UI.

Checklist

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

Decode stdout and stderr with separate incremental UTF-8 decoders before merging text output. Cover the legacy shell paths and the Core Bash implementation.
Fixesanomalyco#36655
@me2seeksme2seeks changed the title fix(opencode): decode shell streams independentlyfix: prevent UTF-8 corruption when stdout and stderr interleaveJul 13, 2026
@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.

Bash output can corrupt UTF-8 when stdout and stderr interleave

1 participant

@me2seeks