Repository navigation
feat(remote): keep or end host programs when a connection closes (Refs 1lck/Lithe-IDEA#2231) - #160
Merged
Merged
Conversation
…1lck/Lithe-IDEA#2231) - remote.connect starts the persistent server session (--connect <key>, --state-dir <installRoot>) and returns sessionKey, sessionToken, resumed and keptPrograms; resume { key, token } attaches to a kept session, and a refused token connects once more with a new session. - server.keep: only programs the user chose to keep outlast the idle timeout; attaching clears an earlier keep, so a crashed client's programs end after ten minutes. - remote.disconnect takes programs: end|keep and returns { closed, kept }. - remote.runningPrograms and remote.endPrograms list and end what a host session still runs. - closePrograms preference (ask|end|keep, automatic asks) with closing in remote.preferences. - remote.session.state_failed log event; protocol and Core API docs.
…anup is expected (Refs 1lck/Lithe-IDEA#2231) remote.endPrograms takes an optional programs list ([{kind, id}] as remote.runningPrograms listed them), so a client that reconnected to a kept session ends what it listed without hanging up a terminal it started meanwhile. Resource cleanup that finds the connection already closed (after server.keep or a loss) no longer logs WARN, as the session's own cleanup already treats it.
… choice (Refs 1lck/Lithe-IDEA#2231) remote.preferences now reports closing.idleTimeoutSeconds, the server's default idle timeout, so the Remote Workspace settings page shows the value the host applies instead of a copy. The constant moves to protocol::methods so the client and the server share it.
This was referenced Nov 21, 2026
xiaoyumuxi
marked this pull request as ready for review
November 22, 2026 00:25
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
Refs 1lck/Lithe-IDEA#2231(§9.1、§9.2、§10 关闭确认与保留主机进程;安全项 S33、S35;决策 D5)
桌面端:1lck/Lithe-IDEA#2291(固定到本 PR 的 a81ad08)
类型
feat
改动说明
关闭远程工作区窗口时,主机上还在跑的进程和终端由用户决定结束还是保留。客户端每次都问,可以记住选择,也可以在设置里改回来。没人决定的进程不会一直留在主机上。
持久会话与重新连接
remote.connect改为启动持久服务器会话:--connect <sessionKey>,提供installRoot时加上--state-dir <installRoot>。守护进程的run/、log/和安装目录bin/在同一个根目录下,互不冲突。session新增四个字段:sessionKey、sessionToken、resumed、keptPrograms。resumed为真时,Core 立即列出会话里仍在运行的程序;列表失败时记remote.session.state_failed日志,并返回空列表。resume: { key, token },用于接回之前保留的会话。key 和 token 在 OpenSSH 或wsl.exe启动前校验:key 为空、超过 64 个字符或含字母、数字、.、_、-以外的字符,token 为空、超过 128 个字符或不是十六进制,都返回invalid_request,{ field: "resume", reason: "invalid" }。key 会进入远端命令行,所以必须先校验。INVALID_SESSION_TOKEN,会话已结束、key 被别的会话占用)时,Core 不带resume再连一次。代价是用户多认证一次,但不会被旧 token 锁在外面。server.keepserver.keep:客户端离开前告诉主机保留仍在运行的程序。只有被保留的会话能超过空闲超时(十分钟)继续存在,程序全部结束后会话照常结束。--stdio会话活不过客户端,收到server.keep时返回UNSUPPORTED。remote.disconnectprograms: "end" | "keep",默认end。结果从{ closed }改为{ closed, kept }。end先关闭转发,再发server.shutdown,然后结束传输。keep先关闭转发,再发server.keep,然后结束传输,不结束会话。两种请求都用EXIT_GRACE限时,关窗口不会卡住。通知主机失败时kept为false,程序按崩溃客户端的规则在超时后结束;除Disconnected外的失败记remote.session.cleanup_failed。{ closed: false, kept: false }。remote.runningPrograms/remote.endPrograms(新模块workspace/src/programs.rs)runningPrograms返回{ programs: [{ kind, id, argv, label, runningMs }] },进程在前、终端在后。客户端在关闭确认和重连后的列表(S35)里用它。endPrograms的请求是{ sessionId, programs? }。不带programs时结束全部;带上[{ kind, id }](runningPrograms列出的类型和编号)时只结束这些。接回被保留的会话后,客户端只结束上次列出的程序,不会挂断这次新开的终端。kind不是process或terminal时返回invalid_request。SIGTERM(process.kill,force: false),终端挂断(terminal.close)。每个请求限时 30 秒,返回{ ended }。请求期间已经结束的程序(UNKNOWN_RESOURCE)和会话里没有的编号不计数;不理会信号的程序仍会留在列表里。设置
remote/preferences.json新增closePrograms,取值ask、end、keep。自动值是ask,即每次都问。remote.preferences新增读取字段closing: { source, programs, idleTimeoutSeconds }。remote.editPreferences支持closePrograms: { programs: ...|null },null改回自动。idleTimeoutSeconds(600)是主机等多久才结束断线且没人保留程序的会话。它由服务器决定,没有文档能改;桌面端设置页只读显示它,不再自己抄一份常量。常量DEFAULT_IDLE_TIMEOUT_SECONDS从服务器移到protocol::methods,客户端和服务器共用。日志
remote.session.state_failed:warn 级,remote 通道,每 60 秒限一次,字段为stage、error。remote.session.cleanup_failed的stage说明加入keep。workspace/src/host.rs的Resource::drop)发现连接已经关闭(ClientError::Disconnected)时,不再记remote.resource.cleanup_failedWARN。这时主机已经结束会话、按用户的选择保留了它,或者会在空闲超时后结束它,这一侧已无事可做;会话自身的清理本来就这样处理。其他清理失败照旧记 WARN。契约文档
contracts/remote-workspace-protocol-v1.md:方法表加server.keep。空闲超时一段写明:没有客户端接入时开始计时,除非最后一个客户端发了 keep 且仍有程序在运行。“无客户端接入时”一段写明 keep 语义:接入清除保留,崩溃客户端的程序在超时后结束。contracts/rust-core-api.md:remote.disconnect、remote.editPreferences,新增两行。closePrograms和closing(含idleTimeoutSeconds)。remote.endPrograms写明可选的programs列表。resume?、新字段和持久会话说明(重新连接、拒绝后重连、校验规则)。{ sessionId, programs? }返回{ closed, kept },以及十分钟空闲超时。验证
cargo fmt --allcargo clippy -p lithe-remote -p lithe-workspace -p lithe-core --all-features --all-targets -- -D warnings:无警告cargo test -p lithe-remote --all-features:全部通过。persistence.rs14 个,覆盖:keep 后无客户端仍保留程序;未 keep 的会话超时结束;接入清除保留;程序结束后被保留的会话结束;stdio 会话拒绝 keep。cargo test -p lithe-workspace --all-features:61 个通过。新增a_malformed_resume_is_refused_before_the_client_runs,覆盖 7 组非法 key/token,确认都在 OpenSSH 启动前被拒。另有closePrograms编辑往返测试。cargo test -p lithe-core --lib:890 个通过。新增remote_programs_are_listed_ended_and_kept_only_by_a_persistent_session,通过分发器验证:programs: "later"被拒;kept: false;closed: false。node scripts/logging/generate-log-events.mjs --check:149 个事件,生成结果一致。plugin_sdk_build的端到端用例因缺少 Node 环境失败("native workflow checks require Node")。这些用例由shared/plugins/scripts/sdk-e2e.mjs运行,与本改动无关。