Skip to content

feat(desktop): connect Windows Desktop to WSL Host over peer streams - #7011

Closed
me2seeks wants to merge 3 commits into
apache:rust-previewfrom
me2seeks:feat/wsl-peer-desktop
Closed

me2seeks wants to merge 3 commits into
apache:rust-previewfrom
me2seeks:feat/wsl-peer-desktop

Conversation

@me2seeks

@me2seeks me2seeks commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add an explicit Windows Desktop WSL startup target. Local keeps using IPC and does not start a peer endpoint.
  • Reuse Preview's authenticated Host WebSocket protocol with one peer stream per Host channel. WSL startup control only publishes addresses and identity; there is no transport fallback.
  • Import the mainline Rust peer engine and align the two vendored Deno AES pins.

Verification

  • Windows CLI and native Desktop built; the Linux CLI built in Ubuntu WSL with --no-default-features.
  • The native Workbench opened a control session and UI session and had two concurrent active calls over one cross-boundary peer TCP connection in mirrored mode.
  • Sent SIGTERM to the isolated Linux Host only. The same Windows Desktop process reconnected to a new Host epoch for the same Root. Ubuntu stayed running.
  • The Host runtime integration test checked invalid Bearer rejection and independent WebSocket call channels.
  • A regression test reproduced overlapping stream-open rejection before the fix and passed eight independent round trips after it; the native Workbench loaded the home, settings, search, automation, and workspace picker views.

Scope and follow-ups

This PR requires a compatible Linux Maka executable already present in the selected distro (passed via --wsl-maka). Fresh-distro setup, automatic installation, and a startup picker are out of scope. The WSL Host currently runs in service mode; idle retirement is not changed here.

  • Measure small-request responsiveness while the native Workbench terminal is producing sustained output.
  • Serialize concurrent cold starts and cover delayed first pairing after pending credential expiry.
  • Review reconnect behavior when only the Host anchor drops, and clarify the scope of full Mesh product integration. This draft wires WSL direct connections, not the full roster/discovery/relay authorization layer.

AI use

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

Tool(s) and scope: Maka implemented, reviewed and exercised the draft WSL transport and Desktop wiring.

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

@github-actions github-actions Bot added the effort/XXL Over 2500 readable lines label Nov 19, 2026
@me2seeks
me2seeks marked this pull request as ready for review November 19, 2026 08:38

@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

Thanks for putting this together and exercising the Windows Desktop ↔ WSL flow end to end. I'd hold off on merging the current approach — not because WSL support isn't wanted, but because pulling the full peer stack into the core workspace goes against where we want rust-preview's transport boundary to land.

Why we shouldn't merge this shape

  1. 41k+ lines of transport/crypto weight for a local WSL hop:

    • Bringing platform/peer (~10.2k lines, libp2p + pinned webrtc-rs) into the main workspace forces vendoring ~31k lines of deno-crypto and deno-node-crypto just to reconcile the aes pin (0.8.3 vs 0.8.4), even though this WSL path doesn't use WebRTC, relays, Kademlia, or QUIC at all (127.0.0.1 TCP only).
    • Longer term, we plan to introduce the mainline peer engine as a plugin, and also leave room for a self-hosted Maka Server for multi-Host communication and collaboration. Core crates (cli, desktop-shell, host-runtime) shouldn't depend on PeerId, Multiaddr, or ConnectivitySnapshot.
  2. Concrete transport & lifecycle issues in the current draft:

    • Unnecessary layering & serialization: every Host call goes through wire -> WebSocket -> 1-byte kind -> 64KB duplex bridge (stop-and-wait per-write oneshot ACK) -> yamux/noise -> 127.0.0.1 TCP -> same-process loopback TcpStream::connect + copy_bidirectional -> WebSocket -> wire, with all concurrent stream opens serialized behind a global Mutex in Endpoint::open.
    • Stale pending credential: wsl_peer::Listener::new calls host.prepare_access once at startup and serves that cached token forever; once the 15-minute Pending TTL expires before first pairing, the Host becomes permanently unreachable until restarted.
    • Fragile Desktop lifecycle: direct2d.rs couples window teardown to maka_peer::ConnectivitySnapshot, loops reconnects without separating user exit vs. disconnect cleanly, drops runtime.shutdown_background() while keeping spawned tasks from previous sessions on the shared runtime, and binds 127.0.0.1 (mirrored-mode dependent).

Recommended direction (split into two small PRs)

Two pieces this PR identified are genuinely the right cuts: host::Client needs a transport-agnostic way to open multiple streams to the same target, and workbench::host::admit needs to decouple the expected root_id from the local client data directory.

