Repository navigation
fix(remote): WSL 连接失败读 wsl.exe 的标准输出,找不到发行版报 unreachable,中文消息也能识别 (Refs 1lck/Lithe-IDEA#2231) - #169
Merged
Merged
Conversation
1lck/Lithe-IDEA#2231) wsl.exe 把自己的失败写在标准输出上,标准错误为空(发行版启动后才会在标准错误加一行)。 探测读到流结束时 LaunchError::NoShell 丢掉了这些内容,classify_wsl 只看标准错误, 所以未安装的发行版报 failed,诊断只剩退出码。 - LaunchError::NoShell 带上流结束前读到的行(output),日志分类和错误文字不含它们 - wsl::failure_text 先读标准输出、再读标准错误;classify_wsl 用它分类和生成诊断 - wsl::output_text 识别以非 ASCII 字符开头的 UTF-16LE(如中文消息) - 假 wsl.exe 的测试改为写标准输出,补中文、UTF-8 和找不到用户的情况 - 契约写明诊断来自哪个流
This was referenced Nov 22, 2026
fix(desktop): 固定 Core #169,WSL 没装的发行版说明无法连接、未知用户带 wsl.exe 的消息,补真实主机验收测试 (#2231)
1lck/Lithe-IDEA#2300
Merged
xiaoyumuxi
marked this pull request as ready for review
November 22, 2026 05:29
1 task done
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
关联 Issue
1lck/Lithe-IDEA#2231(远程开发完整设计)#43c 的 Windows 实机验收(#2299 已合入,修复与验收测试在桌面 Draft 1lck/Lithe-IDEA#2300)中发现:连接一个没装的 WSL 发行版时,
remote.connect报failed,诊断只有退出码。契约写的是unreachable,并且diagnostics应带wsl.exe的消息。类型
wsl.exe的标准输出;不新增命令、错误码或日志事件,远端服务协议不变原因
在 Windows 实机上分别抓
wsl.exe --distribution <名字> [--user <用户>] --cd ~ --exec true的两个输出流:Wsl/Service/WSL_E_DISTRO_NOT_FOUNDWsl/WSL_E_USER_NOT_FOUNDgetpwnam(...) failed不设
WSL_UTF8时标准输出是不带 BOM 的 UTF-16LE,设了就是 UTF-8。wsl.exe的失败消息写在标准输出,Core 却只看标准错误:launch::probe)逐行读标准输出,读到流结束返回LaunchError::NoShell,读到的内容随之丢掉;classify_wsl只拿到空的标准错误,所以报failed,诊断是 "wsl.exe exited with status …"。原来的单元测试让假
wsl.exe把消息写到标准错误,和真实行为不一致,所以没测出来。另外,
wsl::output_text只有在第二个字节是 NUL 时才按 UTF-16LE 解码。中文消息以汉字开头("不" 编码为0D 4E),会被当成 UTF-8 解成乱码,错误码也就匹配不到。只有不认WSL_UTF8的旧版 WSL 会走到这条路径。改动说明
crates/remote/src/client/launch.rsLaunchError::NoShell改为NoShell { output }。output是流结束前读到的行,每行带换行,上限沿用探测的输出上限;探测之后流才结束时为空。read_line只去掉\n一个字节,所以按行拼回就是原始字节,UTF-16 不会被切坏;只是最后一行没有换行时会多出一个\n,它补不成完整的 UTF-16 码元,解码时被舍掉。Display和failure_category不变,都不含输出内容(日志只记分类)。a_stream_that_ends_before_the_probe_keeps_what_it_carried:分别输入中文 UTF-16 消息和 UTF-8 消息,解码后与原文一致;空流时output为空。crates/remote/src/client/connection_log.rs:matches!跟着改成NoShell { .. },行为不变。crates/remote/src/client/wsl.rsfailure_text(stdout, stderr):先读标准输出,再读标准错误,各自按output_text解码,去掉空白部分后用换行连接。output_text增加一条:不是合法 UTF-8 且奇数偏移有 NUL 时按 UTF-16LE 解码(UTF-16LE 的换行和 ASCII 错误码都会产生这样的 NUL);合法 UTF-8 里偶尔混进的 NUL 仍按 UTF-8 解码。failure_text的顺序和空白处理。crates/workspace/src/probe.rs、sessions.rs(只改调用处)classify_wsl(exit, stdout, stderr)改用failure_text。WSL_E_DISTRO_NOT_FOUND报unreachable;其他失败(例如用户不存在)报failed,诊断是wsl.exe的原始消息。connect的NoShell分支把output传给classify_wsl。SSH 和容器的分类不变。crates/workspace/src/probe/tests.rs:假wsl.exe改为把消息写到标准输出,覆盖英文 UTF-16、中文 UTF-16、中文 UTF-8 三种(都应是unreachable、诊断为原文),以及用户不存在(failed,诊断为标准输出的消息加标准错误的一行)。contracts/rust-core-api.md:remote.connect的 WSL 段写明诊断先取标准输出、再取标准错误,并举出"用户不存在"作为failed的例子。验证
cargo test -p lithe-remote -p lithe-workspace:remote 166 个、workspace 83 个全部通过cargo clippy -p lithe-remote -p lithe-workspace --all-targets -- -D warnings:无告警cargo fmt --alldesktop/internal/core/remote_acceptance_test.go(桌面 Draft fix(desktop): 固定 Core #169,WSL 没装的发行版说明无法连接、未知用户带 wsl.exe 的消息,补真实主机验收测试 (#2231) 1lck/Lithe-IDEA#2300,暂时固定到本 PR 的edad041):18feb4a):没装的发行版报failed,诊断只有退出码unreachable,诊断带WSL_E_DISTRO_NOT_FOUND;不存在的用户报failed,诊断带WSL_E_USER_NOT_FOUND;断线后 resume 接回运行、“保留”关闭后接回进程也都通过edad041换成 main 上的对应提交