Skip to content

test(mate-thread-wakes): drain GC cycles after asyncio.run() tests - #23608

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
unflaky/posixpath-unraisable-leak-2
Oct 24, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
unflaky/posixpath-unraisable-leak-2

Conversation

@CrysisDeu

@CrysisDeu CrysisDeu commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Stop TestDanglingDefaultAgentReset tests from being blamed for unraisable exceptions that belong to test_mate_thread_wakes.py.

test_config_loader_default_agent.py::TestDanglingDefaultAgentReset::test_a_partial_snapshot_installed_inside_the_locked_write_stops_it continues to fail with ExceptionGroup: multiple unraisable exception warnings after PR #23466 fixed one source. The signature is AttributeError: '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

  • Fixing any other unraisable-exception sources beyond this module.
  • Changing the behaviour of the two asyncio.run() tests themselves.

What changed (motivation → approach → change)

Two tests in test_mate_thread_wakes.py call asyncio.run() with a DashboardState whose ConversationLog stores the pytest tmp_path fixture (a PosixPath) as its _dir. When asyncio.run() closes the event loop, pending asyncio objects that reference the state form reference cycles with the PosixPath.

CPython's cyclic GC defers those cycles until the next collection pass. When that pass lands inside an unrelated test (the victim), tp_clear blanks the PosixPath's __slots__ (_drv, _str) to break the cycle; the object's finalizer or sys.unraisablehook then raises AttributeError while trying to repr/str the half-cleared path — and pytest attributes the error to the innocent victim.

Fix: add an autouse _drain_gc_cycles fixture that runs gc.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 to test_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 PosixPath unraisable leak.

Sibling sweep

Searched all test files for asyncio.run() without an autouse gc.collect() drain. Other files (test_slack_client_connect_retry.py, test_env_credential_secret_refs.py, test_git_coord_never_touches_user_checkout.py) use asyncio.run() but do not create tmp_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 holding pathlib.Path in __slots__ must drain GC cycles after each test via an autouse gc.collect() × 2 fixture. The cycle: asyncio state → ConversationLog._dir (a PosixPath) → back via asyncio task references. tp_clear blanks the path's slots mid-GC, causing AttributeError on the next str(path) call inside sys.unraisablehook.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

@CrysisDeu
CrysisDeu requested review from a team and KiroCrewCaptain as code owners October 24, 2026 01:06
@CrysisDeu
CrysisDeu requested a review from mbriones98 October 24, 2026 01:06
@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 9190f2d1e0745fc404a89a6d10ffb5bb5cd1c043 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ⏭️ skipped

Revision 9190f2d1e0745fc404a89a6d10ffb5bb5cd1c043 ships no reviewable capability (docs, tests or generated files only), so there is nothing to inventory. Does not block merge.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 24, 2026
@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 9190f2d1e0745fc404a89a6d10ffb5bb5cd1c043 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

This is a test-only GC drain that copies the pattern from #23466; no design-level concern blocks it.

Notes

  • Nothing shows this module is the source on shard 7's [gw1], so the description's claim that a green run proves the fix is weak. Another unflagged asyncio.run() file, like those named in the sibling sweep, would cause the same failure again. It is worth adding a conftest-level drain on the victim's side, or getting a traceback that shows the leaking object's origin.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 9190f2d1e0745fc404a89a6d10ffb5bb5cd1c043 — this comment is updated in place on each push.

Review details

No findings.

Notes:

  • The fixture docstring blames a PosixPath __del__ and slot clearing for the error, but pathlib.PurePath defines no __del__. It may be worth rewording it to describe what was actually observed.

[OPUS-REVIEWED] 9190f2d

Verdict parsed from the review's SHA-scoped output markers for commit 9190f2d1e0745fc404a89a6d10ffb5bb5cd1c043.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 9190f2d1e0745fc404a89a6d10ffb5bb5cd1c043 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 9190f2d1e0745fc404a89a6d10ffb5bb5cd1c043 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 9190f2d

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 9190f2d1e0745fc404a89a6d10ffb5bb5cd1c043 false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Oct 24, 2026
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.
@CrysisDeu
CrysisDeu force-pushed the unflaky/posixpath-unraisable-leak-2 branch from b22c6c8 to 9190f2d Compare October 24, 2026 03:27
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention readiness: passed Eligible automated validation passed for the current revision and removed readiness: passed Eligible automated validation passed for the current revision readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Oct 24, 2026
@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) October 24, 2026 06:04

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@KiroCrewCaptain
KiroCrewCaptain merged commit 331e161 into main Oct 24, 2026
155 of 158 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the unflaky/posixpath-unraisable-leak-2 branch October 24, 2026 06:05
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 24, 2026
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.

2 participants