Repository navigation
fix(windows): skip orphans older than the root when a tree candidate vanishes unopened - #20407
Conversation
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The fix works at the mechanism level: it adds the missing age check to the dangling-parent refusal, and the CI failure in #20380 gives it provenance. One small duplication is worth trimming. Notes
What this change shipsInventory (4 items) — 3 justifiedIntent: a Windows tree cleanup no longer refuses because an unrelated process, older than the root, still names a vanished member's recycled PID as its parent. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] 2cdba4d Description read[DESCRIPTION-READ] 797be831ca1f5da943f4db2894d4d713c9aad284000698a49e0671f6bface5fa That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the dangling-parent refusal is relaxed only for an entry proven older than the root, one level deep, with children pinned by handles opened in this call. Every other dangling pair still raises. Notes
[DESIGN-REVIEWED] 2cdba4d Description read[DESCRIPTION-READ] 80077c520093d860cd4196a6d03d4f22b8a0cddba956acec7734da045c26c0d3 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
b2d3073 to
b67c324
Compare
|
|
|
b67c324 to
9c9a8dc
Compare
|
|
9c9a8dc to
e5b65ce
Compare
e5b65ce to
df2a933
Compare
…vanishes unopened The dangling-parent refusal read a fresh entry whose stale parent PID named a vanished candidate as that candidate's child, even when the entry was created before the root and so cannot descend from it. Skip such an entry when its own creation instant predates the root, together with its children from either snapshot, but only when each of those children was opened in this call, is still listed under it in the fresh snapshot, and has no child of its own. Anything else still refuses.
df2a933 to
2cdba4d
Compare
|
Holding for a human reviewer on head 2cdba4d. This changes I found no defect. The proof in Non-blocking: the First Principles note that the creation read at L375 repeats L305 is a style point with no behaviour impact. What clears it: a maintainer review of the termination-set change. — crew-pr-reviewer (r133) |
Problem / Motivation
Goal: A Windows tree drain no longer refuses because an unrelated process, older than the root, still names a vanished tree member's recycled PID as its parent.
test_a_member_exiting_inside_the_terminate_window_reads_as_exited(#20380) failed on a Windows backend shard withOSError: Windows descendant ancestry incomplete: vanished unopened parents; ... [(6892, 6680), (6920, 6680)]. The first Toolhelp snapshot listed 6680 under the root,OpenProcess(6680)failed, and 6680 was gone from the fresh snapshot. The fresh snapshot still had 6892 and 6920 naming 6680 as their parent, sodescendant_termination_handlesraised before the drain reached the terminate window the test is about.Why it matters
The red landed on #18285, which only touches ACP client files, and keeps
PR Readinessred until someone with write access reruns the job. Outside tests, the same refusal can fail a real Windows tree cleanup whenever a short-lived member, such as a console host, exits before its handle opens and its PID once belonged to a process whose children are still running.Not a goal
_windows_foreign_descendant_pidsor the check on unopened candidates that are still running. Both are byte-identical to base.test_runtime_cleanup_windows.py. Removing the sleeper's console host there would hide the production refusal instead of fixing it.What changed (motivation → approach → change)
Toolhelp never updates a parent PID after the parent exits, so an orphan keeps naming a PID that Windows can hand to a new process. The dangling-parent refusal in
descendant_termination_handles(platform_compat_winproc.py, the owner module this function moved to in #22044) read every fresh entry that names a vanished unopened candidate as that candidate's child, with no age check, so an orphan created before the root still counted as a surviving grandchild of the owned tree.The refusal now skips an entry that
_windows_is_older_orphanproves is a stranger. A process that has held its PID since before the root cannot descend from it, and neither can any process naming that PID: it is the stranger's child, or the child of an earlier holder that died before the root started. That argument holds one level down only, because a grandchild's parent may have been created after the root on a PID recycled from one of the root's own processes. So an entry is a stranger only when:Strangers and their children have their handles closed and leave the tree. This is deliberately narrower than the existing disproof for unopenable candidates, which drops a disproven node's whole numeric subtree; the spec paragraph says why the two must not be merged. Any other dangling pair raises as before. When no fresh entry names a vanished candidate, no query handle is opened. The
platform-compat.mdspec paragraph on the dangling-parent rule now states this exception.The
platform_compat.pyfacade forwards the new helper with the module's other names, andtest/test_platform_compat_refactor_facade.pylists it among them.Backwards compatibility
Compatible: the change only affects scans that raised
vanished unopened parentsbefore. In those, a provable stranger is skipped instead of raising.Removes nothing.
Tests
All in
TestWindowsRecycledDescendantAgeDisproof(test/test_platform_compat_windows_tree.py), on the class's fake Toolhelp and handle layer. Against the parent'splatform_compat_winproc.py, only the four cases this PR is meant to let through fail, each with the message CI showed; every case that must keep refusing also refuses on the parent:test_an_older_stranger_naming_a_vanished_candidate_is_not_its_child, six cases: 101 is listed under the root and then vanishes unopened; 102 and 103 still name it, refused or opened, created before the root, at the same instant, or after it. Created before the root, discovery returns no handles and closes the orphans' handles. Otherwise it still raises.test_an_older_orphan_is_skipped_with_its_pinned_childless_child: an older orphan and its own opened, childless console host are both skipped.test_an_older_orphan_closes_a_child_only_the_fresh_scan_lists_under_it: a PID the first snapshot lists under the root opens on a new child of the orphan, so its handle is closed with the orphan's.test_an_older_orphan_does_not_vouch_for_a_grandchild_across_a_vanished_pid(the GPT 6.1 review's input: an orphan's unopened child vanished, and an opened process below it names that PID),test_an_older_orphan_whose_child_has_a_child_keeps_the_refusal,test_an_older_orphan_whose_child_gained_a_child_keeps_the_refusal(the child started a process between the snapshots),test_an_older_orphan_whose_child_pid_was_reused_keeps_the_refusal(the fresh snapshot lists the child under another parent),test_an_older_orphan_with_a_child_only_the_fresh_scan_lists_keeps_the_refusal(the GPT 6.1 review's second input: the orphan starts a child between the snapshots),test_an_older_orphan_whose_child_is_not_opened_here_keeps_the_refusalwith the child refused or retained,test_a_reused_pid_under_a_vanished_candidate_keeps_the_refusal(a new process on an unopened PID reused between the snapshots), andtest_an_older_ancestor_does_not_disprove_a_child_of_a_vanished_candidate(an old ancestor proves nothing about a newer child).<changed to<=fails[same-instant-opened]; dropping the opened-in-this-call rule fails bothnot_opened_herecases; dropping the first-snapshot childless rule, or letting grandchildren through, failswhose_child_has_a_child; dropping the fresh-snapshot childless rule failswhose_child_gained_a_child; dropping the fresh-parent rule failswhose_child_pid_was_reused; reading children from the first snapshot only failswith_a_child_only_the_fresh_scan_lists; closing only children the first snapshot lists under the orphan failscloses_a_child_only_the_fresh_scan_lists_under_it.test/test_platform_compat_windows_tree.py: 20/20 at-n0; 10/10 at-n 4 --dist loadgroup --max-worker-restart=2besidetest/test_runtime_cleanup_windows.pyandtest/test_platform_compat_kill_reap.py; and one shuffled run of all 73 ids (seed 9302), green.Manual verification
N/A — the Toolhelp race cannot be produced from Linux. The faked snapshot sequence above reproduces the exact refusal, and the Windows backend shards run the original test on every PR.
Screenshots / video
N/A — no user-visible change.
Related Issues
Closes #20380
Pattern harvest
Not generalizable: the defect is one missing creation-order check in a single Windows discovery routine, not a pattern that recurs across call sites.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement