Repository navigation
refactor(host): open application channels over supplied streams - #7028
Conversation
Generated-by: Maka
M4n5ter
left a comment
There was a problem hiding this comment.
English
Thanks for splitting this out — keeping each call on its own stream with CallChannelOpener pinning the authenticated target, epoch, and session is the right core shape. Before merging, there are a few contract and abstraction issues we should clean up:
-
Put the shared boundary at "open a channel ready for Host
wireframing", not before WebSocket upgrade:- Currently
Target::openunconditionally runs an HTTP/WebSocket upgrade andClient::connect_websocketunconditionally opens an extra stream forRequest::FinalizeAccess. Any transport that already carries raw multiplexed streams (such as the WSL stdio mux path) can't reuse this without forcing an HTTP upgrade on every substream. - Instead, let
Clientaccept a transport-neutralOpenChannel(Arc<dyn Fn() -> BoxFuture<'static, io::Result<Channel>> + Send + Sync>) with an optionalclient_instance: Option<Arc<str>>viaClient::connect_on(...), and keep WebSocket upgrade + Bearer auth as an adapter wrappingOpenChannel(withFinalizeAccesskept separate from routine connects so already-active credentials don't pay an extra upgrade + SQLite write transaction on every connect). - Also drop
+ SyncfromChannelIo(AsyncRead + AsyncWrite + Unpin + Send + 'staticis sufficient since each stream has a single owner, and+ Syncblocks!Syncmux stream wrappers), and returnio::Result<Channel>from the opener instead of collapsing errors intoStringearly. Keep local-owner control separate so supplying a stream doesn't imply local control authority.
- Currently
-
Allow
expected_epoch: Option<Uuid>on remote connect:connect_websocketrequiresepoch: Uuid, butmaka access prepare(Pairing) only producesrootId,credentialId, andcredential— there is noepochin the pairing payload, andClient::statusis still local-IPC-only. A real remote client holding pairing info cannot call this constructor (the test works around it by readinghost.epoch()in-process).Client::openalready supportsepoch: Option<Uuid>: acceptOption<Uuid>on initial connect, learn the epoch from the authenticatedConnectedresponse, and pin it on all subsequent UI and call channels (and ideally allowstatusover anOpenChanneltoo).
-
Don't silently downgrade
Client::quit()toclose()for remote targets:- In
request_quit,Target::WebSocketreturnsself.close().await(Ok(())), which breaksquit()'s contract ("stop its Host when no other session remains") and is inconsistent withpublication()/configure()returningErr("Host control requires the local owner"). Reject non-localquitexplicitly and let callers invokeclose()directly for remote sessions.
- In
-
Preserve safe diagnostic detail in
websocket::connect_on_stream:- Right now every non-HTTP failure (premature EOF, I/O error, protocol mismatch) collapses into
"Host WebSocket upgrade failed". Keep the HTTP branch status-only, but surface the I/OErrorKindor safe protocol error category so remote connection failures are debuggable.
- Right now every non-HTTP failure (premature EOF, I/O error, protocol mismatch) collapses into
-
Tighten the integration test in
remote_host.rsto assert behavior rather than internals:- Drop
assert_eq!(opened.load(Ordering::Relaxed), 5)— it locks in internal handshake/pairing call counts rather than external behavior. - Instead of opening two call channels and immediately dropping them, exercise an actual independent call (e.g. confirm one channel completes
HostLogs.readafter the other finishes/closes). - Note that
Host::openusesOptions::default()(LifecycleMode::Service), where even a localquit_ephemeralwouldn't retire the Host; if the test is meant to prove closing a remote session does not retire an ephemeral Host, configureLifecycleMode::Ephemeralexplicitly, and assert that remotequit/publication/configureare rejected.
- Drop
简体中文
感谢拆出这个独立 PR——每条 call 独立开流、由 CallChannelOpener 固定已认证的 target / epoch / session,这部分核心方向是对的。合入前有几处契约和抽象边界建议先理干净:
-
把共用边界放在“打开一条可直接跑 Host
wire帧的Channel”,而不是焊在 WebSocket 升级之前:- 目前
Target::open无条件执行 HTTP/WebSocket Upgrade,Client::connect_websocket每次建连也无条件多开一条流发Request::FinalizeAccess。像 WSL stdio mux 这种本身已经提供原始流复用的传输都没法直接复用,否则每条子流都要强跑一遍 HTTP Upgrade。 - 建议让
Client底层只认传输无关的OpenChannel(Arc<dyn Fn() -> BoxFuture<'static, io::Result<Channel>> + Send + Sync>)以及可选的client_instance: Option<Arc<str>>(如Client::connect_on(...)),把 WebSocket Upgrade + Bearer 鉴权做成包在OpenChannel外面的独立适配器(FinalizeAccess也从常规建连里拆出,避免已激活凭证每次重连都白跑一次握手和 SQLite 写事务)。 - 同时建议去掉
ChannelIo上不必要的+ Sync(单条流由单一 owner 独占,AsyncRead + AsyncWrite + Unpin + Send + 'static就够了,强加Sync会挡住不少!Sync的 mux 流包装),opener 返回io::Result<Channel>保留底层错误类型;本地 owner 控制入口继续独立,不让“能提供 stream”等同于拥有本地控制权。
- 目前
-
远端首次连接允许
expected_epoch: Option<Uuid>:connect_websocket强制要求传入epoch: Uuid,但现有maka access prepare(Pairing)只包含rootId、credentialId和credential,根本没有epoch,且Client::status仍写死 Local IPC。真实远端客户端拿着配对信息根本无法调用这个构造函数(当前测试是靠同进程直接读host.epoch()绕过的)。- 现有
Client::open已经支持epoch: Option<Uuid>:首次连接允许传None,从认证后的Connected响应接收 epoch,后续 UI 和 call channel 一律 pin 死该 epoch(同时也可以顺手支持通过OpenChannel查询status)。
-
不要在远端目标上把
Client::quit()静默降级为close():request_quit对Target::WebSocket直接返回self.close().await(Ok(())),违背了quit()“在无其他 session 时停止 Host”的契约,也与同文件publication()/configure()返回Err("Host control requires the local owner")不一致。建议对非本地目标明确拒掉quit,由调用方在远端退出时显式调用close()。
-
websocket::connect_on_stream保留安全的诊断信息:- 目前除
Error::Http外,提前 EOF、I/O 错误、协议响应异常都会被抹成同一句"Host WebSocket upgrade failed"。HTTP 分支继续只报状态码即可,I/O 错误建议保留ErrorKind,协议错误保留安全的错误类别,方便远端排障。
- 目前除
-
收紧
remote_host.rs的测试断言,测外部行为而非实现细节:- 去掉
assert_eq!(opened.load(Ordering::Relaxed), 5)——它锁死了内部握手/配对/anchor 调用次数,属于典型的实现耦合断言。 - 不要把两条并发打开的 call channel 直接
drop,实际跑一次独立调用(例如一条结束后另一条仍能完成HostLogs.read)。 - 另外
Host::open用的是默认Options::default()(LifecycleMode::Service),该模式下就算走本地quit_ephemeralHost 也不会退;如果测试目标是证明“关闭远端 session 不会误退 ephemeral Host”,fixture 需要显式配置LifecycleMode::Ephemeral,并补上远端调quit/publication/configure被拒绝的断言。
- 去掉
Generated-by: Maka
Generated-by: Maka
…st-channel-opener
Generated-by: Maka
|
Cross-machine smoke at |
|
CI comparison for eaf93d4: the initial Windows Desktop shard failed waiting for MAIN_DRAFT; the targeted rerun failed on the Close side pane control. The unmodified rust-preview base 874817f (run 44678458639, job 136099594884) exhibits both identical assertions in those same tests. This is baseline evidence for those failures, not a request to waive the required check. The other lanes passed. |
M4n5ter
left a comment
There was a problem hiding this comment.
LGTM — separating OpenChannel / connect_on from websocket::channel_opener and finalize_access, allowing Option<Uuid> on initial connect, rejecting non-local quit, and tightening the integration test around real concurrent HostLogs.read calls and LifecycleMode::Ephemeral makes this much cleaner. Thanks for the cross-machine smoke test as well.
Summary
Separate the Host client stream-opener work from #7011. Local IPC behavior stays unchanged. A remote embedding can supply a new async stream for each Host channel and reuse the existing authenticated WebSocket protocol. No WSL, peer engine, or crypto dependency changes are included.
Refs #7011
Verification
cargo test --locked -p maka-host-runtime --test integration host_opens_independent_supplied_channelspassed. It exercises invalid Bearer rejection, independent call channels, and closing the remote session without retiring the Host.cargo fmt -p maka-host-runtime -- --checkand staged ASF header and whitespace checks passed.AI use
Tool(s) and scope: Maka implemented and tested the client stream abstraction and split this PR.
Checklist
Does this PR entail a change in behavior?