Skip to content

ci: run the weekly PyPy tests in batches so the runner keeps enough memory - #849

Merged
JuroOravec merged 1 commit into
mainfrom
ci/pypy-runner
Nov 23, 2026
Merged

JuroOravec merged 1 commit into
mainfrom
ci/pypy-runner

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

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:

  • Each PyPy worker's memory only grows during the run, to 3 to 5 GB per worker. When the runner died, the four workers held about 15.2 GB of the runner's 16 GB.
  • Much of it is memory PyPy's garbage collector does not track: one worker held 4.1 GB of process memory while PyPy's own heap was 1.0 GB.
  • Pydantic model classes made at run time are never freed on PyPy: 2000 of 2000 were still alive after three 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).
  • Run alone, two tests of the Events work budget (the cap on the effort Citry spends checking request data) in test_events_pydantic_bounded.py add 2.2 GB and 1.2 GB that the worker never gives back.

Three other fixes did not help enough in probes:

  • Two workers instead of four: the runner still died after 45 minutes.
  • 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.
  • Forcing a garbage collection after every test file: the runner still died.

The change

.github/workflows/py--alt-interpreters.yml, step "Run Python tests":

  • A batches matrix value: 8 for PyPy, 1 for 3.14t.
  • With one batch, the step runs the original pytest command.
  • With more, pytest --collect-only first 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.
  • The step fails when the batch count is missing or not a positive whole number, so a bad value cannot silently run no tests.

Evidence

  • Run 45281208310 (the batched step before the review fixes): the PyPy job ran all eight batches in 17 minutes of test time, where the old step had reached only 88% after 26 minutes. 21076 passed, 1093 skipped, 1 expected failure (xfail) and 5 failed: 22175 tests in total, the same count as the old single run. 3.14t ran its single batch: 21342 passed, 2 failed.
  • Run 45281240697 (the same step on a probe branch, with memory logged every 30 seconds): the peak memory in use per batch was 3.6 to 6.2 GB of the runner's 16 GB.
  • Run 45285363655 on this branch's commit: the same result. The PyPy job ran all eight batches in 17 minutes of test time, with the same 21076 passed and the same five failures.

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_collector
  • test_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_refused
  • test_events_pydantic_bounded.py::test_a_signed_pydantic_v1_state_too_deep_to_restore_answers_stale_state

The 3.14t failures are handled separately.

Checks

  • Versioning and changelog: this is a CI-only change. It touches nothing the 1.x compatibility promise covers and needs no changelog entry.
  • Security: nothing reaches the browser. The new matrix.batches value reaches the script only through env:.
  • Reviewed by two independent agents. The first found that naming files from git ls-files skipped the conftest's collect_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.
  • Cost: the weekly job only; no effect on pull request CI or releases. Listing the tests adds about 30 seconds, and each batch pays pytest's startup time again.

🤖 Generated with Claude Code

…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]>
@JuroOravec
JuroOravec merged commit abe8792 into main Nov 23, 2026
23 of 25 checks passed
@JuroOravec
JuroOravec deleted the ci/pypy-runner branch November 23, 2026 23:39
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.

1 participant