Repository navigation
fix(ssh): keep multibyte file names intact when a remote folder listing spans several packets - #50944
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
…ng spans several packets The remote folder browser decoded each SSH stdout/stderr packet with Buffer#toString, so a UTF-8 name whose bytes straddled two packets turned into U+FFFD halves and could not be opened. Decode both streams with a StringDecoder per stream and flush them on close before parsing. Fixes stablyai#50943 Co-authored-by: Neil <[email protected]>
86ed47c to
673893f
Compare
ELI5
When you add a project from an SSH host, Orca lists the remote folders so you can pick one. That list comes over the network in pieces. If a piece ended halfway through a Chinese, accented or emoji character, that folder name came out garbled and Orca couldn't open it. Orca now waits for the rest of the character before turning the bytes into text.
What Changed
runBrowseCommandinsrc/main/ssh/filesystem/ssh-remote-directory-browse.tsdecodes the SSH channel's stdout and stderr with oneStringDecoder('utf8')per stream instead of callingBuffer#toString()on each packet. Both decoders are flushed withend()inonClosebefore the stdout fence is read and the listing is parsed.项目turned into���目). The garbled name pointed at a path that doesn't exist, so picking it failed. Error messages on stderr could be garbled the same way.ssh-remote-directory-browse.test.ts, which feeds raw stdout split in the middle of项through a fake channel and checks the entry is项目.Why
A remote
lswrites to a pipe in blocks, and sshd forwards each read as its own packet, so any listing bigger than one block can split a character. #50298 fixed the same problem inspawnCommandCapturewith aStringDecoder, which is the standard Node way to decode a byte stream that arrives in chunks. Collecting raw buffers and decoding once on close would also work, but it would hold every chunk in memory and differ from #50298 for no benefit.Linked Issue
Fixes #50943
Visual Proof
N/A: no UI change of its own. The fix changes which names the existing folder list receives, and the difference only shows up when a packet boundary lands inside a character, which can't be reproduced on demand in a screenshot. The before/after is shown in the test output below.
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
pnpm exec vitest run src/main/ssh/filesystem/passes on this branch. Withorigin/main'sssh-remote-directory-browse.tsswapped in, the new test fails: expected项目, received���目.A separate probe ran the real
browseSshDirectorythrough a fake channel for four cases: a 4-byte emoji plus CJK split at every byte boundary, a multibyte stderr error message, and the Windows path with no fence. On main all four were garbled (/home/��,ls: ������ '������',C:/Users/������). On this branch all five probe tests pass.Contributor's end-to-end probe: the real code ran the generated remote command over 300 CJK-named folders, with output delivered in 4096-byte packets. main had 1 entry with U+FFFD; this branch had 0.
Ran on macOS with a fake channel, which replaces only the SSH transport. The decoder sits on the main process, so it works the same for every desktop OS and remote host, including the Windows-host PowerShell path that uses the same handler.
Static gates on the touched files: anti-slop oxlint, code-quality native plugins, ast-grep,
check-changed-code-quality, oxlint and oxfmt are all clean.Performance
None, because this only runs when the user browses a folder in the SSH add-project picker. It runs once per directory listing in the main process, not on a hot path, and doesn't touch the renderer, polling or terminal streams. Benchmark (node, old
toStringper packet vs newStringDecoder, mean of 20 runs):No new I/O, subprocesses or polling, and nothing comes close to a 16 ms stall.
Risk
Level: Low
ASCII-only listings decode to exactly the same bytes as before. The only behavior change is for multibyte characters that crossed a packet boundary, which used to be garbled. Nothing changes on the remote side and nothing is persisted, so mixed-version remotes aren't affected. To back out, a plain revert is enough.
Review
Focus on the two
end()calls inonClose. They flush any trailing partial bytes beforefence.readStdoutruns. The timeout and error paths reject without parsing, so they don't need a flush.Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Maintainer update: squashed onto current main and added a regression test; the fix itself is unchanged.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)