Repository navigation
fix(ci): a hanging test fails at a per-test timeout, and a narrowed devops ci test sizes its workers and stops its whole process group - #1717
Merged
Conversation
…evops ci test sizes its workers and stops its whole process group Nothing bounded a test, so one stuck child process held a devops ci run, and every xdist worker it owned, for more than an hour. pytest-timeout 2.4.0, the current release (2.5.0 is yanked), joins the dev group, and [tool.pytest.ini_options] sets timeout = 600 with timeout_method = "signal", so a test that hangs fails in its own process with pytest-timeout's report naming it, and the run and its worker carry on. The bound is a hang bound: the slowest test in 185 cached gate runs took 139 s at a load average of 30-50, the latest runs' slowest 21-34 s, and the bound stays under half the run's 1800 s timeout, so a hung test is reported by name before the whole run is stopped. No per-call timeout is added to the subprocess calls under tests/. A narrowed devops ci test given no -n started 16 workers for a few covering tests. It now runs serially for up to DEFAULT_CI_TEST_SERIAL_MAX_FILES (12) test modules and on DEFAULT_CI_TEST_NARROWED_WORKERS (4) above that; the full suite, the fallback to it and devops ci keep -n logical, and a given -n is kept. Measured at -n 0, 4 and 16 over selections of 1, 3, 5, 8, 12 and 19 test modules: up to 8, serial was the fastest or within the noise at about a third of the CPU of 4 workers; at 12, serial matched 4 workers' 79 against 82 s at 84 against 193 CPU-seconds; at 19, 4 workers ran 2.8 times faster than serial at about the same CPU. The hook's command for a one-module change took 10.6 s and 12 CPU-seconds against 17.7 s and 183 with -n logical. devops ci test ran pytest through subprocess.run, whose timeout kills only uv and left pytest running. Every pytest run it starts now goes through run_subprocess_async in a session of its own, so a timeout stops the whole group, and the run fails naming its command and timeout. No terminal or supervisor signal reaches that session, so a cancellation, which Ctrl-C makes and which SIGTERM and SIGHUP make for a devops ci test run, forwards the SIGINT a terminal would have sent, so pytest runs its teardown and finally blocks, then escalates to SIGTERM and SIGKILL. A second signal cuts the grace short but cannot skip the SIGKILL, which is sent from a finally; the start is shielded, so one cancellation while the child starts still stops its group, though a second Ctrl-C in that window leaves asyncio's clean-up to kill the child alone; and a late cancellation stays a cancellation. A timeout, which devops ci's checks share, still starts at SIGTERM. The handlers are set only from the main thread, leave an ignored SIGHUP ignored for nohup, and are handed back after the run. A serial run that hangs after its summary line is stopped with its whole group at the run's timeout, the only bound there, counted from the start: 1800 s for devops ci test. No serial run hung in the measured runs: the tail is pytest's unconfigure gc, the capture teardown and interpreter finalization, and the tracer's atexit shutdown cannot deadlock on its client lock, which no export holds during I/O. The tests drive devops ci test through its CLI, double the process edge at asyncio.create_subprocess_exec, refuse any real uv or pytest child, set the signal dispositions they rely on whatever the run inherited, run the real devops on the tree under test, and watch hung children through pidfds, failing a test whose child leads no session of its own and killing what a failing test leaves. The targeted-test command is uv run devops ci test <test-file> in AGENTS.md, CONTRIBUTING.md, docs/SDLC.md, docs/SELF_IMPROVEMENT.md, docs/ROUTINE_TASKS.md, the knowledge base and the generated AGENTS.md block, and docs/TESTING.md describes the bound, the workers, the stop and the doubles. The fail-to-pass replay's could-not-run report is the pull request that closes the item. Part of #1669
dan-petty
added a commit
that referenced
this pull request
Oct 20, 2026
…d-not-run (#1718) When pytest could not start on the replayed base tree, devops ci fail-to-pass reported "0 failed and 0 passed ...; 0 errored" as an outcome: a feature passed the check with nothing replayed, and a defect failed it saying no changed test failed on base, though none ran. _run_pytest_on_base dropped pytest's exit status and returned no outcomes when the JUnit report was missing. _run_pytest_on_base now keeps pytest's exit status. An exit of 2 (interrupted), 3 (internal error) or 4 (usage error), or a run that wrote no complete JUnit report, is a ReplayCouldNotRun on the report, with the exit status and the last whole lines of pytest's output that fit in 256 characters. Exit 3 counts with a report too, as pytest writes one holding pytest::internal when an internal error ends a session it had begun to report. A report that is empty or never closes its root testsuites element counts as none: the JUnit parser, still the stdlib HTMLParser, records whether the root closed. Such a replay fails the check for any pull request; the report names the exit status, the replayed test files and pytest's last output, and points to the Fail-to-pass: not applicable line, which still passes the check without replaying. Exit 5, no tests collected, stays an empty replay, and a replay whose tests collect and run reports as before, so a changed test that only fails to collect on base is reported as errored. The command writes an unsatisfied report raw, with markup and emoji codes off, so pytest's output reaches the terminal as pytest wrote it. AGENTS.md and the instruction generator's line say the check fails any pull request whose replay pytest could not run on base, as when the overlaid tests/ import support the base lacks or the pull request changes dependencies or the test harness; that such a pull request declares the not-applicable line; and that a changed test that only fails to collect on base is reported as errored. The could-not-run reports' text is checked against syrupy snapshots, the suite's first, which docs/TESTING.md now names; the trailing-whitespace hook leaves tests/__snapshots__/ alone, as trimming a blank line's indent breaks a snapshot. With part 1 (#1717), the per-test timeout, the narrowed run's worker count and its process-group stop, this completes the item. The task file keeps part 1's section and adds this one as PR 2, with every criterion of the item and both amendments delivered, and changelog.d/1669.md is the item's one fragment, covering both parts. Closes #1669
3 tasks
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 first of #1669's two pull requests. A hanging test fails at a per-test timeout, and a narrowed
devops ci testsizes its workers and stops its whole process group. Before this, nothing bounded a test: on 2026-10-18 one stuck child process held adevops cirun, and every xdist worker it owned, for more than an hour.Per-test timeout.
pytest-timeout2.4.0 joins the dev group. 2.4.0 is the current release; 2.5.0 is yanked.[tool.pytest.ini_options]setstimeout = 600andtimeout_method = "signal". A test that hangs fails in its own process with pytest-timeout's report naming it, and the run and its worker carry on.timeout=is added undertests/.Workers for a narrowed run. Given no
-n, a narroweddevops ci testruns serially for up to 12 test modules (DEFAULT_CI_TEST_SERIAL_MAX_FILES) and on 4 workers above that (DEFAULT_CI_TEST_NARROWED_WORKERS). The full suite, the fallback to it, anddevops cikeep-n logical, and an explicit-nis kept.The commit hook's run for a one-module change took 10.6 s and 12 CPU-seconds, against 17.7 s and 183 CPU-seconds with
-n logical.The whole process group stops.
devops ci testran pytest throughsubprocess.run, whose timeout killed onlyuvand left pytest running.run_subprocess_asyncin its own session. A timeout stops the whole group, and the run fails naming its command and timeout.devops ci test, cancels the run. The group first gets the SIGINT a terminal would have sent, so pytest runs its teardown andfinallyblocks, then SIGTERM, then SIGKILL.finally.devops ci's other checks: a timeout there still starts at SIGTERM and reports as before.nohup, and are handed back after the run.After the summary line. A serial run that hangs after printing its summary is stopped with its group at the run's timeout. That is the only bound there, counted from the start: 1800 s for
devops ci test. No serial run hung in 21 measured runs. The tracer's atexit shutdown can't deadlock on its client lock, because no export holds it during I/O.Tests.
devops ci testthrough its CLI, with the process edge doubled atasyncio.create_subprocess_exec. The signal tests run the realdevopson the tree under test, with a fakeuvand telemetry off.uvorpytestchild, except pytester's.nohupor as a background job.tests/support/hung_children.pywatches them through pidfds. It fails a test whose child leads no session of its own, and kills whatever a failing test leaves.Docs.
uv run devops ci test <test-file>in AGENTS.md,CONTRIBUTING.md,docs/SDLC.md,docs/SELF_IMPROVEMENT.md,docs/ROUTINE_TASKS.md, the knowledge base and the generated AGENTS.md block.docs/TESTING.mddescribes the bound, the workers, the stop and the doubles.docs/agent/tasks/task-1669-ci-runner-never-stalls.md, records all of it.Verification
ProcessLookupError;SIG_IGN;devops ci fail-to-pass --base origin/release/v0.2.37replays the changed tests on the base: the per-test-timeout and process tests fail there, and the selection tests don't collect. The pull request's own fail-to-pass check runs the same replay.uv run devops cipassed (pre-push hook).Part of #1669