Repository navigation
ci: run the weekly PyPy tests in batches so the runner keeps enough memory - #849
Merged
Merged
Conversation
…emory On PyPy each pytest-xdist worker process rarely gives memory back, so it keeps growing as it runs more test files. Four workers that lived for the whole suite filled the runner's 16 GB near the end of the run, the runner stopped answering, and GitHub cancelled the job without a test report (#739). The PyPy job now runs the test files in eight batches, each with its own pytest and new workers. The files come from `pytest --collect-only`, so the conftest files and the marker filter still decide what runs. The free-threaded job keeps one batch, which runs the same command as before. Refs #739, #708 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The weekly
test (pypy3.11)job was being cancelled before its tests finished, because the runner ran out of memory. This change runs the PyPy test files in eight batches. Each batch starts its own pytest process and its own parallel test workers (pytest-xdist), so the memory the workers held is freed between batches. The free-threaded CPython 3.14 job (3.14t) keeps one batch and runs the same command as before.Refs #739 (the weekly failure) and #708 (PyPy and free-threaded failures). Neither is closed: the PyPy job now finishes and reports, but five PyPy tests still fail (listed below).
What went wrong
Both failed weekly runs carry the annotation "The hosted runner lost communication with the server. Anything in your workflow that ... starves it for CPU/Memory ... can cause this error." The 2026-11-23 run stopped at 88% of the tests after 26 minutes; the 2026-11-16 run stopped at 99%. The 90-minute job limit was not involved.
Probe runs on a temporary branch logged each worker's memory each time it finished a test file:
gc.collect()calls, while plain classes were all freed. Every test that defines models therefore adds to its worker for the rest of the run (this is also PyPy and free-threaded test failures left after #585 #708 item 2).test_events_pydantic_bounded.pyadd 2.2 GB and 1.2 GB that the worker never gives back.Three other fixes did not help enough in probes:
MALLOC_ARENA_MAX=2(fewer glibc malloc pools): one heavy file dropped from 5.5 GB to 3.1 GB, but the whole suite under a 13 GB cap still hit the cap 38% of the way through.The change
.github/workflows/py--alt-interpreters.yml, step "Run Python tests":batchesmatrix value: 8 for PyPy, 1 for 3.14t.pytest --collect-onlyfirst lists the tests it would run. That keeps the file patterns the conftest files skip (collect_ignore_glob) and the marker filter (-m) in charge of which tests run. Batch 1 then runs files 1, 9, 17 and so on of that list, batch 2 runs files 2, 10, 18, and so on. Every batch runs even when an earlier one fails, and the step fails if any batch failed.Evidence
Left open
These five tests fail because of how PyPy behaves, not because of memory, so the PyPy job still fails:
test_events_schemas.py::TestPydanticPathText::test_a_class_made_at_run_time_can_be_freed(PyPy and free-threaded test failures left after #585 #708 item 2; explained above).test_events_pydantic_bounded.py::test_a_check_that_raises_lets_go_of_the_request_data_without_the_cycle_collectortest_events_pydantic_bounded.py::test_the_copy_of_a_chain_of_nested_models_is_built_on_a_thread_with_a_small_stack(the 300-model chain from PyPy and free-threaded test failures left after #585 #708 item 1, built in a subprocess; it fails with an internal PyPy error trace)test_events_pydantic_bounded.py::test_deep_data_checked_from_a_thread_with_a_small_stack_is_refusedtest_events_pydantic_bounded.py::test_a_signed_pydantic_v1_state_too_deep_to_restore_answers_stale_stateThe 3.14t failures are handled separately.
Checks
matrix.batchesvalue reaches the script only throughenv:.git ls-filesskipped the conftest'scollect_ignore_glob, so pytest would have tried to load the benchmark files and failed; the list now comes from pytest. The second found that an empty batch count passed with no tests; the step now refuses it.🤖 Generated with Claude Code