Skip to content

R1: lifetime tests collect only what they allocate (unit-tests timeout) - #1213

Merged
trissim merged 5 commits into
mainfrom
refactor/R1-gc-test-cost
Oct 12, 2026
Merged

trissim merged 5 commits into
mainfrom
refactor/R1-gc-test-cost

Conversation

@trissim

@trissim trissim commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

What was wrong

tests/unit/test_custom_function_events.py::test_qt_adapter_mixed_native_lifetime_orders[*] (four cases) each hit the 120 s pytest timeout in the unit-tests job (CI run 38155492658, about 527 s for the file), which contributed to the job being cancelled at 45 minutes. The file makes about 200 full gc.collect() calls, and late in the unit session each full collection walks the whole session heap (more than 3 s per call).

Change (tests only)

  • An autouse fixture in that file calls gc.freeze() before each test and gc.unfreeze() after. Objects allocated earlier in the session move to the permanent generation, so each collection covers exactly what the test allocates.
  • New canary test_collection_under_the_frozen_heap_still_reclaims_new_cycles: a fresh self-referencing object is alive before gc.collect() and reclaimed after it, under the fixture.
  • Receipt: docs/refactor/consolidation-20261009/R1-release-blockers.md (item 3).

Assertions before and after

The diff to the test file is 30 added lines and no removed or edited line: every existing assertion is unchanged. The lifetime tests assert that weak references to adapters, subscribers and signal objects are dead after gc.collect() for every destruction order, and that no callback fires after cancellation. Freezing cannot make these weaker: a frozen object is treated as a live external root, so a test object that is still referenced from the earlier heap stays alive and the assertion fails, exactly as before. Nothing had to be restored.

Verification (local, Linux, merged with origin/main ae6ddace5)

  • tests/unit/test_custom_function_events.py alone: 11 passed in 1.17s.
  • With its neighbour tests/unit/test_custom_function_lifecycle.py, -n 2: 66 passed in 55.50s.
  • guardrails_local.sh: guardrails rc=0 (three ratchets exit 0, 38 guardrail tests passed, nra-r1 "increased": []).
  • SMOKE_SKIP_GUI=1 smoke_local.sh: 5 passed, smoke rc=0.
  • Not run: the full unit suite, so the time of this file late in a full session was not re-measured here; macOS and Windows.

Note: the sibling PR for refactor/R1-selected-source-discovery adds the same receipt file; whichever merges second needs a trivial merge of that document.

R1 (item 3) · PR #1213 · guards 1/1 · production −0 +0 · tests −0 +30

🤖 Generated with Claude Code

trissim and others added 4 commits October 11, 2026 22:45
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 12, 2026 03:19

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@trissim
trissim merged commit 6c1312d into main Oct 12, 2026
2 checks passed
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