Skip to content

fix(ssh): keep multibyte file names intact when a remote folder listing spans several packets - #50944

Merged
nwparker merged 1 commit into
stablyai:mainfrom
Pr1p:fix/ssh-browse-multibyte-chunks
Nov 27, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
Pr1p:fix/ssh-browse-multibyte-chunks

Conversation

@Pr1p

@Pr1p Pr1p commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

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

  • runBrowseCommand in src/main/ssh/filesystem/ssh-remote-directory-browse.ts decodes the SSH channel's stdout and stderr with one StringDecoder('utf8') per stream instead of calling Buffer#toString() on each packet. Both decoders are flushed with end() in onClose before the stdout fence is read and the listing is parsed.
  • Before: a name whose UTF-8 bytes were split across two packets became U+FFFD replacement characters (for example 项目 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.
  • After: an incomplete character at the end of one packet is held until the next packet arrives, so names and error text come through unchanged.
  • Adds 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 ls writes 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 in spawnCommandCapture with a StringDecoder, 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. With origin/main's ssh-remote-directory-browse.ts swapped in, the new test fails: expected 项目, received ���目.

  • A separate probe ran the real browseSshDirectory through 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 toString per packet vs new StringDecoder, mean of 20 runs):

Case old new
200 ASCII names, 1 packet 0.001 ms 0.002 ms
200 CJK names, 1 packet 0.002 ms 0.008 ms
50k CJK names, 230 × 4 KB packets 1.66 ms 1.75 ms
5k CJK names, 88,899 × 1-byte packets 4.40 ms 2.50 ms

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 in onClose. They flush any trailing partial bytes before fence.readStdout runs. The timeout and error paths reject without parsing, so they don't need a flush.

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

Maintainer update: squashed onto current main and added a regression test; the fix itself is unchanged.

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)

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

runBrowseCommand now uses separate UTF-8 StringDecoder instances for stdout and stderr. It incrementally decodes incoming SSH packets and flushes both decoders when the channel closes, before processing the output. A test splits the UTF-8 bytes for 项目 across two packets and checks that browseSshDirectory returns the intact name as a directory.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 67389

This change keeps non-ASCII folder names intact in the SSH remote folder browser when their bytes arrive across packets. It is small and localized, has a test for the split-packet case, and shows no concrete merge risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: multibyte file names stay intact when a remote folder listing arrives in several SSH packets. The changeset decodes stdout and stderr with StringDecoder in runBrowseCo…
Linked Issues check Passed Active directly linked issue #50943 requires every remote folder name to arrive intact regardless of SSH packet boundaries. At the reviewed head, runBrowseCommand in src/main/ssh/filesystem/ssh-remote…
Out of Scope Changes check Passed The whole-PR diff against the merge base touches two files. The source file changes are limited to the StringDecoder import, the two decoder declarations with a comment, the two write() calls replacin…
Description check Passed The description follows the repository template closely. It covers ELI5, What Changed, Why, Linked Issue (Fixes #50943), Visual Proof (N/A with reason), Testing with results, Performance with a benchm…
Full details: Title check

Explanation

The title names the main change: multibyte file names stay intact when a remote folder listing arrives in several SSH packets. The changeset decodes stdout and stderr with StringDecoder in runBrowseCommand and adds a test for a split multibyte directory name, so the title matches the change. It also states the scope in plain terms.

Full details: Linked Issues check

Explanation

Active directly linked issue #50943 requires every remote folder name to arrive intact regardless of SSH packet boundaries. At the reviewed head, runBrowseCommand in src/main/ssh/filesystem/ssh-remote-directory-browse.ts decodes stdout and stderr with one StringDecoder('utf8') each through write(), which carries partial UTF-8 bytes into the next packet. Both decoders call end() in the close handler before stdout is passed to fence.readStdout, so trailing partial bytes are flushed before parsing. The change addresses the reported defect. The PR description says no test was committed, but the head adds src/main/ssh/filesystem/ssh-remote-directory-browse.test.ts. That test splits the bytes of '项目' across two data packets and expects the entry '项目' with isDirectory true. This is automated regression coverage for the requirement. #50298 is closed and is treated as background only. The reported before/after probe result is not independently re-run here, but the code path and test establish the behavior.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base touches two files. The source file changes are limited to the StringDecoder import, the two decoder declarations with a comment, the two write() calls replacing toString(), and the two end() calls in the close handler. All of these serve the #50943 decoding fix. The new test file adds one Vitest case for a multibyte name split across two packets. It directly supports the same objective and is not unrelated. The only inconsistency is documentary: the PR description states that no test is committed, while the head contains this test. The test file does not change behavior outside the scope of the fix. Not verified: whether the new test fails on the base revision, because that was not run.

Full details: Description check

Explanation

The description follows the repository template closely. It covers ELI5, What Changed, Why, Linked Issue (Fixes #50943), Visual Proof (N/A with reason), Testing with results, Performance with a benchmark table, Risk with level Low and a backout path, Review focus, and the checklist. The AI Disclosure section is left empty, which the template allows for internal contributors, but the author's status is not stated. The raw summary describes the code change and test, which matches the description. The description also cites #50298 as a precedent, which is consistent with the objectives.

  • 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: cffbf232-37dd-494e-8ea3-8437abf47c80
Commits

Reviewing files that changed from the base of the PR and between 86ed47c and 673893f.

Files selected for processing: 1

  • src/main/ssh/filesystem/ssh-remote-directory-browse.test.ts

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

Finishing Touches
Fix failing CI checks

  • Create a new PR

…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]>
@nwparker
nwparker force-pushed the fix/ssh-browse-multibyte-chunks branch from 86ed47c to 673893f Compare November 27, 2026 14:58
@nwparker nwparker closed this Nov 27, 2026
@nwparker nwparker reopened this Nov 27, 2026
@nwparker
nwparker merged commit eb8cf68 into stablyai:main Nov 27, 2026
149 of 154 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]: SSH remote folder browser garbles non-ASCII names that span two packets

2 participants