Skip to content

feat(desktop): connect Windows to WSL Host over stdio mux - #7056

Merged
M4n5ter merged 15 commits into
apache:rust-previewfrom
me2seeks:feat/wsl-stdio-desktop
Nov 21, 2026
Merged

M4n5ter merged 15 commits into
apache:rust-previewfrom
me2seeks:feat/wsl-stdio-desktop

Conversation

@me2seeks

@me2seeks me2seeks commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Connect Windows Desktop to the same user's WSL Host using wsl.exe --exec, a Yamux session over stdin/stdout, and the existing Linux local IPC endpoint. Local Windows Desktop remains unchanged. WSL does not need a TCP listener, address discovery, or peer credentials.

Uses the Host client channel opener already merged into rust-preview in #7028. Supersedes the WSL transport experiment in #7011; ordinary remote Linux and mobile transports are not part of this change.

Verification

  • Built Windows Desktop and the Linux Maka CLI (--no-default-features).
  • Native Windows Desktop cold-started the isolated Ubuntu Root ~/.maka/wsl-stdio-e2e. The Host reported ephemeral lifecycle and three concurrent active calls.
  • Sent SIGTERM only to that disposable Host. The same Desktop process connected to the new epoch and opened three active calls again. Ubuntu and existing Roots were left alone.
  • Focused bridge tests exercised concurrent channels, startup handoff and a 512 KiB half-close round trip.
  • Regenerated third-party notices for Yamux.

Follow-ups before merge

  • Confirm the isolated Desktop exits normally and its ephemeral Host retires: the Windows launcher returned exit code 0, the Host PID exited, and the test Root no longer had a live Host registration. Ubuntu stayed running. The exact UI gesture was not observed.
  • Confirm required CI and reviews.

AI use

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Maka implemented and exercised the bridge and prepared this PR.

Checklist

  • Tests cover the change and fail without it
  • Format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

@Astro-Han Astro-Han left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update at ca2f2329fda88da2e14995b4c08506723db06120: both earlier CI P2 findings are resolved and withdrawn. I read the full increment from 635010da71e472fe3a3820e315d6fad48c9ebf10: it adds the WSL bridge, web-time and Yamux inventory entries and restores the existing component digests in the notice manifest. The current tooling job and Linux job both passed. Their original logs execute the dependency inventory check and notice coverage check; the tested inventory/manifest match this head.

The original omitted-inventory and clipboard-rs digest findings applied to the earlier head. The corresponding inline comments are marked resolved below.

This is a scoped build-metadata fix verification, not full acceptance of the 23-file Windows/WSL transport. Normal window-close retirement remains unchecked in the PR body. Root identity and authority across restart, startup/residency handoff, cancellation/half-close, journal isolation, all existing local/remote consumers, and real Windows/WSL Desktop behavior still require full validation. I did not run local Cargo tests or native GUI verification. Other CI failures remain, and I have not attributed them all to this change. No protocol epoch file is changed; that alone does not establish compatibility.

Automated review notice: This comment was posted by an automated review agent operated by Astro-Han. It is not an independent human review and does not replace one.

tokio = { workspace = true, features = ["io-util", "sync"] }
tokio-util = { workspace = true, features = ["compat"] }
uuid.workspace = true
yamux = "0.13.10"

@Astro-Han Astro-Han Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved at ca2f2329fda88da2e14995b4c08506723db06120; the earlier P2 is withdrawn. The missing distribution inventory entries are now present and tooling job 136006388078 passed. This resolves this scoped CI finding, not full transport acceptance.

