远程工作区生命周期: 孤儿agent被watchdog回收后不重生 / host进程复用已dispose的协议客户端
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 22
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
问题描述
远程工作区(Remote SSH,desktop-attached-remote 模式)存在两个相关的生命周期 bug,导致会话假死后无法自愈,必须手动杀进程才能恢复。3.7.6 客户端与远程端同版本,远程端为 Ubuntu 24.04。
Bug 1:客户端重启后远程 agent 变孤儿,watchdog 回收后不重生
复现步骤:
- 连接远程工作区,agent 正常运行
- 直接退出/重启 ZCode 客户端(不断开远程工作区)
- 重新打开客户端并重连该远程工作区
实际行为:
- 远程旧 agent 进程成为孤儿,协议状态已死
- 重连后所有调用超时:本地日志中
subscribeConversationV4 FAIL (5795ms)/FAIL (19702ms),远程单日累计 2603 条zcode_protocol.v4.gateway_error(Client request timed out: session/requestRuntimePreferences) - 随后 watchdog 回收 agent,但没有拉起新 agent:
[remote] ZCode agent process exited {
code: null,
signal: 'SIGTERM',
terminationKind: 'watchdog_recycle',
terminationReason: 'request-timeout'
}
- UI 表现为远程工作区“崩了”,重连无效,直到手动杀掉远程 zcode 进程 + 本地 host 进程后重连才恢复
期望行为:watchdog 回收孤儿 agent 后应自动拉起新 agent;或客户端退出时主动清理远程 agent。
Bug 2:本地 host 进程持有已 dispose 的协议客户端,UI“重新连接”不重建 host
同一远程工作区在一次断连后,本地 zcode-host-remote-workspace-ssh-* 进程(存活 10+ 小时)持续对所有 RPC 报错:
[zcode-host] [rpc:call] zcode-session.readWorkspaceState FAIL {"message":"ZCode Protocol client is disposed"}
[zcode-host] [rpc:call] zcode-agent.subscribeConversationV4 FAIL {"message":"ZCode Protocol client is disposed"}
at ZCodeProtocolClient.assertNotDisposed (.../zcode-server.cjs)
UI 上反复点“重新连接”不会重建该 host 进程,错误持续整晚,直到手动 kill 该 host 进程、由客户端重新拉起后才恢复。
修复建议
- watchdog
recycle后自动 respawn agent(或至少让客户端重连路径能触发重生) - 客户端 app 退出流程中主动断开并清理远程 workspace 的 agent
- UI“重新连接”应重建 host 进程或至少重建其协议客户端,而不是复用已 dispose 的引用
环境
- 客户端:ZCode 3.7.6(Arch Linux)
- 远程端:zcode-server 3.7.6(Ubuntu 24.04,经 SSH 直连)
- 模式:desktop-attached-remote
- 远程端需要经代理访问 API(与 #68 同场景,已用 proxychains 解决网络层,本 issue 与网络无关:复现时代理链路、内存、进程均正常)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source files or tests are named. Start by reproducing the reported watchdog_recycle and disposed-client failures, then trace the watchdog recycle, reconnect path, and host/protocol-client lifecycle. Done means a recycled orphan agent respawns or is cleaned up, and reconnecting no longer reuses a disposed host client.
Written by the indexing model from the issue text.
Assessment
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100