Instead of importing platform/peer, we can keep the core boundary minimal and let WSL, future Peer plugins, and a future Maka Server all sit cleanly on top of it:

  1. PR 1 — Minimal Client stream-opener abstraction (platform/host-runtime):

    • Abstract repeated dialing in host::Client and CallChannelOpener around an OpenChannel closure returning a boxed async byte stream (ChannelIo: AsyncRead + AsyncWrite + Unpin + Send + 'static, OpenChannel = Arc<dyn Fn() -> BoxFuture<'static, io::Result<Channel>> + Send + Sync>), exposing Client::connect_on(open, epoch) alongside Client::connect(path, epoch).
    • Keep Host::channel / wire framing as-is (no per-substream HTTP/WebSocket upgrade when the underlying transport already multiplexes raw streams, and no TransportKind / Host ingress trait yet — we can extract a guarded Ingress from Host::serve when the first direct remote/plugin transport lands).
  2. PR 2 — Lightweight WSL wiring (products/maka):

    • Use wsl.exe --exec with a lightweight mux (e.g. plain yamux) owning stdout from byte 0 (diagnostics on stderr), and have the Linux helper forward each normal substream straight to the existing Linux Host Local IPC.
    • This requires zero TCP listeners, works regardless of WSL2 NAT vs. mirrored networking, avoids remote pairing/expiry for a same-user local Desktop, and automatically reuses an already running Linux Host along with its UID check, residency accounting, and graceful drain.
    • A few invariants to make sure we preserve in PR 2:
      • Half-close: Client::close shuts down the write side and waits for Response::Closed; the mux ↔ IPC bridge must propagate half-close rather than dropping the whole stream on first EOF.
      • Cold-start residency handoff: reuse the existing Linux deployment::connect_local (which already holds the launch lease / executor.lock) to hold a short-lived startup Client until Windows establishes its anchor and acks handoff over a one-shot bootstrap substream, then close the startup Client.
      • Connection ownership in desktop-shell: keep Target (distro/root/expected root_id) separate from a single Connection (which owns its WslBridge child process + mux driver, rather than relying on Arc drop). Keep direct2d.rs unaware of yamux/peer, and distinguish user quit (run quit_ephemeral before tearing down the helper) from disconnect/reconnect (fence & clean up, then reconnect without sending Quit).

If this direction sounds good, let's drop platform/peer and third-party/deno-* and start with PR 1. Happy to help review the small opener PR right away.

简体中文

感谢把 Windows Desktop ↔ WSL 的端到端链路跑通。当前形态不太建议直接合入——不是不需要 WSL 支持,而是为了本机 WSL 把整套 peer 栈拖进主 workspace,与 rust-preview 期望的传输边界方向不符。

为什么不建议按当前形态合入

  1. 为了本机 WSL 跨边界,引入了 4.1 万+ 行传输/加密代码包袱:

    • 把 platform/peer(约 1.02 万行,libp2p + 锁定版本的 webrtc-rs)迁进主 workspace,被迫把 deno-crypto 和 deno-node-crypto(约 3.1 万行)整包 vendor 进来,只为了对齐 aes 版本锁(0.8.3 vs 0.8.4);而这套 WSL 路径完全没有用到 WebRTC、Relay、Kademlia 或 QUIC(只走了 127.0.0.1 TCP)。
    • 长期规划上,main 的 peer 引擎后续会以插件形式引入,未来也计划支持用户自部署 Maka Server 用于多 Host 通讯和协作。核心 crate(cli、desktop-shell、host-runtime)不应耦合 PeerId、Multiaddr 或 ConnectivitySnapshot。
  2. 当前草稿中的具体传输与生命周期问题:

    • 多余的协议套娃与串行瓶颈:每条 Host 调用链都要走 wire -> WebSocket -> 1 字节 kind -> 64KB duplex 桥(每次写入同步 oneshot 等 ACK)-> yamux/noise -> 127.0.0.1 TCP -> 同进程再回环 TcpStream::connect + copy_bidirectional -> WebSocket -> wire,且 Endpoint::open 用全局 Mutex 把并发开流串行化了。
    • Pending 凭证过期后永久不可达:wsl_peer::Listener::new 只在启动时调用一次 host.prepare_access 并永久缓存该 token;若首次配对前超过 15 分钟 Pending TTL,之后每次配对都下发过期 token,只能重启 Host。
    • Desktop 生命周期较脆弱:direct2d.rs 直接依赖 maka_peer::ConnectivitySnapshot 触发关窗重连,没有把用户主动退出与断线重连干净区分,删掉 runtime.shutdown_background() 后前一次会话 spawn 的任务仍滞留在共享 runtime 上;同时写死 127.0.0.1 依赖 WSL mirrored 网络模式。

