Repository navigation
fix(ssh): pin UTF-8 output for remote Windows PowerShell commands - #52812
Conversation
[Medium impact] The PR appears safe to merge. SummaryRemote Windows PowerShell commands now set UTF-8 output before running the requested script.
No actionable issues were found. This review checked the code; it did not run tests or Windows commands. Reviews (2) · Last reviewed commit: "fix(ssh): keep the UTF-8 preamble commen..." · Reviewed by Greptile |
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
Windows PowerShell 5.1 and PowerShell 7 write stdout in the host's OEM code page when run over sshd, while Orca decodes remote output as UTF-8. Paths with non-ASCII characters (CJK user profiles, accented folder names) came back as replacement characters. powerShellCommand now prefixes every encoded script, inline and gzip, with a guarded [Console]::OutputEncoding = UTF8Encoding($false) assignment (BOM-less; a no-op when there is no console). The folder browse's local pins are dropped since the wrapper now covers them. Fixes stablyai#52750 Co-authored-by: Neil <[email protected]>
79247a0 to
1922f40
Compare
ELI5
When Orca talks to a Windows machine over SSH, it asks PowerShell for things like the user's home folder or where Node is installed. PowerShell answers in the machine's old local text encoding, but Orca always reads the answer as UTF-8. Any non-ASCII character in a path (Chinese, Japanese, Korean, or even
café) comes back as?or�, and the path is then wrong. Orca now tells PowerShell to answer in UTF-8 before every command, so those paths arrive intact.What Changed
execCommanddecodes as UTF-8. Non-ASCII paths fromreadRemoteHomeCommand, the remote Node lookup, the runtime store inventory and other probes arrived garbled. Only the folder browse pinned the encoding itself.powerShellCommand(src/main/ssh/remote-exec/ssh-remote-powershell.ts), which builds every remote Windows PowerShell command, prefixes each encoded script withtry { [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false) } catch {};on both the inline path and the gzip self-extracting path.
UTF8Encoding($false)is BOM-less, so output never starts with a stray BOM. Thetrykeeps sessions without a console working: there the assignment throws and is skipped.ssh-remote-directory-browse.tsare removed, since the wrapper now covers them.ssh-remote-powershell.test.tsdecodes the built command on both the inline and the compressed paths and checks the preamble is there.Why
src/main/sshdecodes as UTF-8, so pinning the output side makes all of them consistent.[System.Text.Encoding]::UTF8can emit a BOM on some hosts.UTF8Encoding::new($false)never does, so parsers that compare the first line exactly keep working.Linked Issue
Fixes #52750
Visual Proof
N/A: nothing in the UI changes. The visible effect is the bytes remote PowerShell returns, so the proof below is text output from a real Windows host over sshd, captured once on
mainand once on this branch.Before (main): non-ASCII path segments arrive as
?/�, and the output encoding is IBM437After (this branch): paths intact, UTF-8, no BOM
Raw bytes on 5.1 and 7:
caf c3 a9/e5 bc a0 e4 b8 89(UTF-8), noef bb bfprefix.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
Real Windows host (en-US, OEM code page 437), Windows PowerShell 5.1 and PowerShell 7: ran the built commands from
mainand from this branch on the inline path, the gzip path,readRemoteHomeCommand, and a console-less (DETACHED_PROCESS) session, against a temp folder whose name holds CJK and accented characters. Results are above: garbled onmain, intact on this branch, no BOM, console-less exit 0.Original report (zh-CN, code page 936, Windows 10 19045, PowerShell 5.1): @Pr1p ran Orca's real
powerShellCommand,execCommandandresolveRemoteNodePaththroughcmd.exe /d /s /c, which is how sshd runs exec requests.mainreturned GBK bytes and four U+FFFD; this branch returned the path intact, and the Node lookup under a CJK profile succeeded.Unit:
vitest run src/main/ssh/remote-exec/ssh-remote-powershell.test.ts src/main/ssh/filesystem/ssh-remote-directory-browse.test.tspasses. oxlint, oxfmt, the anti-slop, native code-quality and ast-grep gates, and the changed-code quality gate are all clean.Performance
Negligible. The change only runs when Orca builds a remote Windows SSH command, never on render, typing or terminal output. It adds 88 script characters (228 base64 characters) per command. The encoder costs 0.42 → 1.49 µs for a typical short script and 24.2 → 24.5 µs for a script near the budget, against a remote PowerShell spawn that takes hundreds of milliseconds. It adds no new subprocesses, I/O or polling. Scripts within about 230 characters of the 8,000-character inline budget now use the existing gzip fallback; the budget check already counts the preamble.
Risk
Level: Low
Review
Original fix by @Pr1p in #52812. The maintainer follow-ups switched to the BOM-less
UTF8Encoding($false)and tightened the comment and test.Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)