[Bug] ZCode 3.9.1 会话打开需 20-30 秒:setting.json.lock 出现无效 owner 的残留锁导致 RPC 串行超时(附定位过程与规避方案)
Open
Nobody has claimed this yet.
priority: P2
- Dominant language
- No language data
- Stars
- 22
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
更正说明:本 issue 初版将主因归为
v2/agent-config/claude残留 transcripts,经进一步核对逐日日志后推翻——该目录自 7 月初就存在而此前八周一切正常,且当天日志中零引用。已按时间线证据改写为残留锁为主因。详见正文。
环境
- ZCode 3.9.1(Electron 41.0.3),macOS(Apple Silicon)
- db.sqlite 约 490MB、406 个会话;
v2/数据从备份整体还原
现象
- 点击任意历史会话需 20-30 秒才能完成加载,启动也明显变慢
- 当天上午 ~10:00 前一切正常,问题当天早上开始出现并持续全天
关键证据(时间线)
~/.zcode/v2/logs/逐日检查:08-24、08-25 两天零 "file lock" 超时;08-26 10:02:08 出现第一批:
[2026-08-26 10:02:08.280] [warn] [rpc:call] setting.update FAIL
{"message":"Timed out after 8003ms waiting for the ZCode file lock: /Users/ctai/.zcode/v2/setting.json.lock"}
- 残留锁目录内的 owner 文件:
owner-683-1787708612450-*.json→ 创建于当天 09:43:40;pid 683 与当天任何 ZCode 相关进程不符(当天 ZCode 各进程 pid 均为 2 万+ 量级)——即该锁文件已无有效 owner,但一直未被回收 - 当天 15:16 点击会话时(慢的那次),多个 RPC 同时卡 23-25 秒后一起返回——排在同一把锁后面:
[rpc:call] zcode-session.readWorkspaceState OK (23351.7ms)
[rpc:call] zcode-session.readWorkspaceState OK (24487.9ms)
[rpc:call] model-provider.getAll OK (24524.1ms)
[rpc:call] model-provider.refreshCodingPlanApiKey OK (25155.3ms)
- 同日对照(网络/凭证条件相同):
- 15:03 完全重置
~/.zcode(全新 v2 = 全新锁)→ 启动与会话打开正常 - 15:04 还原旧 v2(含残留锁)→ 15:16 点击会话再次变慢
- 15:23 手工删除
setting.json.lock/→ 之后一切正常(~2-3s)
- 15:03 完全重置
- 会话打开路径事件(
session.resumed、zcode_protocol.v4.hydrate_three_source_merge)durationMs恒为 0(未埋点),26.7 秒的静默卡顿只能靠时间戳差分定位
规避方案(已验证有效)
- 退出 ZCode
- 删除残留锁目录
~/.zcode/v2/setting.json.lock/(内含指向无效 pid 的owner-*.json) - 重启后会话打开从 ~25s 降至 ~2-3s
建议(按影响排序)
- 残留锁自动检测/回收:owner pid 已不存在(或明显非本产品进程)时应自动接管而非让后续操作逐一 8s 超时——本例残留锁存活约 5.5 小时,期间所有 settings/workspace 类 RPC 反复超时,用户感知为「打开会话极慢」
- 持有锁进程的异常退出路径排查:owner 锁创建于 09:43,当天
v2/crash/无新增 dump——即不经 crashpad 记录的退出(被 kill / 强退等)也会留下死 owner 锁 - 补充埋点:会话打开路径(
session.resumed、hydrate_three_source_merge)durationMs恒为 0,本次只能靠时间戳差分定位 - (次要,未证实与本次相关)
v2/agent-config/claude/会长期积累 transcripts(本例 133MB、7 月一次性产生后无任何清理机制)——当天日志中零引用,仅作为相邻发现提出
相关观察(同场景、次要)
- 每次打开会话都会重启一轮 session-isolation MCP pool(健康连接也要 ~2.5s);
plugin:document-skills:image_search的 official auth 被拒("official MCP rejected the current credential")后每次打开都重试并失败,进一步加重感知延迟 - directory 型 marketplace 会整仓快照(本例 13GB,含 Rust
target/构建产物);下次启动时快照被自动清掉(这个行为是对的),但 refresh 会重新完整拷贝,建议尊重 .gitignore / 排除构建产物 - #370(GUI 切换卡顿 >3s)症状相近,供关联参考
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
Start with ~/.zcode/v2/setting.json.lock and the corresponding entries in ~/.zcode/v2/logs/, especially the setting.update timeout and owner-*.json metadata. Trace the setting and workspace RPC path, along with session.resumed and zcode_protocol.v4.hydrate_three_source_merge; done means an invalid owner no longer serializes requests into repeated 8-second timeouts and session opening returns to the normal range.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- electron, macos
- Domain
- desktop, observability, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100