建议方向(拆成两个小 PR)

这个 PR 识别出的两处切口本身是对的:host::Client 需要传输无关地向同一目标反复开流,workbench::host::admit 需要把预期的 root_id 与本机 client 数据目录解耦。

不需要引入 platform/peer,只要把核心边界收干净,WSL、后续的 Peer 插件和未来的 Maka Server 就能自然挂在这层之上:

  1. PR 1 — 最小化的 Client 开流抽象(platform/host-runtime):

    • 将 host::Client 和 CallChannelOpener 中重复的 IPC 拨号抽象为返回异步字节流的 OpenChannel(ChannelIo: AsyncRead + AsyncWrite + Unpin + Send + 'static,OpenChannel = Arc<dyn Fn() -> BoxFuture<'static, io::Result<Channel>> + Send + Sync>),在保留 Client::connect(path, epoch) 的同时提供 Client::connect_on(open, epoch)。
    • 保持现有 Host::channel / wire 帧协议不变(底层传输本身已支持原始流复用时,无需为每条子流再跑 HTTP/WebSocket Upgrade);现阶段也不提前加 TransportKind 或 Host 入站 trait——等第一个直投远端/插件传输落地时,再从 Host::serve 抽出带 residency 守卫的 Ingress。
  2. PR 2 — 轻量 WSL 接线(products/maka):

    • 通过 wsl.exe --exec 启动 helper,用轻量多路复用(如纯 yamux)从第 0 字节独占 stdout(诊断日志走 stderr),Linux 侧 helper 将每条普通子流直接透明转发到现有的 Linux Host Local IPC。
    • 这样做不需要任何 TCP 监听端口,不受 WSL2 NAT / mirrored 网络模式影响,省去同机 Desktop 的 remote pairing 及过期问题,同时天然复用正在运行的 Linux Host 及其 UID 校验、residency 计数和优雅排空路径。
    • PR 2 落地时建议守住几条不变量:
      • 保留半关闭(half-close):Client::close 会先关闭写端再等待读端返回 Response::Closed,mux ↔ IPC 桥接需正确传播半关闭,不能一侧 EOF 就直接丢弃整条流。
      • 冷启动 residency 交接:复用 Linux 现有 deployment::connect_local(已自带 launch lease / executor.lock)持有一个短命 startup Client,待 Windows 侧建好 anchor 并通过一次性 bootstrap 子流确认交接后再关闭该 startup Client。
      • desktop-shell 连接所有权:把长期 Target(distro / root / 预期 root_id)与单次 Connection(独占 WslBridge 子进程与 mux driver,不靠最后一个 Arc drop 回收)分层;窗口层(direct2d.rs)不感知 yamux/peer,明确区分用户退出(先跑完 quit_ephemeral 再拆 helper)与断线重连(fence + 清理后重连,不发 Quit)。

如果这个方向达成一致,建议先移除 platform/peer 和 third-party/deno-*,从 PR 1 开始推进,小 opener PR 提上来可以马上看。

@me2seeks

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I split the transport-neutral Host client work into #7028 so it can be reviewed independently, without WSL, the peer engine, or the Deno AES patches.

The motivation for keeping P2P on the WSL path is to exercise the same Host-over-peer-stream boundary that future iOS/Android clients can use, not to make those clients depend on WSL bootstrap. A future mobile QR flow would use its own device pairing and admission. This does not require bringing roster, signed address publication, relay authorization, or resumable streams into this PR. The question of how the peer engine is packaged and owned (including the plugin direction) is still open; I am not treating this branch as merge-ready.

In 03d48a8 the WSL peer listener derives its address from the running network mode: mirrored uses loopback, NAT derives the guest IPv4 from the route to its default gateway, and unsupported modes fail explicitly. The internal Host WebSocket remains loopback-only. The commit also fixes half-close and the startup/pairing paths. The Windows peer regression tests and Linux CLI typecheck passed; NAT has not been exercised on a real NAT-mode WSL instance.

@M4n5ter

M4n5ter commented Nov 19, 2026

Copy link
Copy Markdown
Member
English

Thanks for splitting out #7028 — that's definitely the right place to focus first.

On the motivation for keeping P2P on the WSL path: I think we're conflating two unrelated problems here.

Preparing for future mobile/remote clients has nothing to do with WSL. If the goal is to exercise the remote Host-over-stream boundary (pairing, remote admission, multi-channel calls, reconnects), the direct and faithful way is to run a regular remote Linux Host and connect to it over the network — not route it through WSL.

