[Bug] 会话 working directory 随多次 resume 逐层加深,最终 Bash spawn ENOENT
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 22
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
会话 working directory 随多次 resume 逐层加深,最终导致 Bash spawn ENOENT
环境
- Windows 10 x64,ZCode 桌面客户端
- Shell:Git Bash(
C:\Program Files\Git\bin\bash.exe) - 工作区:
E:\Kevin_project\Claude(客户端 UI 中始终显示为同一个 "Claude" 工作区)
现象
同一会话的 working directory 逐渐变深(每次 +1 层尾段):
E:\Kevin_project\Claude
E:\Kevin_project\Claude\Claude
E:\Kevin_project\Claude\Claude\Claude
目录不存在后,Bash 工具所有命令报 spawn C:\Program Files\Git\bin\bash.exe ENOENT —— 错误指向 bash.exe 而非真实原因(cwd 无效),排障极具误导性。手工创建占位目录后立即恢复。
关键行为
持久 shell 存活期间一切正常(即使 session.directory 已是无效深层路径);context 压缩 / session resume 触发 shell 重启后,新 spawn 使用 session.directory(不存在的深层路径)→ ENOENT 爆发。
证据
~/.zcode/cli/db/db.sqlite的session表directory字段出现三种深度值(同一会话sess_57b22ee3...历经两层与三层);subagent 会话继承父会话的深层 directory,加深会蔓延:
sess_57b22ee3... | E:\Kevin_project\Claude\Claude\Claude
sess_6d990b6f... | E:\Kevin_project\Claude\Claude
sess_010df08d... | E:\Kevin_project\Claude
sess_subagent_agent_... | E:\Kevin_project\Claude\Claude\Claude ← 继承
- project 实体并存(UI 只显示一个工作区):
proj_e-kevin_project-claude => E:\Kevin_project\Claude (1 个会话)
proj_e-kevin_project-claude-claude => E:\Kevin_project\Claude\Claude (4 个会话,含受影响会话)
~/.zcode/cli/log/zcode-2026-09-15.jsonl:每次session.resumed事件携带当时的 directory 值,可见其在不同深度间变化(同一会话两次 resume 分别为两层)。
推断根因
会话恢复 / 会话派生路径时,directory 的重新计算把 workspace 尾段重复追加了一次(...\Claude + Claude);subagent 从父会话继承后进一步加深。
期望修复
- resume / shell 重启前校验 directory 存在性,无效时回退最近有效祖先目录(而非直接 spawn)
- 修正 directory 派生逻辑的重复追加
- spawn 失败时错误信息包含实际使用的 cwd,避免误导排障
临时规避
手工创建深层占位目录(如 mkdir "E:\Kevin_project\Claude\Claude\Claude")。
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 by tracing the session resume and derivation paths, using the session table in ~/.zcode/cli/db/db.sqlite and session.resumed entries in ~/.zcode/cli/log/zcode-2026-09-15.jsonl as evidence. Done means repeated workspace suffixes no longer accumulate, invalid directories fall back before shell restart, and spawn errors identify the actual cwd.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bash, git
- Domain
- cli, desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100