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(automations): decode cmd.exe precheck output in the Windows OEM code page - #50960
On Windows, an automation precheck runs through cmd.exe. When cmd.exe prints its own error, for example "this command does not exist", it uses the legacy code page for the system language instead of UTF-8. Orca read everything as UTF-8. On Chinese, Japanese, Korean, Russian, Thai or Vietnamese Windows, the message that explains why a precheck skipped a run came out as garbage. Orca now decodes those lines in the right code page.
What Changed
Before:runLocalPrecheck called setEncoding('utf8') on stdout/stderr. When cmd.exe wrote a message in the OEM page (GBK, Shift_JIS, etc.), the stored precheck stderr was 'x' ����.
After: that line reads 'x' 中文… (the localized cmd.exe message). Lines that are valid UTF-8, such as node or git output, look the same as before.
Mechanism:
src/main/automations/dispatch/precheck-runner.ts keeps a bounded raw byte tail for each stream with the existing createOutputSink(…, 'tail'). The cap is 4 bytes per allowed character. The runner decodes once at settle and then applies the existing character cap. When the tail was truncated, the runner first drops up to 3 leading UTF-8 continuation bytes, so a character cut by the cap does not push its whole line into the OEM decoder.
New src/main/windows/windows-shell-output-decoding.ts, with decodeWindowsShellOutput(bytes):
Output that is all valid UTF-8 returns bytes.toString('utf8') straight away and never loads the registry addon.
Otherwise, on win32, it reads HKLM\SYSTEM\CurrentControlSet\Control\Nls\CodePage\OEMCP once per process (cached, failures included) through the existing loadWindowsNativeRegistry. Then it decodes each line as UTF-8 when the line is valid, and with the OEM decoder when it is not. It works per line because one pipe can carry both, for example nosuchcmd || node ….
A UTF-8 character cut at the very end (timeout kill, block flush) still counts as UTF-8 and shows one U+FFFD, as StringDecoder did before.
Supported OEM pages: 866, 874, 932, 936, 949, 950, 1258. Off Windows, without the addon (server slots), or on any other page, output decodes as UTF-8 as before. SSH prechecks are unchanged.
Why
Adding chcp 65001 or chcp 936 in front of the command does not help. Probed on a Windows host: cmd.exe still writes its own messages to the pipe in OEMCP, and the bytes do not change. Decoding on Orca's side is the only fix that does not depend on what the user's command prints.
N/A. The change is in the text stored for a precheck result. It only shows up on Windows with a CJK/Cyrillic/Thai/Vietnamese OEM code page, and no such GUI host was available (changing a system locale needs a reboot). The before/after strings are in What Changed and Testing.
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
Windows host (OEMCP 437, node 24): a probe of spawn(cmd, { shell: true }) with nosuchcmd_é showed cmd.exe writing 0x82 (é in cp437). main decodes that to 'nosuchcmd_�' is not recognized…. Putting chcp 936/chcp 65001 in front did not change the bytes.
Contributor (Windows 10 19045, OEMCP 936): ran the real runAutomationPrecheck with nosuchcmd_xyz || node -e …. On main, stderr was U+FFFD garbage. With the fix, it is the localized "not recognized" message, and node's stdout stays readable.
Scratch test with the real runAutomationPrecheck: OEMCP 936 mocked, win32 set at settle, a child writing one GBK line and one UTF-8 line. main fails. This branch passes, including a truncated 中×10000 tail with suffixes ''/a/ab, which stays all 中.
Electron ICU (Electron 43, ICU 78): ibm866, windows-874, shift_jis, gbk, euc-kr and big5 all construct and decode. If a page is not supported, the TextDecoder constructor throws and the catch falls back to UTF-8.
It covers a mixed GBK cmd.exe line, a UTF-8 line and an unterminated tail.
It also covers a UTF-8 line cut mid-character at the end, alone and after a GBK line.
It fails on main because the module does not exist. The cut-character cases fail when the trailing-cut handling is removed (mutation checked).
vitest run src/main/windows/ src/main/automations/ bounded-output-sink.test.ts: 14 files passed, 43 tests.
oxlint, oxfmt, anti-slop oxlint, native code-quality oxlint, ast-grep and the changed-code quality gate all pass on the touched files.
macOS/Linux behavior is unchanged: decoding stays UTF-8.
Performance
Cold path: main process, once per local automation precheck. No renderer, store, polling or terminal-stream changes, and no new subprocesses. The registry read is one cached sync read and only happens when output is not valid UTF-8 on win32. Benchmarks (node 24) compare old and new:
Decode at settle, per stream:
Typical 200 B ASCII: 0.0004 ms.
Dir-like 16 KB GBK: 0.09 ms.
Adversarial 8000 invalid 1-byte lines: 1.2 ms.
Adversarial 16000 invalid bytes on one line: 0.2 ms.
Everything stays well under 16 ms.
Ingest with createOutputSink vs the previous string tail:
Typical: 0.0003 ms.
1 B × 200k flood: 5.5 ms vs 33 ms on main.
64 KB × 1600 (100 MB): about 2–3 ms.
Max event-loop gap is about 2 ms, the same as main.
Risk
Level: Low
Who is affected: only Windows machines with OEM page 866/874/932/936/949/950/1258, and only for lines that are not valid UTF-8. Those lines were already garbled on main.
Trade-off 1: a line that is mostly UTF-8 but has one stray invalid byte in the middle now decodes entirely in the OEM page instead of showing one U+FFFD. Such output is already corrupt. A character cut at either end of the tail is handled.
Trade-off 2: Russian tools that write ANSI cp1251 now show wrong Cyrillic letters instead of U+FFFD. That output was unreadable on main too.
Not covered:TextDecoder has no cp437/cp850, so accented letters in cmd.exe messages on Western-European OEM pages stay garbled, as on main.
Back out: plain revert.
Review
Possible follow-ups, out of scope here: the SSH precheck path, and ephemeral-vm-recipe-process.ts, which has the same shell: true + UTF-8 pattern.
Agent skill upstream boundary
Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
macOS/Linux and SSH prechecks keep the UTF-8 decode. Older remote runtimes are not involved: this runs only on the local main process.
Original fix by @Pr1p in #50960. Maintainer review changes are squashed into this commit, and Chen is kept as the author.
Checklist
This PR is small and focused
I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
I stated the risk: what could break, for whom, and how to back it out
Before/after screenshots or videos attached for UI changes, or N/A with reason
Self-reviewed for correctness, security, and performance
Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)
Local precheck stdout and stderr are retained as bounded byte buffers and decoded when the process settles. On Windows, the decoder uses the OEM code page when available and decodes valid UTF-8 lines as UTF-8. It uses UTF-8 decoding when no OEM decoder is available. The character cap applies after decoding. Tests cover mixed GBK and UTF-8 output and UTF-8 output cut off mid-character.
Severity of issue fixed: Medium
Merge Risk: Low · up to 8616c
Windows precheck output is now decoded with the OEM code page where possible, which fixes the garbled text. In one narrow case, an unterminated final line ending in a byte that is not a valid UTF-8 start can still show a replacement character instead of the OEM text. This is cosmetic and low risk.
Pre-merge checks: 4
Check name
Status
Explanation
Linked Issues check
Issue #50959 requires three things. First, cmd.exe messages from local Windows prechecks must decode in the OEM code page. Second, UTF-8 tool output must stay readable. Third, the change must not alte…
Out of Scope Changes check
All changed code supports the decoding objective of #50959. The changes are: the new windows-shell-output-decoding module, the byte-tail buffering and single decode in runLocalPrecheck, and the new un…
Title check
The title names the main change: cmd.exe precheck output is now decoded in the Windows OEM code page. It matches the changeset, which adds OEM decoding for local Windows precheck output. The title fol…
Description check
The description follows the repository template. It includes ELI5, What Changed, Why, Linked Issue (Fixes #50959), Visual Proof (N/A with a reason), Testing with platform details, Performance, Risk wi…
Full details: Linked Issues check
Explanation
Issue #50959 requires three things. First, cmd.exe messages from local Windows prechecks must decode in the OEM code page. Second, UTF-8 tool output must stay readable. Third, the change must not alter other paths. At head 8616ce7, runLocalPrecheck (src/main/automations/dispatch/precheck-runner.ts) collects raw byte tails through createOutputSink. It calls decodeByteTail once in settle, which calls decodeWindowsShellOutput. decodeWindowsShellOutput (src/main/windows/windows-shell-output-decoding.ts) reads OEMCP from the registry once per process. It maps the code page to a TextDecoder encoding. decodeMixedShellOutputLines decodes each LF-delimited line as UTF-8 when valid, and otherwise with the OEM decoder. This handles a pipe that carries both a GBK cmd.exe line and a UTF-8 node line. A final line cut mid-character is checked without treating the partial character as invalid. The SSH path (runSshChannelPrecheck) still decodes as UTF-8. Non-Windows platforms return bytes.toString('utf8'). The PR reports a manual before/after run on zh-CN (OEM 936). Its stderr changes from U+FFFD to the localized message. The changes since the previous review add windows-1258 to the mapping and the cut-character handling in decodeByteTail. Both keep the same behavior for the reported case. Limit: the new test file was not read in this review. Test behavior is taken from the summary and the PR description.
Full details: Out of Scope Changes check
Explanation
All changed code supports the decoding objective of #50959. The changes are: the new windows-shell-output-decoding module, the byte-tail buffering and single decode in runLocalPrecheck, and the new unit test file. The byte cap of four bytes per character supports the existing character cap. The mid-character cut handling in decodeByteTail and isUtf8BeforeCutCharacter prevents a split character from turning a valid UTF-8 line into OEM text. This supports the UTF-8 readability requirement. The entry for windows-1258 is a minor addition. It is a Windows code page, not a true OEM page, and the PR description does not list it. It is in the same locale mapping and does not change other behavior, so it is not an unrelated change. The SSH path and ephemeral-vm recipe path are not changed. The PR description states that the ephemeral-vm recipe path was left out on purpose. The PR description should be updated to list 1258 in the supported pages.
Full details: Title check
Explanation
The title names the main change: cmd.exe precheck output is now decoded in the Windows OEM code page. It matches the changeset, which adds OEM decoding for local Windows precheck output. The title follows the conventional commit form and is 77 characters long, which is within a reasonable range for a title.
Full details: Description check
Explanation
The description follows the repository template. It includes ELI5, What Changed, Why, Linked Issue (Fixes #50959), Visual Proof (N/A with a reason), Testing with platform details, Performance, Risk with level and back-out plan, Review, Agent skill boundary, Notes, and Checklist. The AI Disclosure section is left blank, which the template allows for internal contributors, and the author has not stated whether it applies. The Risk section says how to back out the change. Remaining gaps are minor: the Performance section explains the trade-off, and the Testing section names the platforms tested.
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Preserve encoding boundaries when trimming the byte tail.
On Windows with OEMCP 936, UTF-8 output containing '中'.repeat(6000) occupies 18000 bytes. This cut starts the retained buffer inside a character. The strict UTF-8 decoder then throws, so decodeMixedShellOutputLines decodes the entire retained line as GBK. The final 4000-character slice remains unreadable. Fatal decoding throws on invalid input as documented for Node 24. (nodejs.org)
Preserve boundary context when trimming so the cut cannot change the retained line's encoding selection. Keep genuine OEM fallback working. Add a regression case through byte-tail collection and final decoding.
Based on learnings, validate complete encoding units rather than arbitrary byte fragments.
On Windows, local automation prechecks run through cmd.exe, which writes
its own messages (such as "is not recognized as an internal or external
command") to the pipe in the OEM code page. The runner decoded every byte
as UTF-8, so on zh-CN, ja, ko, ru, th and vi Windows the stored precheck
output, which tells the user why a run was skipped, showed U+FFFD garbage.
The runner now keeps bounded raw byte tails per stream (createOutputSink)
and decodes once at settle. decodeWindowsShellOutput reads OEMCP from the
registry once per process and decodes each line as UTF-8 when it is valid,
otherwise with the OEM decoder, because one pipe can mix UTF-8 tool output
with cmd.exe messages. A UTF-8 character split by the byte cap at the start
or by a kill at the end stays UTF-8. Off Windows, without the registry
addon, or for unsupported pages, output is decoded as UTF-8 as before. SSH
prechecks are unchanged.
Fixesstablyai#50959
Co-authored-by: Neil <[email protected]>
nwparker
changed the title
fix(automations): decode cmd.exe precheck output in the OEM code page
fix(automations): decode cmd.exe precheck output in the Windows OEM code page
Nov 27, 2026
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Reject impossible UTF-8 lead bytes before treating a suffix as cut.
On Windows with OEMCP 866, Buffer.from([0x32, 0x30, 0xf8]) represents the unterminated text 20°. The IBM866 mapping assigns 0xf8 to °. (encoding.spec.whatwg.org)
Line 40 treats 0xf8 as a four-byte UTF-8 lead. The helper then validates only 20, so the exported decoder bypasses OEM decoding and returns 20�.
Only accept a suffix that can actually begin a valid UTF-8 character. Reject impossible leads such as 0xf8 and invalid continuation combinations. This preserves the valid E4 B8 cutoff case while allowing OEM fallback for this input. UTF-8 lead bytes cannot exceed 0xf4. (encoding.spec.whatwg.org)
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
On Windows, an automation precheck runs through cmd.exe. When cmd.exe prints its own error, for example "this command does not exist", it uses the legacy code page for the system language instead of UTF-8. Orca read everything as UTF-8. On Chinese, Japanese, Korean, Russian, Thai or Vietnamese Windows, the message that explains why a precheck skipped a run came out as garbage. Orca now decodes those lines in the right code page.
What Changed
runLocalPrecheckcalledsetEncoding('utf8')on stdout/stderr. When cmd.exe wrote a message in the OEM page (GBK, Shift_JIS, etc.), the stored precheck stderr was'x' ����.'x' 中文…(the localized cmd.exe message). Lines that are valid UTF-8, such as node or git output, look the same as before.src/main/automations/dispatch/precheck-runner.tskeeps a bounded raw byte tail for each stream with the existingcreateOutputSink(…, 'tail'). The cap is 4 bytes per allowed character. The runner decodes once at settle and then applies the existing character cap. When the tail was truncated, the runner first drops up to 3 leading UTF-8 continuation bytes, so a character cut by the cap does not push its whole line into the OEM decoder.src/main/windows/windows-shell-output-decoding.ts, withdecodeWindowsShellOutput(bytes):bytes.toString('utf8')straight away and never loads the registry addon.HKLM\SYSTEM\CurrentControlSet\Control\Nls\CodePage\OEMCPonce per process (cached, failures included) through the existingloadWindowsNativeRegistry. Then it decodes each line as UTF-8 when the line is valid, and with the OEM decoder when it is not. It works per line because one pipe can carry both, for examplenosuchcmd || node ….StringDecoderdid before.Why
Adding
chcp 65001orchcp 936in front of the command does not help. Probed on a Windows host: cmd.exe still writes its own messages to the pipe in OEMCP, and the bytes do not change. Decoding on Orca's side is the only fix that does not depend on what the user's command prints.Linked Issue
Fixes #50959
Visual Proof
N/A. The change is in the text stored for a precheck result. It only shows up on Windows with a CJK/Cyrillic/Thai/Vietnamese OEM code page, and no such GUI host was available (changing a system locale needs a reboot). The before/after strings are in What Changed and Testing.
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
Windows host (OEMCP 437, node 24): a probe of
spawn(cmd, { shell: true })withnosuchcmd_éshowed cmd.exe writing0x82(é in cp437). main decodes that to'nosuchcmd_�' is not recognized…. Puttingchcp 936/chcp 65001in front did not change the bytes.Contributor (Windows 10 19045, OEMCP 936): ran the real
runAutomationPrecheckwithnosuchcmd_xyz || node -e …. On main, stderr was U+FFFD garbage. With the fix, it is the localized "not recognized" message, and node's stdout stays readable.Scratch test with the real
runAutomationPrecheck: OEMCP 936 mocked, win32 set at settle, a child writing one GBK line and one UTF-8 line. main fails. This branch passes, including a truncated中×10000 tail with suffixes''/a/ab, which stays all中.Electron ICU (Electron 43, ICU 78): ibm866, windows-874, shift_jis, gbk, euc-kr and big5 all construct and decode. If a page is not supported, the
TextDecoderconstructor throws and the catch falls back to UTF-8.windows-shell-output-decoding.test.ts(codec test):vitest run src/main/windows/ src/main/automations/ bounded-output-sink.test.ts: 14 files passed, 43 tests.oxlint, oxfmt, anti-slop oxlint, native code-quality oxlint, ast-grep and the changed-code quality gate all pass on the touched files.
macOS/Linux behavior is unchanged: decoding stays UTF-8.
Performance
Cold path: main process, once per local automation precheck. No renderer, store, polling or terminal-stream changes, and no new subprocesses. The registry read is one cached sync read and only happens when output is not valid UTF-8 on win32. Benchmarks (node 24) compare old and new:
createOutputSinkvs the previous string tail:Risk
Level: Low
TextDecoderhas no cp437/cp850, so accented letters in cmd.exe messages on Western-European OEM pages stay garbled, as on main.Review
ephemeral-vm-recipe-process.ts, which has the sameshell: true+ UTF-8 pattern.Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
macOS/Linux and SSH prechecks keep the UTF-8 decode. Older remote runtimes are not involved: this runs only on the local main process.
Original fix by @Pr1p in #50960. Maintainer review changes are squashed into this commit, and Chen is kept as the author.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)