From d8f86052755476ea8e95a552cd74266503d450e6 Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Mon, 22 Jun 2026 08:29:54 +0200 Subject: [PATCH] Drop -n 4 xdist parallelism from the pytest-coverage pre-commit hook The coverage gate failed twice in a row on GitHub Actions on the exact same line (wake_alarm/_alarm_display.py:71), with the run rerun on the identical commit -- ruling out a one-off flake. Could not reproduce locally across 6 attempts, including running the exact same -n 4 invocation directly. The likely cause is a pytest-xdist/pytest-cov worker coverage-combine timing issue specific to the CI runner that isn't practical to root-cause further from here. Running the hook serially removes the risk outright; local timing shows no meaningful slowdown. Co-Authored-By: Claude Sonnet 4.6 Claude-Session: https://claude.ai/code/session_01A7vbgtFfZmfxJtN5DdtJky --- ...t-xdist-coverage-flake-fix-2026-06-22.json | 28 +++++++++++++++++++ meta/scripts/pytest_changed_packages.py | 8 ++++-- 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 docs/superpowers/evidence/pytest-xdist-coverage-flake-fix-2026-06-22.json diff --git a/docs/superpowers/evidence/pytest-xdist-coverage-flake-fix-2026-06-22.json b/docs/superpowers/evidence/pytest-xdist-coverage-flake-fix-2026-06-22.json new file mode 100644 index 0000000..31d42fb --- /dev/null +++ b/docs/superpowers/evidence/pytest-xdist-coverage-flake-fix-2026-06-22.json @@ -0,0 +1,28 @@ +{ + "intent": "Eliminate a reproducible (not flaky) coverage-gate false failure on GitHub Actions, where pytest-xdist's -n 4 workers combined with pytest-cov consistently dropped coverage of one specific line (wake_alarm/_alarm_display.py:71) on the CI runner, never locally.", + "scope": [ + "meta/scripts/pytest_changed_packages.py (the pre-commit pytest-coverage hook entry point)", + "Non-goal: a full root-cause diagnosis of the xdist/coverage interaction itself -- not reproducible locally despite 6 attempts, so the fix removes the risk rather than chasing the exact mechanism" + ], + "changes": [ + "Removed the -n 4 (pytest-xdist parallel workers) flag from the pytest invocation this hook runs. Serial execution has never produced a coverage gap in any local or CI run; -n 4 produced the identical gap on two consecutive CI runs (a rerun of the same commit), which rules out a one-off flake and points at a CI-runner-specific worker/coverage-combine timing issue this repo cannot fix at the pytest-cov/xdist level from here." + ], + "verification": [ + { + "command": "time python meta/scripts/pytest_changed_packages.py python_pkg/wake_alarm/_alarm.py", + "result": "pass", + "evidence": "948 passed, 100.00% coverage, 14.3s total -- functionally identical runtime to the parallel version locally, with the coverage gap gone" + }, + { + "command": "pre-commit run --all-files", + "result": "pass", + "evidence": "all hooks green including pytest-coverage" + } + ], + "risks": [ + "Slightly slower CI runs without parallelism, though local timing showed negligible difference (~13-14s either way for this test count); reliability of the 100%-coverage gate matters more than a few seconds" + ], + "rollback": [ + "git revert this commit to restore -n 4 if CI proves the gap was actually something else (e.g. transient runner load) -- but two identical consecutive failures on the same line make that unlikely" + ] +} diff --git a/meta/scripts/pytest_changed_packages.py b/meta/scripts/pytest_changed_packages.py index 87791b0..c10baba 100755 --- a/meta/scripts/pytest_changed_packages.py +++ b/meta/scripts/pytest_changed_packages.py @@ -56,8 +56,12 @@ def main() -> int: "--cov-report=term-missing", "--cov-fail-under=100", "-q", - "-n", - "4", + # No -n/xdist: pytest-cov's worker coverage combine has shown a + # reproducible (not flaky -- failed identically twice in a row) gap + # under -n 4 on the GitHub Actions runner that never occurs running + # serially, including run repeatedly with the same -n 4 locally. + # Serial is slightly slower but has never produced a false coverage + # failure, which matters more for a 100%-coverage gate. # Override addopts from pyproject.toml to avoid double --cov flags. "-o", "addopts=--strict-markers --strict-config -ra",