Repository navigation
fix(mapping-store): recover Windows stale locks after system PID reuse - #627
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
CIM 身份查询与锁处理 packages/mapping-store/src/mapping-store.ts, packages/mapping-store/test/windows-lock.test.ts, docs/architecture/harness-plugin-runtime.md |
Windows 进程身份查询改用 CIM,读取路径和创建时间,并将创建时间转换为 UTC ISO 字符串。测试覆盖 PID 复用、身份信息不足、查询失败和活动锁等情况。 |
原生 Windows 锁行为验证 packages/mapping-store/test/windows-lock-native.test.ts |
新增 Windows 原生测试,验证 PID 复用时回收旧锁且不终止子进程,并验证活动所有者锁和缺少创建时间的旧格式锁会被保留。 |
Priority:
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers: omsd512-w
Merge Risk: 
Minimal · up to a85d6
-
No actionable merge-blocking issue is established. Windows CI remains the planned check for the native tests.
Pre-merge checks: 
4
-
Full details: Linked Issues check
-
Explanation
[
#612] 要求:Windows 上识别残留锁的 PID 已被其他进程复用,安全回收旧锁;不结束无关进程;身份未知时不删锁;真实持锁者仍受单实例保护。已核对的实现(mapping-store.ts 的 processIdentity 差异):
- 锁冲突时改用 Get-CimInstance Win32_Process 读取 ExecutablePath 和 CreationDate。路径不可读时,仍可依据创建时间判断 PID 复用。
- CreationDate 在 PowerShell 内转换为 UTC round-trip ISO 字符串('o' 格式),避免默认 DateTime JSON 格式问题。
- 查询设置 timeout: 5_000。失败、空输出或无效输出时返回空身份,锁保留。
- 代码中未见 kill 或删除进程的调用。
测试覆盖(windows-lock.test.ts,模拟 Windows 响应):
- 路径不可读、创建时间相差超过 5 秒:回收旧锁。
- 同路径但创建时间不同:回收旧锁。
- 创建时间在 5 秒容差内,或路径等价写法相同:保留锁。
- 查询失败(EACCES、ETIMEDOUT、ENOENT)、空输出、畸形输出:保留锁并返回 STORE_LOCKED。
- 无锁冲突时不调用 PowerShell。
- 对 process.kill 仅使用信号 0 探测。
残余不确定性:
- 三项 Windows 原生测试(windows-lock-native.test.ts)未在本地执行,待 Windows CI 验证。
- 原报告的普通权限 svchost.exe 实机场景未经报告者在候选版本上验证。
- 上述不确定性属于验证范围,不构成代码层面的未满足需求。
Full details: Out of Scope Changes check
-
Explanation
已检查的变更均与 [
#612] 的 Mapping Store 锁身份检查直接相关:- packages/mapping-store/src/mapping-store.ts:processIdentity 从 Get-Process 改为 Get-CimInstance,增加 UTC ISO 转换和 5 秒超时。该变更直接实现
#612的需求。 - packages/mapping-store/test/windows-lock.test.ts:模拟 Windows 身份响应的单元测试,验证上述行为。
- packages/mapping-store/test/windows-lock-native.test.ts:仅 Windows 执行的原生测试,验证真实子进程的 PID 复用和活动持锁保护。
- 运行时架构文档(docs/architecture/harness-plugin-runtime.md):同步查询方式与安全边界说明,属于对实现的文档化。
未发现与
#612无关的功能变更。PR 描述中的 macOS/Linux 路径不变、无新增依赖,与代码差异一致。未审阅的 ignored_files 为空,无排除影响。 - packages/mapping-store/src/mapping-store.ts:processIdentity 从 Get-Process 改为 Get-CimInstance,增加 UTC ISO 转换和 5 秒超时。该变更直接实现
-
Finishing Touches
-
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
codexhost v0.15.0 ## What's New Import native Sessions from a selected Host, answer multi-select questions, and use Grok's native questions. This release also adds Antigravity usage statistics and improves conversation reliability across Claude Code, Pi, Windows, and Codex Desktop. 支持从所选 Host 导入原生 Session、回答多选问题,并接入 Grok 原生提问。本版还新增 Antigravity 用量统计,改进 Claude Code、Pi、Windows 和 Codex Desktop 的会话可靠性。 ### Features - Select a local or remote Host for Session import, keeping import and opening on the selected machine; support macOS Broker-backed imports for Claude Code, Cursor CLI, CodeBuddy, and WorkBuddy (BytePioneer-AI#207) - Answer external Harness multi-select questions in a shared card, with accompanying single-choice and text fields and drafts retained while switching chats (BytePioneer-AI#625) - Answer Grok's native single-choice, multi-select, and text questions, with cancellation and native withdrawal support (BytePioneer-AI#625) - Read Antigravity's native historical request and Token usage, including Sessions created outside codexhost; model and cost information remain unavailable when absent from native records (BytePioneer-AI#588) ### Fixes - Steer Claude Code continuations within the same Turn without stopping background Subagents, and keep accepted instructions attached to that Turn (BytePioneer-AI#617) - Release Claude Code Turns after refused Subagent messages, and allow Fork and message-edit recovery after entering a native worktree (BytePioneer-AI#626, BytePioneer-AI#629) - Improve Pi's large-history RPC performance and ignore late replies to expired read-only queries without faulting the Session (BytePioneer-AI#607) - Recover stale Windows Mapping Store locks when a PID has been reused by another process (BytePioneer-AI#627) - Keep Antigravity questions working across Turns, preserve the project working directory, and bound process cleanup waits (BytePioneer-AI#586) - Keep Antigravity Conversation totals separate from current context usage (BytePioneer-AI#587) - Disable background self-update by default for Host-started Antigravity processes on Windows and macOS, while retaining explicit updates (BytePioneer-AI#585) - Explain unavailable ZCode plans or quotas without asking an already signed-in account to log in again (BytePioneer-AI#621) - Compact Composer controls in narrow layouts and keep native question and approval inputs separate from chat controls (BytePioneer-AI#624, BytePioneer-AI#625) - Support Codex Desktop 26.1023 native language settings (BytePioneer-AI#636) - Fix availability checks routed through the Harness Broker ### 新功能 - 会话导入支持选择本地或远程 Host,导入和打开始终使用所选机器;macOS 上通过 Broker 托管的 Claude Code、Cursor CLI、CodeBuddy 和 WorkBuddy 支持导入 (BytePioneer-AI#207) - 外部 Harness 多选问题使用公共卡片,可与单选、文本字段一起回答,切换聊天时保留未提交草稿 (BytePioneer-AI#625) - 接入 Grok 原生单选、多选和文本提问,支持取消及原生问题撤回 (BytePioneer-AI#625) - 从 Antigravity 原生历史记录统计请求和 Token,包括未经 codexhost 创建的 Session;原生记录缺少模型信息时显示为未知模型且不计价 (BytePioneer-AI#588) ### 修复 - Claude Code 后台 Subagent 运行期间支持同一 Turn 内继续插入指令,不必停止后台任务;已接受的指令保持归属当前 Turn (BytePioneer-AI#617) - Claude Code 子 Agent 消息被拒绝后正确释放 Turn;进入原生 worktree 后仍可 Fork 和进行消息编辑恢复 (BytePioneer-AI#626, BytePioneer-AI#629) - 改善 Pi 大历史 RPC 处理性能;只读查询超时后的迟到回复不再导致 Session 故障 (BytePioneer-AI#607) - Windows 上 PID 被其他进程复用时,可以回收残留的 Mapping Store 锁 (BytePioneer-AI#627) - 修复 Antigravity 多轮提问失效,明确项目工作目录,并限制进程清理等待时间 (BytePioneer-AI#586) - 避免把 Antigravity 整段 Conversation 的累计用量误当作当前上下文占用 (BytePioneer-AI#587) - Windows 和 macOS 上由 Host 启动的 Antigravity 进程默认关闭后台自更新,保留显式更新操作 (BytePioneer-AI#585) - ZCode 已登录但套餐或额度不可用时显示正确原因,不再要求重复登录 (BytePioneer-AI#621) - 窄布局下压缩 Composer 控件,并避免聊天控件干扰原生提问与审批输入 (BytePioneer-AI#624, BytePioneer-AI#625) - 适配 Codex Desktop 26.1023 的原生语言设置 (BytePioneer-AI#636) - 修复通过 Harness Broker 路由的可用性检查 ### Breaking Changes - Language overrides require Codex Desktop's native settings service. Desktops exposing only the legacy locale RPC are no longer supported for language overrides; reading can fall back to the browser language, but changing the override requires the native service (BytePioneer-AI#636) ### 破坏性变更 - 语言覆盖设置需要 Codex Desktop 原生 settings 服务。仅提供旧 locale RPC 的 Desktop 不再支持语言覆盖;读取时可以降级使用浏览器语言,但修改覆盖值需要原生服务 (BytePioneer-AI#636) ## Installation ### npm ```bash npm install -g @codexhost/cli codexhost ``` For remote Session import and multi-select questions, update the Desktop installation and the relevant remote Hosts and Brokers together. ### Installer Download the installer matching your OS and CPU architecture from this release's assets. ### macOS Gatekeeper After installing on macOS, if codexhost shows "Apple cannot verify this app" when you open it for the first time, run the following command in Terminal and reopen codexhost: ```bash xattr -dr com.apple.quarantine /Applications/codexhost.app ``` ## Contributors Thanks to everyone who contributed to this release: - @BeiLuoqu (BytePioneer-AI#585, BytePioneer-AI#586, BytePioneer-AI#587, BytePioneer-AI#588) - @bwndlct (BytePioneer-AI#617) - @BytePioneer-AI (BytePioneer-AI#207, BytePioneer-AI#625, BytePioneer-AI#626, BytePioneer-AI#627, BytePioneer-AI#629, BytePioneer-AI#636) - @cy2s (BytePioneer-AI#624) - @karlorz (BytePioneer-AI#625) - @kunkun9527 (BytePioneer-AI#607) - @SuperGoodGame (BytePioneer-AI#207) - @ump45nose (BytePioneer-AI#621) # Conflicts: # Cargo.lock # Cargo.toml # package-lock.json # package.json # packages/renderer-extension/src/renderer-binding-probe.ts
问题与根因
Fixes #612
Windows 重启后,Mapping Store 残留锁记录的 Node PID 可能被
svchost.exe等系统进程复用。普通权限下Get-Process的Path/StartTime均可能不可读;现有实现因此无法识别进程身份变化,持续返回STORE_LOCKED,阻止 Host 启动。此外,直接将 PowerShell DateTime 交给 Windows PowerShell 的
ConvertTo-Json,不能保证得到Date.parse可读取的 ISO 时间。修改
Get-CimInstance Win32_Process读取ExecutablePath/CreationDate,利用创建时间识别路径不可读的系统进程 PID 复用。startedAt代替缺失的processStartedAt。基于
origin/main的独立 worktree/分支,不包含原工作目录的未提交改动。测试
MappingStore.initialize()/ 磁盘锁验证:路径不可读但创建时间不同、同路径 PID 复用、真实持锁身份、时间容差、旧锁、查询失败/超时/无效输出、EPERM 与已退出进程等。STORE_LOCKED;修改后通过。本地已执行(macOS arm64 / Node 24.18.0)
npx vitest run --config tests/vitest.config.js packages/mapping-store:92 passed,3 skipped(Windows 原生测试)。npm run typecheck:通过;测试文件 lint 调整后另跑npx tsc -p tests/tsconfig.json --noEmit --pretty false通过。node tools/check-boundaries.mjs、git diff --check:通过。尚未验证