03d48a89f illustrates the mismatch pretty clearly: deriving a WSL NAT guest IPv4 from the default gateway route and adding pair_authenticated_client to shortcut pairing are both WSL-specific workarounds that mobile clients will never use, while WSL itself ends up carrying the weight and fragility of the peer stack and NAT-mode networking for a same-machine boundary.

Keeping the two tracks separate is much cleaner:

  • Remote / future mobile path: build and validate against an ordinary remote Linux Host (starting by making refactor(host): open application channels over supplied streams #7028's client opener transport-neutral), without WSL bootstrap or NAT heuristics.
  • Windows Desktop ↔ WSL: treat it as a local same-user subsystem boundary over wsl.exe --exec stdio mux → Local IPC, with no peer engine or TCP/NAT routing involved.

Also, in AI-agent-driven development there is really no reason to treat already-written code as a sunk cost or hesitate to discard an earlier prototype — patching around the wrong foundation costs far more long-term than starting fresh on the right boundary. I wouldn't invest more effort hardening the WSL-over-peer branch here; let's get the client transport abstraction right in #7028 first, then land WSL and remote/plugin transports cleanly on their own merits.

简体中文

感谢把 #7028 拆出来,先聚焦那边是对的。

关于在 WSL 路径上保留 P2P 的理由,我觉得这里把两件不相干的事混在一起了。

为未来的移动端/远程客户端铺路,和 WSL 本身没有关系。如果目标是提前验证远端 Host-over-stream 的边界(配对、远端 admission、多通道调用、断线重连),最直接也最贴近真实场景的做法就是起一台普通的远端 Linux Host,让客户端跨网络连接,而不是绕道 WSL。

03d48a89f 恰恰暴露了这个错位:通过默认网关路由推导 WSL NAT guest IPv4、以及新增 pair_authenticated_client 来跳过正常配对,全都是移动端根本不会用到的 WSL 特化胶水;而 WSL 作为一个本机跨子系统边界,反过来背上了整套 peer 栈和 NAT 网络模式的复杂度与脆弱性。

把两条线彻底分开会清晰得多:

  • 远程 / 未来移动端路径:直接对着普通远端 Linux Host 开发和验证(先把 refactor(host): open application channels over supplied streams #7028 的 Client 传输抽象定干净),不掺杂 WSL 引导和 NAT 推导。
  • Windows Desktop ↔ WSL:按本机同用户跨子系统边界处理,直接走 wsl.exe --exec stdio mux → Local IPC,不引入 peer 引擎,也不碰 TCP/NAT 路由。

另外,在 AI Agent 驱动的开发模式下,完全没必要把已经写出来的代码当成沉没成本、舍不得推倒重来——在不合适的底座上反复打补丁的长期代价,远比换到正确边界重新实现高得多。建议不要再继续往 #7011 这条 WSL-over-peer 路径上叠补丁了,我们先把 #7028 的传输抽象收干净,再各自独立推进 WSL 和远端/插件传输。

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

I checked the incremental change through 03d48a89f8c333dea3c577adec473c54c631c532, the added dependency and notice inputs, and the original hosted CI failures. This is a focused integration check, not complete validation of all 99 files or Windows/WSL behavior.

  • P2 — regenerate the distribution notices for the AES change. The new third-party/deno-crypto/Cargo.toml / third-party/deno-node-crypto/Cargo.toml pins and Cargo.lock introduce aes 0.8.4, whereas the Rust base uses 0.8.3. Neither the PR's products/maka/cli/notices.json nor the tested merge's manifest covers cargo:[email protected]. linux-checks job 135607408554 fails explicitly with Third-party notices do not cover current component or license data: cargo:[email protected]. Its checkout is 011353d1cc91086ebaf43f517e6bfde4671a977f, with parents Rust d0bfb20 and this exact PR head. Update and verify the generated dependency/notice artifacts for the actual new graph.
  • P2 — make the imported JavaScript pass the repository formatter. The added third-party/deno-crypto/00_crypto.js is rejected by tooling job 135607408048; Biome checks 525 files and reports one formatting error in this new file. This independently keeps the current CI red.

I also read the earlier architectural review. The current change still imports the peer and crypto stack; these CI findings neither resolve that design discussion nor establish correctness of pairing expiry, half-close, cold starts, reconnects, or cleanup. The retained-image native failure also occurs with the baseline NSH tree, so I am not attributing it to this transport change. I did not run Cargo or native WSL/Windows tests locally.


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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/XXL Over 2500 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants