Repository navigation
test(windows): drain the loop before calling the owner graph retained - #12348
Conversation
|
Intent: make the owner-release assertion in |
Opus 4.8 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing to check. The change removes the actual root of the flake (a finalization-timing dependency, not the retention assertion), the product code confirms no exception is stashed that the [DESIGN-REVIEWED] f59c53d |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
…r graph The owner-release assertion in test_failed_owner_cleanup_survives_gc_and_retries_from_maintenance samples a weakref one event-loop tick and one gc.collect() after dropping the last strong reference. What holds the referent at that point is a closure cell on the frames of the refusal the test just provoked, so the release waits on the cyclic collector seeing a traceback the tick happens to drop. That tick is the whole margin, and a loaded CI shard that needs another one reds on unrelated code. Clear the caught exception's __traceback__ inside the except block instead. The frames go with it, so one gc.collect() frees the referent with no tick at all, and a retention the product itself holds -- transient or permanent -- still reds. Fixes #12336
dc2a912 to
f59c53d
Compare
|
self-added: yes
|
buluoray
left a comment
There was a problem hiding this comment.
Approved on f59c53d8dcb4c837bc0f880fc6cd9d43e78817ab after source-level verification.
Verified, not taken on trust:
- The assertion is still falsifiable after the
__traceback__clear. Injected a product-side strong reference to theprocessobject intostate.terminally_scanned(reachable from the module-global_PENDING_WINDOWS_TREE_CLEANUPS) and re-ran the target test: it reddened with exactlypending cleanup retained the process owner graphattest/test_windows_tree_reap.py:185. Restoring the product code turns it green again. - Clearing the traceback masks nothing. The exception is already asserted at
test/test_windows_tree_reap.py:174before the clear at:177, the no-exception path is guarded bypytest.failat:179, and nothing re-raises. The frame heldprocessonly as the parameter ofterminate_windows_asyncio_tree— a harness artifact, not the product's retention path:_PendingWindowsTreeCleanup.__slots__stores handles/pins only (src/kiro_crew/platform_compat.py:3862-3888), and the product reference is one-directional (process._windows_cleanup_state = state,:3985). git grep _OWNER_RELEASE_PASSESis empty at both this head andorigin/main— no dangling reference.
Non-blocking: if one gc.collect() were ever insufficient in place of the old sleep(0) + collect(), the failure direction is a flaky RED (weakref still set), never a false GREEN — the safe side.
Problem / Motivation
A backend test shard reds on code the PR under review never touched. The message is always the same:
Seen on #11827 (Windows shard 1, attempt 1 and the automatic attempt 2) and on #11807 (Linux shard 1). Neither diff touches Windows process control, so it is not Windows-only and it is not the author's change.
Why it matters
The shard is a required check, and a fork contributor cannot re-run a single failed job. Every hit costs that author a force-push and a fresh CI round of roughly 40 minutes on a PR that is already green.
What changed (motivation → approach → change)
The test provokes a refusal, drops its last strong reference to a fake process, and asserts a weakref to it is dead. It samples that weakref one event-loop tick and one
gc.collect()after the drop.What holds the referent at that moment is a closure cell on the frames of the refusal itself. Those frames hang off the exception's traceback, so the release waits on the cyclic collector seeing a traceback that the tick happens to drop. That tick is the entire margin, measured: on an idle host the weakref clears on exactly that pass and no earlier. A shard that needs one more pass reds.
The except block clears the caught exception's
__traceback__. The frames go with it, so a singlegc.collect()frees the referent with no tick at all, and nothing about the outcome depends on when CPython finalizes anything. A retention the product itself holds, brief or permanent, still reds.__import__("gc")and__import__("weakref")become ordinary top-level imports, because the collection is now named in two places.Backwards compatibility
Compatible: test-only change. No product code, no public contract, and the assertion covers strictly more than before.
Tests
test/test_windows_tree_reap.pyis the only file touched. Its 13 tests pass, the target test runs in 0.01s, and 40 consecutive runs under random ordering pass.Three controls, built locally and discarded:
call_laterreleases the process 30ms later__traceback__clear removed, the single collect keptThe first two show the assertion still catches a retention the product holds, whichever kind. The third shows the clear is what frees the referent, so the pass is not luck.
Manual verification
N/A — unit coverage sufficient. The controls above reproduce the CI failure and then close it directly.
Related Issues
Fixes #12336
Pattern harvest
Rule candidate: review-prompt
Pattern: a test asserts a weakref referent is already collected after a fixed number of event-loop ticks, which makes CPython finalization timing a contract.
Checklist
feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)