Skip to content

🐛 fix(ci): parallelize graalpy tests, recover crashed workers - #3240

Merged
gaborbernat merged 7 commits into
mainfrom
ci-stability
Sep 17, 2026
Merged

gaborbernat merged 7 commits into
mainfrom
ci-stability

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Two jobs on #3238 failed for reasons unrelated to that PR's diff, which only touched a workflow file and a README badge. graalpy-24.1 - ubuntu-24.04 hit the hard 30-minute step timeout, and 3.13t - windows-2025-vs2026 failed with worker 'gw0' crashed while running 'tests/unit/create/test_creator.py::test_get_site_packages'. Neither is a test regression, so re-running the job would have hidden both without fixing anything.

[env.graalpy] in tox.toml overrides commands and, unlike every other environment inherited from [env_run_base], drops the -n auto --dist loadfile xdist flags, so it was the only environment in the matrix running the suite one test at a time; tox config -e graalpy confirmed the resolved command had no -n flag before this change. The Windows failure is a real pytest-xdist worker crash: test_get_site_packages builds a virtualenv, then spawns a subprocess of its free-threaded interpreter from inside an xdist worker, and pytest-xdist marks a test failed when its worker dies mid-run instead of retrying it. pytest-rerunfailures's own README documents that it can recover a hard worker crash when paired with -n, so PYTEST_ADDOPTS now carries --reruns 2 --reruns-delay 2 for CI 🔁, leaving local tox run failing on the first try as before.

pytest-rerunfailures is incompatible with the flaky plugin. flaky was a dependency with zero @flaky usage anywhere in the codebase, so it and its now-meaningless --no-success-flaky-report addopt go, rather than risk a plugin conflict. The graalpy-24.1 job gets more headroom too (50/40 minutes vs 40/30). Its per-process startup runs slower 🐢 than CPython's.

@gaborbernat gaborbernat changed the title Fix two CI flake root causes 🐛 fix(ci): parallelize graalpy tests, recover crashed workers Sep 16, 2026
@gaborbernat
gaborbernat enabled auto-merge (squash) September 16, 2026 22:33
A pytest-timeout SIGALRM fired mid-traceback-formatting on graalpy
under -n auto, corrupting xdist state into an unrecoverable
INTERNALERROR. Switch its timeout method to thread, which hard-kills
the worker instead and lets xdist's crash recovery take over.

Also pass PYTHONFAULTHANDLER through tox so a future silent worker
crash (as seen on 3.13t/Windows) gets a native stack trace instead of
nothing; tox's pass_env allowlist was silently stripping it.
The Ubuntu leg of #3240's own validation run needed 11 reruns and
still had 2 hard failures, all tests/unit/activation/test_fish.py
cases on the same worker slot, timing out at the existing 120s limit.
The rerun that did land under load ran in 44s standalone, so the
tests aren't broken; GraalPy's JIT warmup across `-n auto` workers on
a shared runner was starving them of CPU.

Dropping to `-n 2` cuts that contention directly instead of just
giving failing tests more rope. Bumped the per-test timeout to 300s
for graalpy on top of that as a margin, since even under less
contention subprocess-heavy shell-activation tests can run slower on
GraalPy than the 120s default assumes.
-n 2 cut the timeout-driven reruns to zero and made the run faster,
but a fully clean run (394 passed, 0 reruns) still crashed 26s after
finishing: "IllegalStateException: The language did not complete all
polyglot threads but should have: [Thread[...,Polyglot-python-1,...]]".

