Skip to content

Fix process tree termination races - #12

Merged
JamesLinYJ merged 1 commit into
mainfrom
agent/fix-process-tree-race
Aug 6, 2026
Merged

Fix process tree termination races#12
JamesLinYJ merged 1 commit into
mainfrom
agent/fix-process-tree-race

Conversation

@JamesLinYJ

@JamesLinYJ JamesLinYJ commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • classify descendant identity/open outcomes as verified, gone or reused, and fatal
  • skip only descendants that can be proven gone or PID-reused while keeping root and access-denied failures strict
  • hold synchronizable process handles and treat a failed TerminateProcess as benign only when the handle is already signaled
  • preserve leaf-first termination and the existing pre-open-before-terminate policy
  • add unit coverage plus a Windows stress test with continuously exiting child processes

Root cause

The process-tree path propagated every descendant ERROR_INVALID_PARAMETER as fatal even though that code also represents the expected races where a snapshotted process exits or a captured PID is reused. A second race existed after handles were opened: TerminateProcess failure was counted unconditionally even when the process had already exited naturally.

Impact

End Process Tree continues terminating the verified root and all still-verifiable descendants when short-lived descendants disappear. PID reuse remains protected by creation-time validation, and access-denied or unexpected errors are still reported before any termination starts.

Validation

  • rustfmt 1.9.0 on the changed Rust files, followed by --check
  • strict Clippy/type checking with -D warnings for x86_64-pc-windows-msvc
  • strict Clippy/type checking with -D warnings for i686-pc-windows-msvc
  • strict Clippy/type checking with -D warnings for aarch64-pc-windows-msvc
  • release-profile cargo check --all-targets --locked for x86_64-pc-windows-msvc
  • git diff --check
  • Windows CI run #3: all x86_64 tests, i686 tests, strict Clippy checks, and x86_64/i686/aarch64 release builds passed

Closes #11

@JamesLinYJ
JamesLinYJ marked this pull request as ready for review August 6, 2026 08:57
@JamesLinYJ
JamesLinYJ merged commit cfd35ca into main Aug 6, 2026
3 checks passed
@JamesLinYJ
JamesLinYJ deleted the agent/fix-process-tree-race branch August 6, 2026 08:59

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3d409b1bba

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

|child| is_valid_process_tree_edge(parent, *child, snapshot_time_100ns),
) {
DescendantProcessOutcome::Verified(child) => child,
DescendantProcessOutcome::GoneOrReused => continue,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Report vanished intermediate nodes instead of skipping their subtree

When a snapshotted intermediate process exits before this query but one of its children remains alive, this continue skips recursion into that intermediate node, so the surviving grandchild is never verified or opened; the root can then be terminated and kill_process_tree reports success even though part of the snapshotted tree remains. The new stress test only creates direct short-lived children and does not cover this case. Preserve enough verified state to traverse surviving descendants, or report that the tree could not be fully prepared rather than silently abandoning the branch.

AGENTS.md reference: AGENTS.md:L120-L125

Useful? React with 👍 / 👎.

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.

End Process Tree aborts when a snapshotted descendant exits during validation

1 participant