Skip to content

perf(planning): run the Python suite in parallel with pytest-xdist - #9017

Merged
kyle-sexton merged 5 commits into
mainfrom
perf/8757-planning-suite-time
Oct 22, 2026
Merged

kyle-sexton merged 5 commits into
mainfrom
perf/8757-planning-suite-time

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Refs: #8757

Summary

The four planning surface Python modules (test_server, test_exporters, test_round, test_schema under plugins/planning/surface/) take 318 s serially on the dev host (394 suite-seconds in scripts/suite-seconds.txt). This runs each of them on pytest-xdist workers in test-python.

This links #8757 without closing it: the issue's verification is the local scripts/check-affected.sh --tests gate under a budget, and that gate runs no Python (affected-tests.sh names test_*.py as NOT RUN and exits 3), so this PR changes CI only.

Fix

  • .github/requirements-ci.txt: pin pytest-xdist==3.8.0 (latest release; requires pytest>=7.0.0) and its one dependency execnet==2.1.2, one wheel hash each, from PyPI's JSON API. Local venvs (scripts/setup-env.sh) and the lane test-file runner install from the same file.
  • .github/workflows/pr-require-checks.yml, test-python: the xargs loop becomes a while read loop that adds -n auto --dist loadscope for plugins/planning/surface/* modules only. Every module still runs in its own process, every module still runs after a failure, the command is still echoed, and the step fails if any module failed. loadscope keeps each test class on one worker, since TestApi's tests share ordered class state.
  • Scope: plugins/planning/shared/tests/ stays serial. Under -n auto (24 workers, host load average 60 to 96), test_share.py failed twice with "the server did not start within 15 s". It passed serially and at 4 workers. That points to timing sensitivity under load, so it is left out.

Verification

  • Before: 318 s serial for the four surface modules (dev WSL host).
  • After: 114 s for the same four, run through the shipped loop with 4 workers (PYTEST_XDIST_AUTO_NUM_WORKERS=4, the hosted runner's vCPU count), at host load average about 20 on 24 cores: 648 passed, 1 skipped, 0 failed. The leg log of this PR's CI run will show the hosted runner's figure.
  • Failure handling: a list with a missing module first and a passing module second ran both and exited 1.
  • pip install --only-binary=:all: --require-hashes -r .github/requirements-ci.txt (via scripts/setup-env.sh) installed xdist 3.8.0 and execnet 2.1.2, which checks the hashes.
  • actionlint clean. Passing: check-hook-exec-form.test.sh, portfolio-facts.test.sh, ci-ordered-skips.test.sh, plan-test-lanes.test.sh, check-docs-only-gate.test.sh, setup-env.test.sh, setup-env.test.mjs, check-script-contract.test.sh, dependency-classify.test.mjs, collect-base-activity.test.mjs, and ci-test-node-stop-commands.test.sh (with the venv Python; without PyYAML on PATH it fails the same way on main).

Follow-up: the surface entries in scripts/suite-seconds.txt now overstate their time. That costs leg balance only, not coverage. Remeasure them from a whole-tree run.

Related

#8757, #3716

🤖 Generated with Claude Code

kyle-sexton and others added 2 commits October 22, 2026 00:15
Pin pytest-xdist 3.8.0 and its dependency execnet 2.1.2 in
.github/requirements-ci.txt (wheel hashes from PyPI). test-python now
runs each plugins/planning/surface/ module with -n auto --dist loadscope;
loadscope keeps a test class on one worker, since TestApi's tests share
ordered class state. Every other module runs as before, one process per
module, and the loop still runs every module after a failure and fails
the step if any failed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T04:21:11.298737Z 7312eba PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@kyle-sexton
kyle-sexton enabled auto-merge October 22, 2026 04:21
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 2ba4f03482217634da9eeed271e39877a7cc9254: 0 finding(s), 0 as inline comments.

Security review: PR 9017 (head 2ba4f03)

Findings: 0. No inline comments posted.

PR is open and touches two files: .github/requirements-ci.txt and .github/workflows/pr-require-checks.yml.

  • New dependencies: execnet==2.1.2 and pytest-xdist==3.8.0 are added with exact version pins and --hash=sha256 entries, in the same form as the existing pins. They run only in the CI test job. No pin is loosened, and nothing unpinned or from outside the repository is added. A hash mismatch would fail the install. I did not check the new hashes against PyPI, because the lookup needed approval and I didn't pursue it.
  • test-python step rewrite: The step now loops over suite paths read from $RUNNER_TEMP/leg-suites.txt instead of piping them to xargs.
    • Each path is quoted as "$suite" and placed after --, so a path can't inject a command or pytest option.
    • The read -r call and the workers array (-n auto --dist loadscope) take no untrusted input.
    • The trace echo interpolates only the file-derived path, and no github context expression is used in the run: block.
    • The || rc=1 and exit "$rc" keep a failing suite failing the job.
  • Workflow permissions and triggers: The diff doesn't change permissions:, triggers, secrets, or action pins.
  • Manifests and instruction surfaces: No plugin manifest (plugin.json or marketplace.json) is in the diff, so there are no manifest <field> lines. The diff deletes no instruction-surface rules, so the exception register was not needed.

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed 2ba4f03482217634da9eeed271e39877a7cc9254: 0 finding(s), 0 as inline comments.

No findings. I reviewed the 2-file diff (.github/requirements-ci.txt, .github/workflows/pr-require-checks.yml) and posted no inline comments.

What I checked

  • The test-python install step installs .github/requirements-ci.txt with --require-hashes on every leg, so -n auto always has xdist available on the legs that run the surface modules.
  • leg-suites.txt is written by jq -r, so it ends in a newline and while read reaches the last entry.
  • A failing module sets rc=1, the remaining modules still run, and the step exits non-zero at the end. This matches the previous xargs behaviour that ran every module and failed the step if any failed.
  • workers=() followed by "${workers[@]}" is safe on the runner's bash. The [[ ... ]] && workers=(...) line cannot trip -e.
  • The surface tests create their temp directories with tempfile.mkdtemp and unique prefixes. I found no fixed ports or shared /tmp paths in plugins/planning/surface/*.py, so I saw no collision between workers. --dist loadscope keeps each class's tests on one worker.
  • The other consumers of requirements-ci.txt read single pins by awk or grep (pr-test-windows.yml reads pyyaml, scripts/run-ruff.sh reads ruff). The two new pure-Python pins don't affect them.
  • No closing issue: the PR uses Refs: #8757, so there are no acceptance criteria to check.
  • No .claude/rules/ file's globs match the changed files, and no plugin manifests changed.

Not verified

  • I didn't run the workflow or the tests. The 318 s to 114 s timing, the 648 passed result and the failure-handling check are author-claimed. Whether the lane finishes within timeout-minutes: 7 on the hosted runner is unverified until this PR's CI leg log shows it.

Observation, not a finding

  • The loop gives pytest the loop's stdin (the suite list) where xargs gave it /dev/null. Pytest's default fd capture replaces fd 0 during tests, so this shouldn't matter, but adding </dev/null to the pytest call would remove the question.

@kyle-sexton
kyle-sexton added this pull request to the merge queue Oct 22, 2026
Merged via the queue into main with commit 31e7c9f Oct 22, 2026
35 checks passed
@kyle-sexton
kyle-sexton deleted the perf/8757-planning-suite-time branch October 22, 2026 07:24
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