execnet, pytest-xdist's transport, keeps a background reader thread
alive on the controller for each worker gateway (see execnet#96).
GraalVM's Context.close() apparently requires every Python-visible
thread to have exited first, daemon or not, and won't wait past its
own internal ~26-28s grace period. -n 2 lowered the odds of losing
that race; it never removed the thread that could lose it.

Dropping -n/--dist for graalpy removes execnet from the picture
entirely, which removes the thread. Bumped its job/step timeouts to
cover running the suite serially instead of on 2 workers.
Removing xdist (previous commit) didn't fix the interpreter-shutdown
crash: a fully serial run with zero reruns still hit the identical
"did not complete all polyglot threads" error, same thread number
(#54), same ~26s gap after the suite finished.

pytest-timeout's --timeout-method=thread, added earlier specifically
to survive SIGALRM corrupting xdist workers, spawns a watcher thread
per test. GraalVM's Context.close() won't tolerate any Python-visible
thread still alive, daemon or not, regardless of what created it.
Now that xdist is gone, the reason for the thread method is gone too:
plain pytest-timeout defaults to signal-based (SIGALRM) enforcement,
which needs no thread at all, and GraalPy isn't run on Windows so the
Unix-only signal method is safe. This matches the graalpy env's
config from before any of today's changes, which never hit this.
Two prior commits removed xdist and its thread-based timeout method
from the graalpy env, each time expecting to eliminate the extra
thread they believed GraalVM's Context.close() was choking on. Both
were wrong: a run with the graalpy env restored to its exact
pre-#3240 config (no xdist, no --timeout-method override, the same
config that has run clean on other PRs) crashed with the identical
"did not complete all polyglot threads" error, same thread number,
same ~26s shutdown delay.

That rules out anything in our control as the trigger. This is a
nondeterministic crash in GraalVM's own interpreter teardown that
predates all of today's changes, not something caused or fixable by
tuning xdist workers or pytest-timeout's method.

tasks/run_graalpy_tests.py wraps the pytest invocation: if it exits
non-zero but the JUnit report it just wrote shows zero failed or
errored tests, the wrapper treats the run as a pass instead of
failing the build. Any real test failure still fails normally, since
the JUnit report would show it.
@gaborbernat
gaborbernat merged commit 13ed8cc into main Sep 17, 2026
62 checks passed
@gaborbernat
gaborbernat deleted the ci-stability branch September 17, 2026 03:53
gaborbernat added a commit to gaborbernat/virtualenv that referenced this pull request Sep 27, 2026
GraalPy cannot use pytest-xdist because its worker threads trip GraalVM's
Context.close() check (pypa#3240). The suite ran in one process and hit the
65 minute step timeout on ubuntu-24.04.

The runner now starts one serial pytest process per CPU. A --shard=K/N
option in the test conftest gives each process every Nth test ID in
sorted order, so the slices agree even though pytest-randomly shuffles
each process in its own order. Each shard keeps the polyglot shutdown
tolerance, and the run fails if any shard fails or no test ran.

The graalpy env also stops tracing coverage: no step combines or reports
it, and tracing every GraalPy process cost about five times the CPU time.
gaborbernat added a commit to gaborbernat/virtualenv that referenced this pull request Sep 27, 2026
GraalPy cannot use pytest-xdist because its worker threads trip GraalVM's
Context.close() check (pypa#3240). The suite ran in one process and hit the
65 minute step timeout on ubuntu-24.04.

The runner now starts one serial pytest process per CPU. A --shard=K/N
option in the test conftest gives each process every Nth test ID in
sorted order, so the slices agree even though pytest-randomly shuffles
each process in its own order. Each shard keeps the polyglot shutdown
tolerance, and the run fails if any shard fails or no test ran.
gaborbernat added a commit to gaborbernat/virtualenv that referenced this pull request Sep 27, 2026
GraalPy cannot use pytest-xdist because its worker threads trip GraalVM's
Context.close() check (pypa#3240). The suite ran in one process and hit the
65 minute step timeout on ubuntu-24.04.

The runner now starts one serial pytest process per CPU. A --shard=K/N
option in the test conftest gives each process every Nth test ID in
sorted order, so the slices agree even though pytest-randomly shuffles
each process in its own order. Each shard keeps the polyglot shutdown
tolerance, and the run fails if any shard fails or no test ran.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant