Repository navigation
test(mate-thread-wakes): drain GC cycles after asyncio.run() tests - #23608
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS This is a test-only GC drain that copies the pattern from #23466; no design-level concern blocks it. Notes
[DESIGN-REVIEWED] 9190f2d Description read[DESCRIPTION-READ] e88a9abc6d590b9fe16ac5263f6ac70dbc3ba1507f1aa42b7dbf19328efa20fe 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 |
Opus 5.5 Review — ✅ no blocking findingsReviewed Review detailsNo findings. Notes:
[OPUS-REVIEWED] 9190f2d Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 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: |
Two tests call asyncio.run() with a DashboardState whose ConversationLog stores tmp_path as a PosixPath. When the loop closes, pending asyncio objects that reference the state form reference cycles with the PosixPath. CPython's cyclic collector defers those cycles until a later GC pass that can land inside an unrelated test; tp_clear blanks the path's slots (_drv, _str) before __del__ fires, raising AttributeError inside sys.unraisablehook and blaming the innocent victim (test_config_loader_default_agent.py::TestDanglingDefaultAgentReset). Fix mirrors the pattern from test_remote_session_client.py (PR #23466): add an autouse gc.collect() × 2 fixture that runs AFTER each test in this module, paying the GC cost in the right place.
b22c6c8 to
9190f2d
Compare
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: test (1 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: test-only fixture that collects GC cycles after each test in the module so a later test is not blamed for them.
Problem / Motivation
Goal: Stop
TestDanglingDefaultAgentResettests from being blamed for unraisable exceptions that belong totest_mate_thread_wakes.py.test_config_loader_default_agent.py::TestDanglingDefaultAgentReset::test_a_partial_snapshot_installed_inside_the_locked_write_stops_itcontinues to fail withExceptionGroup: multiple unraisable exception warningsafter PR #23466 fixed one source. The signature isAttributeError: 'PosixPath' object has no attribute '_str'/'_drv'inside_pytest/unraisableexception.py.Failing run: 40039450735 attempt 1, job 120710747446 (Linux shard 7,
[gw1]).Why it matters
Every run of shard 7 risks an innocent test being marked FAILED by a GC cycle that belongs to a different test. This breaks CI determinism and wastes developer time triaging a victim that has no bug.
Not a goal
asyncio.run()tests themselves.What changed (motivation → approach → change)
Two tests in
test_mate_thread_wakes.pycallasyncio.run()with aDashboardStatewhoseConversationLogstores the pytesttmp_pathfixture (aPosixPath) as its_dir. Whenasyncio.run()closes the event loop, pending asyncio objects that reference the state form reference cycles with thePosixPath.CPython's cyclic GC defers those cycles until the next collection pass. When that pass lands inside an unrelated test (the victim),
tp_clearblanks thePosixPath's__slots__(_drv,_str) to break the cycle; the object's finalizer orsys.unraisablehookthen raisesAttributeErrorwhile trying to repr/str the half-cleared path — and pytest attributes the error to the innocent victim.Fix: add an autouse
_drain_gc_cyclesfixture that runsgc.collect()× 2 after each test in this module, paying the GC cost at the right place. This is the exact same pattern that PR #23466 applied totest_remote_session_client.py.Backwards compatibility
Compatible: test-only change, no production code touched.
Tests
No new tests added. The fix is a GC-drain fixture. The passing CI for this PR — specifically that the victim test (
TestDanglingDefaultAgentReset::test_a_partial_snapshot_installed_inside_the_locked_write_stops_it) no longer fails on any shard — is the proof.Manual verification
N/A — automated CI covers this.
Screenshots / video
N/A — no UI change.
Related Issues
Follows from PR #23466 which fixed one source of the same
PosixPathunraisable leak.Sibling sweep
Searched all test files for
asyncio.run()without an autousegc.collect()drain. Other files (test_slack_client_connect_retry.py,test_env_credential_secret_refs.py,test_git_coord_never_touches_user_checkout.py) useasyncio.run()but do not createtmp_path-backed state objects in the same way, so they are lower priority; this PR targets the confirmed new source.Pattern harvest
asyncio.run()tests that create objects holdingpathlib.Pathin__slots__must drain GC cycles after each test via an autousegc.collect()× 2 fixture. The cycle: asyncio state →ConversationLog._dir(aPosixPath) → back via asyncio task references.tp_clearblanks the path's slots mid-GC, causingAttributeErroron the nextstr(path)call insidesys.unraisablehook.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.