Repository navigation
Description
Follow-up to #585. The PR for #585 fixes the causes it could pin down (server-stored State, the Pydantic support check, and several test-only problems on PyPy and free-threaded 3.14). These remain. PyPy and free-threaded support are best effort.
1. PyPy: a 300-model Pydantic chain uses all the runner's memory
test_events_pydantic_bounded.py::test_a_chain_of_nested_models_deeper_than_the_nesting_limit_is_refused builds a chain of 300 nested Pydantic models and checks data against it. On PyPy, building Citry's bounded copy of that validator (_pydantic_bounded.py, build called from checker_for on a check thread) grows memory until the xdist worker crashes.
Evidence, from a probe run on a temporary branch (run 43714378175):
- Memory used on the 16 GB runner rose from 1.3 GB to 15.5 GB between 12:46 and 13:00, then the worker running this test crashed (reported as
gw1andgw4). - After the crash the run stopped making progress and was interrupted by the step's 45-minute timeout.
- Run alone, the module stopped in the same place: the faulthandler stack shows the check thread inside
builduntil the 10-minute timeout.
The test only reached this path once the Pydantic support check was fixed in the #585 PR (before that, every Pydantic class was refused on PyPy, so the test failed quickly). The PR skips this one test on PyPy, pointing here, so the weekly run can finish.
Best hypothesis: the copy's schema walk (or pydantic-core's own build of 300 nested schemas) keeps per-level data alive that CPython frees by reference counting and PyPy's garbage collector does not free in time, or the walk itself repeats work per level. The input is the app author's class, not request data. Size: unknown until reproduced on PyPy (needs a local PyPy build of citry_core, which has no macOS PyPy wheel); likely half a day to a day.
The first weekly run on the #585 branch (run 43703841315) ended with "The hosted runner lost communication with the server" after 55 minutes, with no log. That run still refused Pydantic classes, so it did not reach this test, and its cause is not pinned down. Memory starvation is the likely kind of failure, given the annotation.
2. PyPy: a class made at run time is not freed
test_events_schemas.py::TestPydanticPathText::test_a_class_made_at_run_time_can_be_freed fails on PyPy: after del made and one gc.collect(), the weak reference to the Pydantic class is still alive. It may need more collections on PyPy, or something holds the class there. Size: small once reproduced.
3. PyPy: the JetBrains fixture test
citry_lsp/tests/test_jetbrains_template.py::test_jetbrains_spike_fixture_loads_and_parses_both_document_shapes fails on PyPy with assert project.status.registry_ready is True. Not investigated. Size: unknown.
4. Free-threaded 3.14 without the GIL: request data kept alive
In the report-only step that runs with PYTHON_GIL=0, test_events_pydantic_bounded.py::test_a_check_that_raises_lets_go_of_the_request_data_without_the_cycle_collector fails: with the cycle collector off, the data passed to a check that raised is still alive after the caller drops it. It passes with the GIL on. A small standalone script that hands an exception back from a worker thread the same way keeps the data alive on free-threaded 3.14.6 even with PYTHON_GIL=1, so the cause is probably how the free-threaded build counts references across threads (objects freed later than on the standard build), not a Citry leak. That step only reports until #433. Size: small to decide (adjust the test for free-threaded builds, or prove a leak).
5. Free-threaded 3.14: threads copy the starter's context variables
On free-threaded 3.14 (and with -X thread_inherit_context=1), a new thread starts with a copy of the context variables of the thread that started it, and a ThreadPoolExecutor thread keeps the copy for later work. The #585 PR fixes the one test this broke and documents the effect on the request sub-path. A sweep of the citry tests with -X thread_inherit_context=1 on CPython 3.14 found nothing else. Still to check: whether any other Citry context variable (render state, Events validation state) can reach work that runs later on a pooled thread. Size: small review.
Activity
fix(events): accept Pydantic classes on PyPy (#585)
fix(events): accept Pydantic classes on PyPy (#585)
fix: run server-stored State, Pydantic Events and the test suite on P…
ci: run the weekly PyPy tests in batches so the runner keeps enough m…
ci: run the weekly PyPy tests in batches so the runner keeps enough m…
JuroOravec commentedon Nov 23, 2026
Weekly PyPy run with the batched test step from #849 (45285363655): 21,076 passed, 5 failed. Two failures are already listed above (
test_a_check_that_raises_lets_go_of_the_request_data_without_the_cycle_collectorandtest_a_class_made_at_run_time_can_be_freed). Three are new, all intest_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 built in a subprocess crashes inside PyPy.test_deep_data_checked_from_a_thread_with_a_small_stack_is_refusedtest_a_signed_pydantic_v1_state_too_deep_to_restore_answers_stale_stateSeparately, pydantic model classes made at run time are never freed on PyPy: 2000 of them were still alive after three
gc.collect()calls, while plain classes were freed. That is why each worker's memory kept growing until the runner ran out, which #849 works around by running the tests in batches.ci: run the weekly PyPy tests in batches so the runner keeps enough m…
test: skip the deep-State restore test on PyPy and check the answer a…
test: skip or fix the five tests that fail on PyPy (#851)