Comment thread products/maka/cli/notices.json Outdated
"cargo:[email protected] registry+https://github.com/rust-lang/crates.io-index": "663bce254470eb5563d5b41d8a8b2eceb366748b2784728fe4135b7c0cd4a3dd",
"cargo:[email protected] registry+https://github.com/rust-lang/crates.io-index": "059622eb0e6a6598829c284732c57f80f934f7c818105e7fbacc32306b915823",
"cargo:[email protected] git+https://github.com/maka-agent/cua?rev=b97a7e7a97b1dabc669b7c362ba39691766df761#b97a7e7a97b1dabc669b7c362ba39691766df761": "e8154cd8ea7de8534d8b6b013574384e3fac91e1b80d02cffc097a660a17fa47",
"cargo:[email protected] git+https://github.com/maka-agent/cua?rev=b97a7e7a97b1dabc669b7c362ba39691766df761#b97a7e7a97b1dabc669b7c362ba39691766df761": "850710858a2299e8104689c650715d9cd56be498291ca81e2cdb20e8b0a3c72a",

@Astro-Han Astro-Han Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved at ca2f2329fda88da2e14995b4c08506723db06120; the earlier P2 is withdrawn. The existing component digest is restored and Linux notice coverage job 136006388235 passed. This resolves this scoped CI finding, not full transport acceptance.

@github-actions github-actions Bot added the effort/XL Under 2500 readable lines label Nov 20, 2026
@me2seeks

Copy link
Copy Markdown
Contributor Author

CI comparison for f50086c: the Windows Desktop 2 lane failed on MAIN_DRAFT and Close side pane. The exact rust-preview base 0716ea7 reproduces MAIN_DRAFT (job 136177901986); the earlier unchanged rust-preview base 874817f reproduces both (job 136099594884). This is baseline evidence for the assertions, not a request to waive CI.

@me2seeks
me2seeks marked this pull request as ready for review November 20, 2026 17:44
@github-actions github-actions Bot added effort/L Under 1000 readable lines and removed effort/XL Under 2500 readable lines labels Nov 21, 2026

@M4n5ter M4n5ter left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

English

This is a huge improvement over #7011 — the maka-wsl-bridge protocol layer, stdio exclusivity, residency handoff, and the 512 KiB half-close bridge test are all clean and minimal.

There is one merge-blocking bug in the Windows Desktop lifecycle path and two smaller P2 issues to address before merging (reviewed at 367e5164):

1. [P1] run_app_with_config calls std::process::exit, making the WSL reconnect loop and host::quit unreachable

  • In third-party/nsh/crates/nsh-platform-windows/src/app.rs (lines 697–720), once the UI thread finishes, run_app_with_config calls std::process::exit(if succeeded { 0 } else { 1 }) directly (intentionally, to avoid graphics driver teardown deadlocks under the loader lock — see lines 617–628).
  • Because run_app_with_config never returns after a window opens:
    • When the WSL anchor disconnects, direct2d.rs:74–76 calls quit_app(), which ends the entire maka-desktop-shell.exe process. The cleanup block in direct2d.rs:94–118, bridge.close(), and the reconnect loop in desktop-shell/src/wsl_stdio.rs:58–70 are all unreachable.
    • Explicit user exit ("Quit Maka" / closing the window) also bypasses direct2d.rs:105 (host::quit(bindings)). Local Windows mode still retires ephemeral Hosts because the parent launcher in cli/src/desktop.rs:58–61 holds a local Client and calls quit_ephemeral() after the shell exits 0, whereas the new WSL launcher path (cli/src/desktop.rs:85–92) simply forwards the exit code. Observing an ephemeral Host eventually exit after pipe EOF does not confirm that an explicit Quit was delivered.
  • Suggested fix: keep the Windows message loop and window alive instead of exiting via quit_app() on disconnect (and don't change nsh-platform-windows's std::process::exit to return, which would reintroduce the driver teardown hang). AppView::load_with_config (nsh-platform-windows/src/app.rs:504) already exists, so Windows can follow the same in-window rebind pattern as appkit.rs:144–260:
    • Drive disconnect detection (without gating on foreground.wait_for(|active| *active), which stalls if the window starts or stays unfocused in the background), close the old bindings + bridge, reconnect with backoff (avoiding tight crash loops), and rebind in place via with_running_view(|view| view.load_with_config(config)).
    • On explicit user quit, run host::quit(bindings) and bridge.close() before calling quit_app().
  • Verification: re-verify on the updated SHA against an isolated Root by logging the maka-desktop-shell.exe PID alongside the Host epoch — after terminating the Host, confirm the same shell PID completes calls against the new epoch, and on explicit menu quit confirm the Host actually receives Quit.

2. [P2] "Choose folder…" in WSL mode passes a Windows path straight to the Linux Host

  • direct2d.rs:143–150 returns the Windows native picker path (e.g. C:\src\project) verbatim to Workbench, which submits it to updateWorkspaceLocations. On the Linux Host, PublishedDirectory::open checks path.is_absolute() and rejects it with published root must be absolute.
  • Minimal fix: disable/hide the Windows native folder picker for WSL sessions so Workbench uses the existing Host directory browser (or explicitly translate paths for the selected distro).

3. [P2] cli/src/wsl_stdio.rs enforces an arbitrary 128-channel cap and relies on an implicit first-stream assumption

  • At cli/src/wsl_stdio.rs:117–119, if channels.len() >= 128 returns Err("too many WSL IPC channels") and tears down the entire WSL helper and all active calls (and without biased;, completed tasks in channels.join_next() aren't guaranteed to be reaped before mux.accept()). This 128 cap has no basis here: yamux::Config::default() already bounds concurrent streams and receive windows at the mux layer, and local Host::serve imposes no arbitrary channel cap on same-user IPC. Remove the channels.len() >= 128 check altogether, and add biased; with channels.join_next() ahead of mux.accept() so finished tasks are reaped promptly.
  • At cli/src/wsl_stdio.rs:121, closed.take() implicitly binds anchor-loss tracking to whichever non-bootstrap stream is accepted first. If any caller ever probes Client::status over the opener before Client::connect_on, that short-lived stream closing will immediately trigger anchor loss. Either mark the anchor stream explicitly or document and enforce the invariant at the bridge boundary.
简体中文

相比 #7011 提升非常大——maka-wsl-bridge 协议层、stdio 独占、residency 交接以及 512 KiB 半关闭行为测试都很干净克制。

按 367e5164 逐行核对下来,Windows Desktop 生命周期路径里有一处卡合并的 P1,另外有两处 P2 建议合入前一起修掉:

1. [P1] run_app_with_config 退出时直接调用 std::process::exit,导致 WSL 重连循环和 host::quit 全部不可达

  • 在 third-party/nsh/crates/nsh-platform-windows/src/app.rs(697–720 行),UI 线程结束后 run_app_with_config 会直接调用 std::process::exit(if succeeded { 0 } else { 1 })(这是有意为之,用来规避显卡驱动在线程析构时于 loader lock 下挂死,见 617–628 行注释)。
  • 因此只要窗口正常打开,run_app_with_config 根本不会 return:
    • WSL anchor 断开后,direct2d.rs:74–76 调用 quit_app(),直接结束了整个 maka-desktop-shell.exe 进程。direct2d.rs:94–118 的清理逻辑、bridge.close() 以及 desktop-shell/src/wsl_stdio.rs:58–70 的重连 loop 全都走不到。
    • 用户主动退出(Quit Maka / 关窗)同样会绕过 direct2d.rs:105 的 host::quit(bindings)。本地 Windows 模式之所以还能退掉 ephemeral Host,是因为父进程 cli/src/desktop.rs:58–61 持有本机 Client 在子进程返回 0 后代发 quit_ephemeral();而新增的 WSL 启动器路径(cli/src/desktop.rs:85–92)只是透传退出码,没人发过显式 Quit。管道强制断开后空闲 Host 最终自行退休,并不能说明显式 Quit 已送达。
  • 建议修法:保持 Windows 消息循环与现有窗口存活,不要在断线时通过 quit_app() 结束进程(也不要把 nsh-platform-windows 的 std::process::exit 改成 return,否则会重新引入显卡驱动析构死锁)。AppView::load_with_config(nsh-platform-windows/src/app.rs:504)已经现成可用,建议参考 appkit.rs:144–260 的窗口内换绑模式:
    • 在后台任务中监听断线(不要卡在 foreground.wait_for(|active| *active) 上,否则窗口在后台启动或未获焦点时断线会一直假死),关闭旧 bindings 和旧 bridge,带退避重连(避免 crash loop 死循环),然后通过 with_running_view(|view| view.load_with_config(config)) 在当前窗口内换绑新连接。
    • 用户明确退出时,先完成当前 epoch 的 host::quit(bindings) 和 bridge.close(),再调用 quit_app() 退出进程。
  • 验收建议:修改后用独立 Root 实测时记录 maka-desktop-shell.exe 的 PID 和 Host epoch——杀掉 Host 后确认同一个 shell PID 能向新 epoch 完成调用,并从菜单退出确认 Host 确实收到了 Quit。

2. [P2] WSL 模式下 “Choose folder…” 会把 Windows 路径原样提交给 Linux Host

  • direct2d.rs:143–150 把系统对话框返回的 Windows 路径(如 C:\src\project)原样交给 Workbench,Workbench 随即提交给 updateWorkspaceLocations。Linux Host 的 PublishedDirectory::open 校验 path.is_absolute() 时会直接报 published root must be absolute 拒绝。
  • 最小修法:在 WSL 会话下收起 Windows 原生目录选择器,让 Workbench 走已有的 Host 目录浏览入口(或者按所选 distro 显式做路径转换)。

3. [P2] cli/src/wsl_stdio.rs 有无依据的 128 通道硬上限,且隐式假设第 1 条普通流必为 anchor

  • cli/src/wsl_stdio.rs:117–119 在 channels.len() >= 128 时直接返回 Err("too many WSL IPC channels"),把整个 WSL helper 和所有在途调用一起杀掉(且 tokio::select! 未加 biased;,已完成任务可能还没走 channels.join_next() 就先被 mux.accept() 计入)。这个 128 上限本身没有依据:yamux::Config::default() 在多路复用层已经有并发流数与接收窗口控制,本机 Host::serve 对同用户 IPC 也不设这种随手拍的通道数上限。建议直接删掉 channels.len() >= 128 检查,并给 tokio::select! 加 biased; 将 channels.join_next() 放到 mux.accept() 之前,确保已结束的任务被及时收割即可。
  • cli/src/wsl_stdio.rs:121 的 closed.take() 隐式把第一条接受的非 bootstrap 子流绑定为 anchor 断线监控。如果以后有调用方在 Client::connect_on 之前先经同一 opener 探测一次 Client::status,该短命流关闭后会立刻误触发 anchor 丢失。建议显式标记 anchor 流,或在桥接边界明确约束该不变量。

@M4n5ter

M4n5ter commented Nov 21, 2026

Copy link
Copy Markdown
Member
English

Pushed e33076ef8 (merge latest rust-preview) and d021e98cc to address the three review items:

  1. In-window Direct2D WSL reconnect & explicit quit ordering (direct2d.rs, wsl_stdio.rs, nsh-platform-windows): Keep the Windows message loop and window alive across WSL Host disconnects (view.stop() → detach bindings & close bridge → backoff reconnect → view.load_with_config(...)), show a hidden window if reconnect fails, clean up the tray icon on Surface::stop() and allow native close while stopped, and complete host::quit(bindings) + bridge.close() before calling quit_app() on explicit quit.
  2. Disable Windows native folder picker in WSL mode (host.rs, direct2d.rs, workbench): Attach RemoteHostFilesystem on WSL connections, hide Choose folder… in WorkspacePicker when host.localFolderPicker === false, and reject folder-picker requests at the direct2d.rs WSL boundary.
  3. Remove arbitrary 128-channel cap & enforce handoff order (cli/src/wsl_stdio.rs, wsl-bridge/src/lib.rs): Drop the channels.len() >= 128 limit, use biased; so completed channel tasks are reaped before accepting new streams, fail residency handoff if no Host anchor connected before handoff completion, and document the stream-order protocol invariant.

Verification

  • Builds, lints & unit tests: cargo fmt --check, cargo clippy -D warnings (macOS & Windows), maka-wsl-bridge tests (macOS / Windows / WSL2), maka-workbench Rust (79/79) + JS (222/222) + ui_types / tsc, nsh-platform-windows lib tests in Windows Console Session 1 (359/359), plus asf-license-headers, dependencies, and notices.
  • Live Windows 11 Direct2D ↔ WSL2 E2E (Console Session 1, isolated --wsl-root):
    • Initial launch: maka-desktop-shell.exe PID 10552 connected to WSL Host PID 21 (epoch 1333f45e-cda6-4025-b4c9-11ee91a42b06) and rendered Workbench.
    • After kill -9 21 inside WSL: the same maka-desktop-shell.exe PID 10552 stayed alive and reconnected in-place inside the same window to new Host PID 150 (epoch 745f2f3c-90c8-46d6-b730-42e8e568646f).
    • Workspace Picker (Ctrl+N): verified Choose folder… is hidden while remote directory browsing works.
    • Explicit quit (Ctrl+Q): shell and launcher exited with 0 in 0.56s, Host PID 150 retired in 0.71s, and no maka-desktop-shell.exe or __maka-wsl-stdio-v1 processes remained.
简体中文

已推送 e33076ef8(合并最新 rust-preview)和 d021e98cc,修复了上一轮 review 的三处问题:

  1. Windows Direct2D 窗口内原位重连与显式退出顺序(direct2d.rs、wsl_stdio.rs、nsh-platform-windows):WSL Host 断开时保留 Windows 消息循环和窗口,走 view.stop() → 清理绑定与关闭 bridge → 退避重连 → view.load_with_config(...) 原位换绑;重连失败时拉起隐藏窗口;Surface::stop() 时清理旧托盘图标并允许停止态窗口正常关闭;用户显式退出时先完成 host::quit(bindings) 和 bridge.close() 再调用 quit_app()。
  2. WSL 模式下禁用 Windows 原生目录选择器(host.rs、direct2d.rs、workbench):WSL 连接挂上 RemoteHostFilesystem 标记,WorkspacePicker 在 host.localFolderPicker === false 时隐藏 Choose folder…,同时在 direct2d.rs WSL 边界拒绝目录选择请求。
  3. 移除无依据的 128 通道上限并校验 handoff 顺序(cli/src/wsl_stdio.rs、wsl-bridge/src/lib.rs):去掉 channels.len() >= 128,加 biased; 优先回收已结束任务,handoff 完成时校验 Host anchor 已建立,并补充流顺序协议不变量说明。

验证记录

  • 构建、检查与单测:cargo fmt --check、macOS & Windows cargo clippy -D warnings、macOS / Windows / WSL2 maka-wsl-bridge 单测、maka-workbench Rust(79/79)+ JS(222/222)+ ui_types / tsc、Windows Console Session 1 nsh-platform-windows 单测(359/359),以及 asf-license-headers / dependencies / notices。
  • Windows 11 Direct2D ↔ WSL2 实机 E2E(Console Session 1,隔离 --wsl-root):
    • 首次启动:maka-desktop-shell.exe PID 10552 连上 WSL Host PID 21(epoch 1333f45e-cda6-4025-b4c9-11ee91a42b06),Workbench 正常渲染。
    • 在 WSL 内 kill -9 21 后:同一个 maka-desktop-shell.exe PID 10552 存活并在原窗口内重连到新 Host PID 150(epoch 745f2f3c-90c8-46d6-b730-42e8e568646f)。
    • 打开 Workspace Picker(Ctrl+N):确认 Choose folder… 已隐藏,远端目录浏览正常。
    • 显式退出(Ctrl+Q):shell 与 launcher 在 0.56s 内返回 0 退出,Host PID 150 在 0.71s 内收到 quit 退休,无残留 maka-desktop-shell.exe 或 __maka-wsl-stdio-v1 进程。

@M4n5ter M4n5ter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All review items addressed and verified end-to-end on Windows 11 + WSL2.

@M4n5ter
M4n5ter merged commit fda1503 into apache:rust-preview Nov 21, 2026
12 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/L Under 1000 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants