Skip to content

fix(windows): tolerate a Codex process that has already exited - #1185

Merged
iruriQ merged 3 commits into
BytePioneer-AI:mainfrom
ChaceLyee2101:fix/windows-codex-exit-race
Nov 25, 2026
Merged

iruriQ merged 3 commits into
BytePioneer-AI:mainfrom
ChaceLyee2101:fix/windows-codex-exit-race

Conversation

@ChaceLyee2101

@ChaceLyee2101 ChaceLyee2101 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Windows can return error 5 from TerminateProcess after a process has exited while a handle to it is still open. The Launcher can surface this as a restart failure. Microsoft Win32 documentation

  • Accept that error only when a zero-time wait on the termination handle confirms exit. Other errors still propagate.
  • Skip confirmed exited entries when checking whether a process or the selected Codex Desktop installation is still running.
  • Add a Windows regression test that keeps a handle open after a child exits and then requests termination.
  • Match removed environment keys case-insensitively on Windows in the test added by fix(launcher): keep source checkout builds isolated from inherited installation paths #1174. The test still checks exact spelling on Unix. Failing Windows job

Related issues

Refs #1183. The report does not identify whether the process had exited or Windows denied a live termination request.

UI Demo

N/A (Windows process lifecycle).

Test plan

  • cargo check --locked -p codexhost-platform -p codexhost-launcher --tests --target x86_64-pc-windows-msvc passed.
  • cargo test --offline --locked -p codexhost-platform --lib on macOS passed 80 tests. The remaining system proxy test passed when rerun with access to the macOS configuration store.
  • cargo fmt --all --check and git diff --check passed.
  • The exited-process regression test passed on the Windows Actions runner. Windows job
  • The updated environment-removal test passed on macOS. cargo clippy --offline --locked -p codexhost-platform -p codexhost-launcher --all-targets --target x86_64-pc-windows-msvc -- -D warnings passed.

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between d755693 and 3395b06.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • 修复
    • 改进 Windows 上的进程状态识别,已退出的进程不再被误认为仍在运行。
    • 重复结束已退出的进程时,现在会正确识别其已结束,减少不必要的错误提示。

Windows 进程筛选和进程存在性检查会排除已退出的进程。进程终止逻辑增加同步权限,并在特定访问拒绝情况下检查进程是否已退出。环境变量移除测试改用 OsStr 比较名称。

Changes: Windows 进程状态处理

Layer / File(s) Summary
退出状态检查与进程终止
crates/platform/src/windows_process.rs
新增 process_has_exited,通过零超时等待检查进程状态。terminate_process 打开进程时增加同步权限,并在访问拒绝且进程已退出时视为成功。测试覆盖已退出子进程的再次终止。
进程筛选中的退出状态检查
crates/platform/src/process.rs
Windows 安装目录进程筛选会排除已退出的进程。process_exists 只有在进程未退出且枚举结果包含该 PID 时才返回 true。

环境变量移除测试

Layer / File(s) Summary
环境变量名称断言调整
crates/platform/src/desktop_launch.rs
移除变量的断言改用 OsStr 比较。Windows 额外接受大小写不敏感的名称匹配。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: bwndlct, bytepioneer-ai, mouzhi

Merge Risk: Minimal · previous review d7556

This change prevents Windows restart failures when a process has already exited but its handle remains open. No merge-blocking issues were identified. The new Windows regression test should be run on Windows as normal pre-merge verification.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed 标题“fix(windows): tolerate a Codex process that has already exited”与变更集主要内容一致:Windows 终止进程时,将已退出进程的 TerminateProcess 访问拒绝错误视为成功,并在存活检查中跳过已退出条目。标题简洁,指出了主要修复点。
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed PR 描述与变更集直接相关。描述说明了 Windows 上 TerminateProcess 返回错误 5 的处理方式:仅当零超时等待确认进程已退出时才接受该错误。描述还涵盖跳过已退出进程的检查、新增 Windows 回归测试,以及环境变量移除测试改为 Windows 上大小写不敏感匹配。这些内容与 raw_summary 中列出的 process.rs、windows_process.rs 和 …
Full details: Description check

Explanation

PR 描述与变更集直接相关。描述说明了 Windows 上 TerminateProcess 返回错误 5 的处理方式:仅当零超时等待确认进程已退出时才接受该错误。描述还涵盖跳过已退出进程的检查、新增 Windows 回归测试,以及环境变量移除测试改为 Windows 上大小写不敏感匹配。这些内容与 raw_summary 中列出的 process.rs、windows_process.rs 和 desktop_launch.rs 的改动一致。描述包含具体的测试计划和链接,信息量充足。

Finishing Touches

Generate unit tests (beta)

  • 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.

Share

@ChaceLyee2101
ChaceLyee2101 force-pushed the fix/windows-codex-exit-race branch from d755693 to 3395b06 Compare November 25, 2026 13:52
# Conflicts:
#	crates/platform/src/desktop_launch.rs
@iruriQ
iruriQ merged commit 6340549 into BytePioneer-AI:main Nov 25, 2026
@iruriQ

iruriQ commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the clean fix and real Win32 process regression test! We merged origin/main keeping main's crates/platform/src/desktop_launch.rs (which already landed the Windows env-removal test fix in 93541d522), verified formatting and codexhost-platform tests, and merged this into main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants