You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(process): keep multibyte characters intact across pipe reads - #50298
When Orca runs a Windows .cmd/.bat command and reads what it prints, non-English characters sometimes came back as �. This happened when one character landed half in one piece of output and half in the next. Orca now holds the unfinished half until the rest arrives.
What Changed
Before:spawnCommandCapture turned each stdout/stderr Buffer chunk into a string separately (chunk.toString(encoding)). If a pipe read ended partway through a multibyte UTF-8 character, both halves decoded to U+FFFD, even though the child wrote valid UTF-8.
After: stdout and stderr each get their own StringDecoder (in the requested encoding, default utf-8). Each chunk goes through decoder.write(chunk), which keeps an incomplete trailing sequence for the next chunk. Both decoders are flushed with decoder.end() when capture settles, including on error, timeout and abort rejections, so the attached stdout/stderr are complete.
maxBuffer still counts raw bytes before decoding. Cancellation, timeout and listener cleanup are unchanged.
Why
commandExecFileAsync sends .cmd/.bat commands, and its Windows shim fallback, through spawnCommandCapture. Corrupted characters there can change JSON output, paths and diagnostics before the caller parses them. A streaming decoder fixes this without buffering all raw output until exit, and it is how Node's own stream setEncoding handles text.
Original fix by @Afloat16 in #50298; final version reworked during the bug bash.
Visual Proof
N/A: this changes subprocess text capture, not any UI.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
New spawn-command-capture.test.ts starts a real Node child that writes the first byte of é中😀 (stdout) and ø界🚀 (stderr), then the rest 50 ms later, so the first character is split across two pipe reads. It fails on main with U+FFFD and passes with this change. Extra probes, not committed, also checked that timeout rejections carry decoded partial output.
Ran on macOS: targeted vitest for process-capture/, oxlint, oxfmt, anti-slop, code-quality native plugins, ast-grep and the changed-code quality gate. StringDecoder is cross-platform Node, and this path only runs on Windows in production. The helper behaves the same on every OS, so the test runs everywhere.
Performance
None that matters, because this path is a one-shot capture for Windows batch shims, not a hot path (no terminal stream, polling or render path). Microbenchmark per chunk, Node 24, old toString vs new decoder.write:
The worst case is about 0.17 ms per 64 KB pipe read, spread across separate data events. That is far below the 16 ms stall budget. The only allocation is two small decoder objects per process. No new subprocesses, I/O or polling.
Risk
Level: Low. Only text decoding changes. Byte limits, error shapes and settlement are unchanged. A plain revert restores the old behavior.
spawnCommandCapture now uses separate StringDecoder instances for stdout and stderr. It decodes chunks while preserving multibyte characters split across reads, then flushes both decoders when capture finishes. A test checks the complete captured output for both streams.
Severity of issue fixed: Medium
Merge Risk: Minimal · up to f7ee8
Multibyte output from captured commands is no longer corrupted when a character is split across pipe reads. No behavioral or performance risk is evident in the change, so it is ready to merge once CI passes.
Pre-merge checks: 4
Check name
Status
Explanation
Linked Issues check
[#50286] The issue requires four coding behaviors in spawnCommandCapture. (1) Independent decoder state per stream: at head, stdoutDecoder and stderrDecoder are separate StringDecoder instances …
Out of Scope Changes check
The whole-PR diff against the merge base changes two files. spawn-command-capture.ts adds the StringDecoder import, the two per-stream decoders, the write calls that replace per-chunk toString…
Title check
The title "fix(process): keep multibyte characters intact across pipe reads" names the main change. The PR switches stdout and stderr capture in spawnCommandCapture to per-stream StringDecoder instanc…
Description check
The description follows the repository template and covers the required sections. It has an ELI5, a before/after account of What Changed, a Why section that explains the approach, a linked issue (Fixe…
Full details: Linked Issues check
Explanation
[#50286] The issue requires four coding behaviors in spawnCommandCapture. (1) Independent decoder state per stream: at head, stdoutDecoder and stderrDecoder are separate StringDecoder instances created before spawn, and onStdoutData/onStderrData each write to their own decoder. (2) Requested encoding: both decoders use options.encoding ?? 'utf-8'. (3) Flush on settlement: finish() calls end() on both decoders after cleanupListeners() and before the reject and resolve branches, so the error path also flushes. (4) Limits, errors, cancellation and cleanup: the maxBuffer byte counters are still checked before write, and the abort, timeout and cleanup code is unchanged in the whole-PR diff against the merge base. The PR description says there are two regression cases for exit 0 and exit 7. The head test file contains only one case, a success-path test with a split first byte and a 5-second timeout. No error-path test exists at head. The issue does not state a test requirement for the error path, so this does not block the verdict. The error-path flush is supported by source only, not by an automated test. Native Windows routing was not executed, as the issue also states.
Full details: Out of Scope Changes check
Explanation
The whole-PR diff against the merge base changes two files. spawn-command-capture.ts adds the StringDecoder import, the two per-stream decoders, the write calls that replace per-chunk toString, and the end() flush in finish. spawn-command-capture.test.ts is a new Vitest case for multibyte text split across pipe reads on stdout and stderr. Both changes support the objective of #50286. Command construction, process launching, SSH capture and Codex file polling are not changed. The head test file has one case, not the two described in the PR description, but the extra case in the description is not a code change, so it does not affect scope.
Full details: Title check
Explanation
The title "fix(process): keep multibyte characters intact across pipe reads" names the main change. The PR switches stdout and stderr capture in spawnCommandCapture to per-stream StringDecoder instances, so multibyte UTF-8 characters split across pipe reads decode correctly. The title is specific and matches the changeset and linked objectives.
Full details: Description check
Explanation
The description follows the repository template and covers the required sections. It has an ELI5, a before/after account of What Changed, a Why section that explains the approach, a linked issue (Fixes #50286), N/A for Visual Proof with a reason, a Testing section with checked items and a described regression test, a Performance line with measurements, and a Risk section with a level and revert note. Gaps: the Risk section does not name a specific revert path beyond a plain revert, the AI Disclosure section is left blank, the Review and Agent skill upstream boundary sections are not filled in, and the Notes checklist items are not addressed. The objectives also say the full gate did not pass locally, but the description checks the local testing boxes and does not state this. These are minor and non-critical, so the description is mostly complete.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
spawnCommandCapture decoded each stdout/stderr chunk on its own, so a
UTF-8 character split across two pipe reads became U+FFFD. Decode each
stream through its own StringDecoder and flush it when capture settles.
maxBuffer still counts raw bytes.
Fixesstablyai#50286
Co-authored-by: Neil <[email protected]>
nwparker
changed the title
fix(process): preserve multibyte command capture across pipe reads
fix(process): keep multibyte characters intact across pipe reads
Nov 27, 2026
If the parent is delayed for more than 50 ms, it can receive both writes in one pipe read. The assertion can then pass with the old per-chunk decoder. Add a controlled-stream test that emits the partial character in separate data events. Keep the real-child test as a smoke test.
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 46376bfa-a28c-421e-a395-f0d267155614
Commits
Reviewing files that changed from the base of the PR and between 60e348e and f7ee80c.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
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
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.
ELI5
When Orca runs a Windows
.cmd/.batcommand and reads what it prints, non-English characters sometimes came back as�. This happened when one character landed half in one piece of output and half in the next. Orca now holds the unfinished half until the rest arrives.What Changed
spawnCommandCaptureturned each stdout/stderrBufferchunk into a string separately (chunk.toString(encoding)). If a pipe read ended partway through a multibyte UTF-8 character, both halves decoded to U+FFFD, even though the child wrote valid UTF-8.StringDecoder(in the requested encoding, defaultutf-8). Each chunk goes throughdecoder.write(chunk), which keeps an incomplete trailing sequence for the next chunk. Both decoders are flushed withdecoder.end()when capture settles, including on error, timeout and abort rejections, so the attachedstdout/stderrare complete.maxBufferstill counts raw bytes before decoding. Cancellation, timeout and listener cleanup are unchanged.Why
commandExecFileAsyncsends.cmd/.batcommands, and its Windows shim fallback, throughspawnCommandCapture. Corrupted characters there can change JSON output, paths and diagnostics before the caller parses them. A streaming decoder fixes this without buffering all raw output until exit, and it is how Node's own streamsetEncodinghandles text.Linked Issue
Fixes #50286
Original fix by @Afloat16 in #50298; final version reworked during the bug bash.
Visual Proof
N/A: this changes subprocess text capture, not any UI.
Testing
New
spawn-command-capture.test.tsstarts a real Node child that writes the first byte ofé中😀(stdout) andø界🚀(stderr), then the rest 50 ms later, so the first character is split across two pipe reads. It fails onmainwith U+FFFD and passes with this change. Extra probes, not committed, also checked that timeout rejections carry decoded partial output.Ran on macOS: targeted vitest for
process-capture/, oxlint, oxfmt, anti-slop, code-quality native plugins, ast-grep and the changed-code quality gate.StringDecoderis cross-platform Node, and this path only runs on Windows in production. The helper behaves the same on every OS, so the test runs everywhere.Performance
None that matters, because this path is a one-shot capture for Windows batch shims, not a hot path (no terminal stream, polling or render path). Microbenchmark per chunk, Node 24, old
toStringvs newdecoder.write:The worst case is about 0.17 ms per 64 KB pipe read, spread across separate data events. That is far below the 16 ms stall budget. The only allocation is two small decoder objects per process. No new subprocesses, I/O or polling.
Risk
Level: Low. Only text decoding changes. Byte limits, error shapes and settlement are unchanged. A plain revert restores the old behavior.
Reported by @Afloat16