阶段 1、阶段 2 已在 fix/wsl-remote-process-cleanup 完成;阶段 3 已完成本次范围内的自动化验证与
真实 Windows + Ubuntu WSL PID 验证。运行证据见
docs/testing/wsl-host-pooling-runtime-evidence.md。
真实环境已验证同窗口同 distro/user 的 1、3、5 个 logical workspace 只保留一个 Windows remote
Host 和一个 WSL zcode-server;最后 owner 释放后按约 60 秒 idle TTL 回收,整个 App 正常关闭时
跳过 TTL,并在约 4 秒的采样窗口内完成 Host/server 回收。task draining、mobile attachment 和 Docker
dedicated 边界由自动化测试覆盖,尚未执行真实 task、真实手机和更新安装运行态注入。
初版实现把 sendPrompt() Promise 的 pending 区间当作 workspace running task。该边界不成立:
sendPrompt() 返回的是命令 ACK,模型输出和工具执行仍可继续。ACK 后把 workspace count 降到 0,
会让关闭 tab 立即执行 disposeWorkspace(),中断尚未结束的 Agent run。
候选边界如下:
send ACK → 仅说明命令已接收;禁止作为 idle/release 边界
turn terminal → stream 已收口;Agent active lock 仍可能未释放
session ready → prompt_completed / prompt_failed,Agent 已释放 active lock
本设计选择 session ready 作为 active run 的完成边界:
sendPrompt(taskId, traceId)
→ 先订阅 task ready event
→ workspace activeRun(taskId)=true
→ 上报 workspace count 与派生的 Host aggregate count
→ send ACK(不改变 count)
→ session ready
→ activeRun(taskId)=false
→ 更新 workspace/Host count
→ 若 workspace 正在 pending release,则执行 release
runningPromptCount。taskMetaById 与 workspace event subscription 属于 Desktop Host 代理层,远端
disposeWorkspace() 不会自动清理它们。ReleaseRemoteWorkspace 完成时必须:
workspaceKey 对应的全部 task meta。onDynamicWorkspaceEvent 返回的订阅 Disposable。sendPrompt ACK 已返回、session 尚未 ready 时关闭 workspace:不得调用
releaseWorkspacePreparation()。| Field | Value |
|---|---|
| Change | 将 Desktop WSL remote workspace 从“一 workspace 一套 Host/server”调整为“同一窗口、同一 distro、同一 Linux user 共享一套 Host/server”,并补齐 workspace runtime 回收、连接并发控制和退出屏障。 |
| Primary goal | 多个 WSL workspace 并行使用时,减少重复 UtilityProcess Host、wsl.exe 启动和 zcode-server 常驻内存,同时保持 workspace、桌面与手机远控边界。 |
| User-visible surfaces | WSL 连接、远程目录选择、remote workspace tab、关闭 workspace、真实关窗、App 退出、更新安装、Renderer reload、手机 /remote attachment。 |
| Pool scope | 当前产品虽然限制单窗口,pool identity 仍显式包含 windowWebContentsId;不跨 Electron 窗口共享。 |
| Idle policy | 最后一个有效 workspace 引用和 draining task 消失后进入 60 秒 idle TTL;真实关窗、App 退出和更新安装跳过 TTL,立即执行有界回收。 |
| Existing docs | docs/wsl-remote-workspace-design.md、docs/remote/wsl-remote-realtime-boundary.md、docs/superpowers/specs/2026-07-19-wsl-remote-process-cleanup-design.md、docs/superpowers/specs/2026-07-13-window-scoped-ssh-remote-host-pooling-design.md、docs/architecture/zcode-code-architecture-overview.md。 |
| Main code owners | packages/desktop/src/main/desktopRemoteSessions.ts、packages/desktop/src/host/index.ts、packages/desktop/src/host/remoteWorkspaceServiceCollection.ts、packages/server/src/remote/wsl-backend.ts、packages/server/src/remote/connect.ts、packages/services/src/zcode-agent/zcodeAgentProcessManager.ts。 |
当前 WSL、Docker 和 server remote 使用 dedicated Host;只有 SSH 使用窗口级 Host pool。同一 WSL distro
打开多个 workspace 时,每个逻辑 session 都会创建一个 UtilityProcess Host,并通过独立 wsl.exe stdio
连接启动一个独立 zcode-server。
当前:同一 distro 的三个 WSL workspace
Desktop Main
├─ Host A ─ wsl.exe ─ zcode-server A ─ Agent(workspaceKey A)
├─ Host B ─ wsl.exe ─ zcode-server B ─ Agent(workspaceKey B)
└─ Host C ─ wsl.exe ─ zcode-server C ─ Agent(workspaceKey C)
运行态测量中,三个完成握手但尚未启动实际 task 的 zcode-server RSS 约为 165 MB、156 MB 和
164 MB,总计约 485 MB。该数字不包含 Windows UtilityProcess Host、按 workspace 启动的 Agent 及
按需启动的 MCP 进程,因此只能作为当前重复 server 基线,不能写成固定产品预算。
以下事实限定本设计:
createLocalServices() 和 ZCodeAgentProcessManager 已能在一个 server 内按 workspaceKey
管理多个 workspace。WSLBackend.resolveInfoPromise 只在单 backend 内缓存;不同 dedicated backend 仍重复执行 availability、
distro 列表和 home 探测。releaseWorkspacePreparation() 表达“workspace 不再需要预热 runtime”,但当前 adapter 实现为空,
无法形成 workspace 级资源回收闭环。desktop-continuous,不得为了共享 Host 注册手机 replayable 使用的
relay_bridge。wsl --terminate / wsl --shutdown。本问题不是单纯的 wsl.exe 启动次数过多,而是 Host owner、logical session、workspace runtime 三种生命周期
当前被绑成一层:
当前耦合
remoteSessionId 关闭
= RPC port 关闭
= 整个 UtilityProcess Host 关闭
= WSL server connection 关闭
= 该 server 内全部 workspace runtime 关闭
dedicated 模型的优点是简单和故障隔离,但同一 distro/user 的多个 workspace 无法复用本来已支持多 workspace 的远端服务图。仅增加探测缓存或连接节流不能消除重复 server 的主要常驻成本;直接复制 SSH pool 又会让零引用 workspace Agent 长期留到窗口关闭,形成另一种资源滞留。
因此本设计必须同时解决:
wsl.exe stdio server connection 和一个 zcode-server。remoteSessionId、attachmentId、workspaceIdentity、workspaceKey 和
Renderer RPC port。zcode-server 改成监听 TCP/Unix socket 的常驻 daemon。wsl --terminate 或 wsl --shutdown,不停止整个 distro。@zcode/protocol,除非实施时证明现有 service RPC 无法表达 workspace runtime
release;若必须修改,需单独更新协议 spec 和 runtime schema。Stopped;验收对象是 ZCode-owned Host、server 和 Agent。| Round | Question | Decision | Boundary fixed |
|---|---|---|---|
| 1 | 是否拆成多份 spec? | 只写一份综合 spec,在文内描述分阶段实施。 | 一个目标设计、一份验收标准。 |
| 2 | 最后引用关闭后是否立即释放 Host? | 零引用后保留 60 秒 idle TTL,前提是生命周期可单点管理且不引入新竞态。 | TTL 由 Main pool entry 唯一持有。 |
| 3 | TTL 期间 App 退出如何处理? | App 退出、真实关窗和更新安装立即取消 TTL 并释放。 | owner teardown 优先于缓存。 |
| 4 | pool 是否跨窗口? | 不跨窗口;当前单窗口限制进一步降低实现风险。 | key 仍包含 windowWebContentsId。 |
| 5 | 最后 workspace 关闭但 task 仍运行如何处理? | 保持 runtime draining,task 完成后释放;App 级 teardown 不等待自然完成。 | UI detach 与 runtime owner 生命周期分离。 |
| 6 | 总体方案 | 采用窗口级 WSL shared pool。 | 不采用仅 quick wins 或 App daemon。 |
在 Desktop Main 中将 WSL Host 与 logical session 分离,复用现有 AttachServicePort 和远端多 workspace
service graph。
优点:
remoteSessionId 和 Renderer API 外部语义。代价:
它可作为方案 A 的前置阶段,但不能消除重复 zcode-server 和本地 Host service graph 的常驻成本,因此不能
作为本 feature 的完成状态。
跨窗口或跨 App 实例共享能进一步减少资源,但需要持久化 owner、远端鉴权、版本升级、跨窗口权限和 daemon 孤儿治理。当前产品只允许单窗口,没有必要承担这组复杂度。
Desktop Main(生命周期 owner)
└─ Window-scoped WSL Host Pool
key = windowWebContentsId + canonicalDistro + linuxUser
│
├─ Remote Host UtilityProcess
│ ├─ local remote-workspace service wrappers
│ ├─ attachment registry
│ └─ workspace lifecycle coordinator
│
└─ WSLBackend / wsl.exe stdio connection
└─ one zcode-server
├─ workspaceKey A → Agent runtime A
├─ workspaceKey B → Agent runtime B
└─ workspaceKey C → Agent runtime C
Main 只管理进程、logical session 和 attachment 生命周期:
poolKey 并 get-or-create Host。remoteSessionId 创建独立 attachment。将 WSL pool 从已经较大的 desktopRemoteSessions.ts 抽到
packages/desktop/src/main/remoteWslHostPool.ts;该文件只负责 pool state machine、single-flight、idle timer
和 Host dispose,不负责 IPC 参数解析或 UI 通知。
Remote Host 持有一个共享 activeServices,通过多个 AttachServicePort 暴露给 logical session。它负责:
WSLBackend。resolvedInfoPromise 继续保证 backend 内 single-flight。connectRemote() 只允许一个 in-flight Promise。createLocalServices() 服务多个 workspace。ZCodeAgentProcessManager 继续按 workspaceKey 隔离 Agent。poolKey = encode(
windowWebContentsId,
canonicalDistro,
linuxUser
)
规则:
windowWebContentsId 必须存在,即使当前产品只有一个窗口,也不得省略。$HOME 作为 user identity;home 目录可以被自定义。workspacePath、workspaceIdentity、remoteSessionId、server asset version 不进入 pool key。连接开始前 distro/user 可能使用默认值,因此 acquisition 与最终 identity 分两层:
connectKey = windowWebContentsId
+ normalizedRequestedDistroOrDefaultSentinel
+ normalizedRequestedUserOrDefaultSentinel
resolvedPoolKey = windowWebContentsId
+ canonicalDistro
+ resolvedLinuxUser
connectKey 只用于首次 resolve 前的 waiter single-flight,不能作为 ready Host 的长期 identity。connectKey 同时最多启动一个 Host,避免多个默认 distro/user 请求在 resolve 前重复建连。resolvedPoolKey,同时保留 connectKey → resolvedPoolKey 的进程内 alias,直到 Host
disposed 或 WSL discovery cache 失效。resolvedPoolKey,新 Host 不发布 attachment;waiter 转移到既有 Host,新 Host
进入 dispose。该冲突路径必须有单元测试。connectKey 时可能产生一个短命 loser Host,但不得产生两个 ready pool owner。remoteSessionId 继续表示一个 Renderer/Main logical remote workspace route:
workspace A → remoteSessionId A → attachment A ─┐
workspace B → remoteSessionId B → attachment B ─┼→ shared WSL Host
workspace C → remoteSessionId C → attachment C ─┘
关闭 remoteSessionId A 不等于关闭 shared Host。
所有隔离语义继续使用:
workspaceKey = workspaceIdentity?.trim() || workspacePath;
文件读写、Git、terminal 和 command cwd 继续使用 workspacePath。Main、Host、mobile attachment、provider
registry 和 Agent release 请求必须同时携带 workspaceIdentity 与 workspacePath,禁止仅按路径匹配。
type RemoteWslHostState =
| "connecting"
| "ready"
| "draining"
| "idle"
| "disposing"
| "disposed";
interface RemoteWslHostEntry {
process: ElectronUtilityProcess;
generation: number;
target: SanitizedWslTarget;
resolvedDistro?: string;
resolvedUser?: string;
state: RemoteWslHostState;
readinessPromise: Promise<void>;
idleTimer?: ReturnType<typeof setTimeout>;
disposePromise?: Promise<void>;
}
这是设计形态,不要求实施逐字复制类型;但以下不变量必须保留:
generation 单调递增;timer、ready continuation 和 exit callback 修改 map 前必须同时比较 entry 对象和
generation。disposing 后拒绝新 attach;调用方需要创建新 Host 时必须等待旧 entry 从 map 摘除。interface AttachedWslWorkspaceSession {
host: RemoteWslHostEntry;
attachmentId: string;
workspacePath: string;
workspaceIdentity?: string;
}
Main 不额外保存可派生的手工 refCount。桌面引用从 attached logical sessions 派生;手机引用从现有
shared-host attachment registry 派生。需要频繁判断时允许维护索引,但索引只能由 attach/detach 的同一原子入口
更新,并必须有一致性测试。
active
├─ refs > 0 → active
└─ refs = 0
├─ running task exists → draining
└─ no running task → releasing → released
draining
├─ new attachment arrives → active
├─ task reaches terminal state → releasing → released
└─ owner teardown → forced bounded shutdown
task 是否运行的权威仍在 Host/远端 Agent/session service。Main 可以持有“workspace 正在 draining”的生命周期 标记,但不得复制 task 内容、stream event 或 snapshot。
workspace runtime 的 acquire/release 使用独立、单调递增的 workspace generation。Main 在同 workspace
重新建立 logical session 时,必须先向 Host 发送 acquire generation 并等待 ACK,收到成功 ACK 后才能 attach
RPC MessagePort。Host 收到 acquire 后取消更旧、尚未开始的 release;若旧 release 已经进入
releaseWorkspacePreparation(),则等待其完成后再 ACK。release 完成前新 session 不得进入 resume/create/sendPrompt。
close generation=7
→ ReleaseRemoteWorkspace(generation=7)
→ releaseWorkspacePreparation in-flight
reopen generation=8
→ AcquireRemoteWorkspace(generation=8, requestId)
→ invalidate pending release generation<8
→ await in-flight release generation=7
→ RemoteWorkspaceAcquired(generation=8, requestId)
→ attach service port
→ resume/create/sendPrompt
实现采用“建 Host 前解析”的等价收敛:Main 为 provisional target 执行可缓存、失败不固化的 WSL identity
resolution,拿到 WSL 列表中的 canonical distro name 与 id -un 的实际 Linux user 后,才调用 Host pool
getOrCreate。因此 provisional key 只用于 resolver single-flight/cache,不会成为 ready Host 的长期 identity;
default target、显式等价 target、大小写不同但 WSL 列表命中同一名称的 target 最终都使用同一 resolved key。
并发 resolver 可以重复探测,但 resolved getOrCreate 必须原子保证只 spawn 一个 Host。App/window 在 resolution
期间关闭时,完成 continuation 必须重新检查 shutdown/window 状态,不得在 teardown snapshot 后创建 Host。
Main 等待 acquire ACK 必须有 10 秒 deadline;deadline 只终止本次 logical connect,不允许绕过 ACK attach,
也不能杀掉仍服务其他 workspace 的 shared Host。Host exit/App shutdown 必须 reject 全部 pending acquire waiter。
generation 在发送 AcquireRemoteWorkspace 前即已分配,因此 timeout/cancel 不能只丢弃 waiter:Main 必须立即对
同 generation best-effort 发送补偿 release。若成功 ACK 在 waiter 放弃后才到达,Main 必须确认该 workspace
没有 attached desktop/mobile owner,再对 ACK 携带的 generation 重发 release;失败 ACK 不需要补偿。这样即使
第一次 release 与 Host 内旧 generation 的 release-in-flight 重叠而未执行,晚 ACK 仍会在旧 release 完成后完成收口。
Acquire ACK 成功只表示 Host 已授予该 workspace generation 的 runtime owner,不表示 desktop logical attachment
已经建立。ACK 后若 AttachServicePort、renderer port 转移或 session tracking 任一步失败,Main 必须对同一
generation 执行补偿性 ReleaseRemoteWorkspace,再释放 pool owner;只释放 pool owner 不等价于释放 shared
Host 内的 workspace runtime。手机 shared-host attachment 必须在创建或转移 MessagePort 前验证已绑定的
workspaceGeneration,非法 session 不得给 Host 留下无调用方持有的 attachment。
AcquireRemoteWorkspace(generation=N) → ACK
→ validate generation
→ AttachServicePort
├─ success → logical session owns runtime N
└─ failure → ReleaseRemoteWorkspace(generation=N)
→ release pool owner
Workspace A connect
→ Main canonicalize provisional WSL target
→ reserve pool entry(connecting, generation=N)
→ create Host
→ create WSLBackend
→ resolve distro + Linux user
→ detect/deploy/start zcode-server
→ Host Connected
→ entry(ready)
→ AttachServicePort(A, workspace context)
→ publish RemoteServicePort(A)
同目标并发连接:
Connect A ─┐
Connect B ─┼→ same readinessPromise → one detect/deploy/server start
Connect C ─┘
ready
├→ independent attachment A
├→ independent attachment B
└→ independent attachment C
取消规则:
wslHostPool.retain() 创建的 pending owner 必须由单一幂等收口函数释放;取消触发 acquire
Promise rejection 后,异步 catch 不得再次减少引用。成功 attach 后 owner 才从 pending connect 转移给
tracked logical session,由 session dispose 负责后续唯一一次 release。setupRemoteConnection() continuation 在 shutdown 后恢复时必须检测 Host lifecycle token,不得重新发布
connection 或 attachment。关闭 workspace A
→ 从 logical session map 摘除 A
→ DetachServicePort(attachment A)
→ 派生 workspaceKey A 的 desktop/mobile refs
├─ refs > 0
│ → 保留 runtime
└─ refs = 0
├─ no running task
│ → disposeWorkspace(workspaceKey A)
└─ running task
→ mark draining(A)
→ terminal event
→ re-check refs
├─ refs > 0 → active
└─ refs = 0 → disposeWorkspace(A)
releaseWorkspacePreparation() 必须从空操作变成真实生命周期入口,并满足:
workspaceIdentity fallback workspacePath 解析 workspaceKey。disposeWorkspace() 或等价 Agent manager API 形成单一实现,不维护两套释放语义。ensureAgentReady() 互斥或按 generation 防止“释放完成后旧 warm-up continuation 又发布
Agent”。pool 只有在以下条件同时满足时才能进入 idle:
Host 已 ready,且没有 pending connect waiter。
last owner released
→ entry.state = idle
→ install timer(entry identity, generation=N, 60s)
new connect before deadline
→ compare current entry + generation
→ clear timer
→ state = ready
→ attach
timer fires
→ compare current entry + generation
→ re-check all four idle predicates
├─ predicate false → no dispose; transition to ready/draining as derived
└─ predicate true
→ state = disposing
→ remove/mark entry atomically
→ disposeHostProcessAndWait
TTL 常量命名并集中定义,单元测试使用可注入 clock/fake timer;不得在多个调用点散落 60_000。
owner teardown 优先级高于 idle cache 和 draining task:
real window close / app quit / update install
→ manager enters shuttingDown
→ reject new Host, connect and attachment
→ cancel all Host idle timers
→ reject pending connect waiters
→ snapshot all dedicated/shared/bot Hosts
→ dedupe by process identity
→ dispose all Hosts in parallel
→ await aggregate bounded barrier
→ continue window destruction / app quit / update handoff
before-quit、窗口 closed 和 update preparation 重复调用必须命中同一 single-flight result。closed 事件。wsl.exe 并发管理缓存分两层:
resolvedInfoPromise 永久复用。wsl --status 和 distro list 使用 5 秒 TTL 缓存;用户刷新 WSL
连接界面或连接失败时允许主动失效。Linux user、$HOME 和实际 distro 必须以具体 Host target 为范围,不能只按 Windows 用户做永久全局缓存。
缓存 rejected Promise 必须清除,后续连接可以重试。
同 poolKey 使用 single-flight 而不是 semaphore;不同 distro 的连接允许并发。若真实运行 trace 证明 WSL VM 在不同 distro 并发仍存在系统级锁竞争,再增加全局小并发 semaphore,不能先凭估算写死串行策略。
正常版本匹配继续跳过上传。首次安装/升级必须满足:
${remotePath}.new。manifestRequestTimeoutMs 约束,超时后允许后续连接重试。远端锁必须覆盖完整 deployServer transaction,而不是只包住某个 installFile() 或
installDirectory():主 server、Node runtime、Agent bundle、官方插件目录和最后的 version marker
必须属于同一个部署 owner,禁止两个版本交错安装。锁固定在 ${REMOTE_BASE}/.deploy.lock,owner 使用
不可预测 UUID;持锁 shell 每 30 秒刷新 owner 文件 mtime,等待者只接管超过 600 秒没有心跳的锁。释放时
必须再次比较 owner token,禁止旧 owner 删除后来者的锁;Host/backend 关闭造成 stdin EOF 时也走同一
owner-checked cleanup。
wsl.exe -- bash -lc <command> 会先经 WSL 默认 shell 重组参数,直接放在 command 参数里的局部
$lock_dir / $owner_token 可能在 lock-holder 真正执行前被展开为空。lock-holder 脚本必须以不含 $
的八进制 payload 写入 owner 唯一临时脚本,再由 bash 执行;脚本结束时同步删除该临时文件,且 stdin
继续保留给 release marker。SSH/Docker 复用同一 wrapper,不能为 WSL 分叉部署事务语义。
lock-holder release 是外部 stdio 边界,默认最多等待 5 秒 close。超时后必须 best-effort destroy 本次 lock stream 的 stdin/stdout/stderr 并返回包含 owner、deadline 和 stderr 摘要的错误;不得直接 dispose 共享 backend。 若部署主体与 release 同时失败,调用方必须保留两个错误上下文,不能用 release timeout 覆盖原始部署失败。
lock acquisition 同样是外部 stdio 边界,总等待默认最多 120 秒,并通过
DeployOptions.deployLockAcquireTimeoutMs 允许连接层覆盖。deadline 从 lock-holder stream 创建成功后开始;若始终
没有 acquired marker,即使其他 owner 持续 heartbeat,也必须销毁本次 waiter 自己的 stdin/stdout/stderr、移除
监听器,并抛出包含 owner、deadline 与 stderr 摘要的 acquisition timeout。不得删除其他 owner 的 lock,也不得
dispose 可能被共享的整个 backend。
deployServer
→ start remote lock-holder shell
→ mkdir ~/.zcode/server/.deploy.lock (atomic acquire)
→ write owner UUID + heartbeat
→ emit acquired marker
→ lock 内重新执行 checkServerDeployDecision
→ fetch one bounded fresh manifest snapshot
→ GLM SHA decision + release materialize share the snapshot
→ install all selected components + write version markers
→ send owner-scoped release / stdin EOF
→ compare owner UUID → remove only this lock
本地上传目录与开发态官方插件目录必须同时使用唯一 remote archive 和唯一 extract staging。归档上传、解压
或替换失败时,只清理本 owner 的 archive/staging;最终目录替换在 deploy-root lock 内执行。
RemoteDownloadAssetInstaller.installDirectory() 已有唯一 staging,但其最终 rm + mv 同样依赖上述
deploy-root lock,component cache lock 不能替代 install-root transaction lock。
WSL backend 的 shutdown barrier 必须先禁止新命令,再回收所有已登记 child。任何在 exec() 入口门禁后
跨越 discovery / identity await 的 continuation,都必须在最终同步 spawn() 前再次检查 disposed;检查、
spawn 与 child 登记位于同一 JavaScript turn,禁止在 disposeAndWait() 已完成后产生新 wsl.exe。直接
execFile() 的探测命令同样必须在同步创建 child 前检查 disposed。
Host/server unexpected close
→ compare pool entry identity
→ mark disposed and remove pool entry
→ cancel idle timer
→ enumerate attached logical sessions
→ emit RemoteSessionClosed for each session
→ existing UI marks affected workspaces disconnected
一个 shared Host 退出会影响同 pool 全部 workspace,这是共享方案明确接受的故障域。重连任一仍打开 workspace 时, Main 创建新 Host;同组其他仍打开 workspace 可复用该 Host 逐个恢复 attachment。每个 workspace 的路径/provider/ Agent 初始化失败保持独立,不因 workspace B 失败回滚已恢复的 workspace A。
所有跨 await 的连接、deploy、attach、timer 和 exit continuation 在写入共享状态前检查:
shuttingDown。检查失败时只释放自己创建且尚未转移 owner 的资源,不发布 stale port/connection。
info。debug 或单次 info,不得按 polling 高频落盘。warn。error。shared WSL Host
├─ desktop attachment
│ └─ clientMode=desktop-continuous
│ └─ direct continuous events; no relay_bridge
└─ mobile attachment
└─ clientMode=web-remote-replayable
└─ existing replayable gap/snapshot recovery
relay_bridge。/remote 继续 attach 桌面已存在的 WSL Host,禁止另起独立 WSL session/runtime。workspaceIdentity 和 remoteSessionId 必须贯穿 bridge、snapshot、queue、owner command 和缓存 key。本设计故意不为 Docker 补对称 shared pool:
Docker 仍使用 dedicated Host,但继续参与统一的真实关窗/App/update shutdown barrier 和幂等 dispose 接口。后续若要 共享 Docker,必须先单独确认 container identity、owner、重建和 volume/workspace 隔离。
本设计只产生一份最终 spec,但实施按依赖分三段;每段都必须保持可运行、可测试和可回滚。
releaseWorkspacePreparation() 建立真实、幂等、可等待的 workspace runtime release。阶段完成后仍可保留 dedicated Host,但关闭不再使用的 workspace preparation 能回收 Agent,首次连接风暴和 deploy 竞争得到控制。
AttachServicePort。wsl.exe PID、WSL server PID、
Agent PID、RSS 和连接耗时。releaseWorkspacePreparation 不再是空操作,并按 workspaceKey 释放正确 Agent。desktop-continuous,不注册 relay_bridge。web-remote-replayable,不新建独立 WSL Host。每次采样必须记录时间戳和父子关系,不能只凭 Task Manager 截图判断:
wsl.exe、server、Agent PID 与 RSS。仓库机械验证:
pnpm typecheck
pnpm lint
正式实现前后使用相同 server 版本、同一 distro 和同一组 workspace 比较:
| Metric | Expected direction |
|---|---|
| 同 pool UtilityProcess Host 数 | N → 1 |
同 pool zcode-server 数 |
N → 1 |
同 pool 长驻 wsl.exe server launcher 数 |
N → 1 |
| 第二至第五 workspace attach 时间 | 明显低于首次冷连接,不重复 deploy/server start |
| 空闲 server RSS | 从 N 份降为 1 份;不规定跨版本绝对阈值 |
| workspace Agent 数 | 按 active/draining workspace,而不是按 Host 或 conversation |
| 最后 owner 关闭后的 Host 存活时间 | 60 秒 ± scheduler tolerance;App teardown 为 shutdown deadline 而非 60 秒 |
日志需要能重建以下时序:pool create/reuse、Host generation、session attach/detach、workspace draining/release、 idle timer install/cancel/fire、owner shutdown override、Host exit。
| Risk | Mitigation |
|---|---|
| shared Host 崩溃扩大影响面 | 限制为窗口+distro+user;批量通知关联 session;重连按 workspace 独立恢复。 |
| 旧 timer 误杀复用后的 Host | entry identity + monotonic generation + fire 前重新派生 idle predicates。 |
| 手工 refcount 漂移 | 优先从 logical/mobile attachment 权威集合派生;若为性能建索引则只允许原子入口更新并做一致性测试。 |
| 关闭 tab 误杀后台 task | refs=0 且 running 时进入 draining;只有 terminal 后释放。 |
| draining 永久不结束 | 正常等待 task lifecycle;真实 owner teardown 使用既有有界 shutdown;异常断线随 Host exit 清理。 |
| shared server 内 workspace 串数据 | 所有隔离 key 使用 workspaceIdentity fallback workspacePath;端到端多 workspace 测试。 |
| deploy 首次安装竞争 | unique staging + remote lock + lock 内版本复查。 |
| discovery 缓存陈旧 | 5 秒短 TTL、主动刷新/失败失效,不缓存 resolved user/home 为全局永久值。 |
| App 退出被 TTL 延迟 | shutdown 首先取消 timer,立即并行 dispose;TTL 从不进入退出等待预算。 |
| mobile replayable 污染 desktop | attachment 保留 clientMode/deliveryKind;desktop WSL 明确禁止 relay_bridge。 |
| Docker 被错误对称化 | 本 spec 明确保持 dedicated,另行确认 container owner 后再设计。 |
zcode-server。desktop-continuous 且无 relay_bridge;手机保持 web-remote-replayable shared-host
attachment。pnpm typecheck 和 pnpm lint 全部通过。