Skip to content

fix(ssh): pin UTF-8 output for remote Windows PowerShell commands - #52812

Merged
nwparker merged 1 commit into
stablyai:mainfrom
Pr1p:fix/remote-windows-powershell-utf8
Nov 30, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
Pr1p:fix/remote-windows-powershell-utf8

Conversation

@Pr1p

@Pr1p Pr1p commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Before: every remote Windows PowerShell command wrote stdout and stderr in the host's OEM code page (for example 936 on zh-CN, 437 on en-US), while execCommand decodes as UTF-8. Non-ASCII paths from readRemoteHomeCommand, the remote Node lookup, the runtime store inventory and other probes arrived garbled. Only the folder browse pinned the encoding itself.
  • After: powerShellCommand (src/main/ssh/remote-exec/ssh-remote-powershell.ts), which builds every remote Windows PowerShell command, prefixes each encoded script with
    try { [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. The try keeps sessions without a console working: there the assignment throws and is skipped.
  • The folder browse's two local pins in ssh-remote-directory-browse.ts are removed, since the wrapper now covers them.
  • ssh-remote-powershell.test.ts decodes the built command on both the inline and the compressed paths and checks the preamble is there.

Why

  • Fix it where the commands are built, once. Pinning in each caller leaves every other caller, and every future one, on the OEM code page. That is how the folder browse ended up as the only caller with a pin.
  • Why not decode as the OEM code page in Orca. The code page differs per host (936, 932, 949, 437, 1252, ...) and would have to be probed before the first real command. Every consumer in src/main/ssh decodes as UTF-8, so pinning the output side makes all of them consistent.
  • Why the BOM-less encoding. [System.Text.Encoding]::UTF8 can 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 main and once on this branch.

Before (main): non-ASCII path segments arrive as ? / �, and the output encoding is IBM437
== powershell.exe inline  stdout: "C:\\Users\\neil\\AppData\\Local\\Temp\\orca-52812-??-caf�\r\nna�ve-??.txt\r\nIBM437\r\n..."  has U+FFFD: true
== powershell.exe gzip    stdout: "C:\\...\\orca-52812-??-caf�\r\nna�ve-??.txt\r\nIBM437\r\n..."                                     has U+FFFD: true
== pwsh.exe inline        stdout: "C:\\...\\orca-52812-??-caf�\r\nna�ve-??.txt\r\nibm437\r\n..."                                     has U+FFFD: true
== pwsh.exe gzip          stdout: "C:\\...\\orca-52812-??-caf�\r\nna�ve-??.txt\r\nibm437\r\n..."                                     has U+FFFD: true
After (this branch): paths intact, UTF-8, no BOM
== powershell.exe inline  stdout: "C:\\Users\\neil\\AppData\\Local\\Temp\\orca-52812-张三-café\r\nnaïve-日本.txt\r\nutf-8\r\n..."  BOM: false  U+FFFD: false
== powershell.exe gzip    stdout: "C:\\...\\orca-52812-张三-café\r\nnaïve-日本.txt\r\nutf-8\r\n..."                                     BOM: false  U+FFFD: false
== pwsh.exe inline        stdout: "C:\\...\\orca-52812-张三-café\r\nnaïve-日本.txt\r\nutf-8\r\n..."                                     BOM: false  U+FFFD: false
== pwsh.exe gzip          stdout: "C:\\...\\orca-52812-张三-café\r\nnaïve-日本.txt\r\nutf-8\r\n..."                                     BOM: false  U+FFFD: false
== readRemoteHomeCommand  stdout: "C:\\Users\\neil\r\n"  status=0
== no-console (DETACHED_PROCESS)  status=0  stdout: "\nexit=0"   (the guarded assignment does not break console-less sessions)

Raw bytes on 5.1 and 7: caf c3 a9 / e5 bc a0 e4 b8 89 (UTF-8), no ef bb bf prefix.

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 main and 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 on main, 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, execCommand and resolveRemoteNodePath through cmd.exe /d /s /c, which is how sshd runs exec requests. main returned 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.ts passes. 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

  • Any Windows SSH host: every remote PowerShell command now sets the console output encoding first. On hosts with no console the guarded assignment is skipped, and the console-less case was tested. The change only affects the remote child process, which exits after each command, so the user's own sessions keep their settings.
  • Mixed versions: this changes only commands Orca builds and sends, so there is nothing to keep compatible on the remote side.
  • Back out with a plain revert.

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

  • 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

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)

@greptile-apps

greptile-apps Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Remote Windows PowerShell commands now set UTF-8 output before running the requested script.

  • Remote Windows PowerShell commands now return UTF-8 text.

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

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Encoded PowerShell commands now prepend a guarded attempt to set console output encoding to UTF-8. Directory-browse scripts no longer set output encoding themselves. Tests check the preamble in decoded inline and compressed commands. The encoded-command format check replaces an exact-value assertion; oversized-script error and warning assertions remain.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 1922f

Remote Windows PowerShell probes should now return non-ASCII paths intact. The change is small and guarded, so it should not break sessions without a console. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: pinning UTF-8 output for remote Windows PowerShell commands. The raw summary and objectives confirm the shared powerShellCommand wrapper now sets console output encodi…
Description check Passed The description follows the repository template closely. It covers ELI5, What Changed, Why, Linked Issue (Fixes #52750), Visual Proof (N/A with reason), Testing with platforms actually tested and not …
Linked Issues check Passed [#52750] requires consistent UTF-8 decoding of remote Windows PowerShell probe output (remote home, Node lookup, runtime-store inventory) on non-UTF-8 code-page hosts, with the fix in the shared power…
Out of Scope Changes check Passed All changes map to #52750. ssh-remote-powershell.ts adds the guarded UTF-8 preamble and its constant. ssh-remote-directory-browse.ts removes two local encoding pins; both scripts still build through p…
Full details: Title check

Explanation

The title names the main change: pinning UTF-8 output for remote Windows PowerShell commands. The raw summary and objectives confirm the shared powerShellCommand wrapper now sets console output encoding to UTF-8, and the folder-browse pins were removed. The title uses the conventional fix(ssh) prefix and fits within a typical length.

Full details: Description check

Explanation

The description follows the repository template closely. It covers ELI5, What Changed, Why, Linked Issue (Fixes #52750), Visual Proof (N/A with reason), Testing with platforms actually tested and not tested, Performance (None, because...), Risk with level and back-out method, AI Disclosure, Review, Agent skill boundary, Notes, and Checklist. The description explains the before and after behavior, the mechanism, and alternatives considered. Minor gap: the Risk section names Low but the template asks for the riskiest part, which it does address via the garbled-text note. Overall the description is complete.

Full details: Linked Issues check

Explanation

[#52750] requires consistent UTF-8 decoding of remote Windows PowerShell probe output (remote home, Node lookup, runtime-store inventory) on non-UTF-8 code-page hosts, with the fix in the shared powerShellCommand wrapper and guarded against sessions without a console. At head, ssh-remote-powershell.ts defines UTF8_OUTPUT_PREAMBLE = 'try { [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false) } catch {}; ' and encodedPowerShellCommand prepends it to every script before encoding. Both the inline and gzip paths of powerShellCommand go through encodedPowerShellCommand, so both carry the preamble. The change since the previous review replaced the preamble's encoding expression with UTF8Encoding($false). This still sets UTF-8 output and keeps the try guard, so the requirement remains met. The PR description still names [System.Text.Encoding]::UTF8, which differs from the code; this is a documentation mismatch and does not affect the requirement. The test file's preamble-check case was not run; this verdict rests on the source diff.

Full details: Out of Scope Changes check

Explanation

All changes map to #52750. ssh-remote-powershell.ts adds the guarded UTF-8 preamble and its constant. ssh-remote-directory-browse.ts removes two local encoding pins; both scripts still build through powerShellCommand, so the wrapper covers them. The test file adds a decode helper and a preamble check, which support the objective. The PR description's Node, remote-home, and runtime-store claims match the issue scope. No unrelated change was identified.

  • 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.

Share

Recent 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: 1e243df5-e9fe-4715-bf1f-9b02083acaa9
Commits

Reviewing files that changed from the base of the PR and between 79247a0 and 1922f40.

Files selected for processing: 2

  • src/main/ssh/remote-exec/ssh-remote-powershell.test.ts
  • src/main/ssh/remote-exec/ssh-remote-powershell.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

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]>
@nwparker
nwparker force-pushed the fix/remote-windows-powershell-utf8 branch from 79247a0 to 1922f40 Compare November 30, 2026 02:27
@nwparker
nwparker merged commit 937f388 into stablyai:main Nov 30, 2026
97 of 99 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Windows SSH host on a non-UTF-8 code page: PowerShell probes return OEM bytes that Orca decodes as UTF-8, garbling non-ASCII profile paths

2 participants