Skip to content

perf(ci): direct pytest runs wait for a gate slot - #4901

Merged
dan-petty merged 2 commits into
mainfrom
perf/4525-pytest-gate-slot
Nov 12, 2026
Merged

dan-petty merged 2 commits into
mainfrom
perf/4525-pytest-gate-slot

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

A direct uv run pytest with the -n logical of addopts took no gate slot. On the shared host it started one xdist worker for each CPU beside a devops ci gate that held the only slot, so the gate ran 3 to 6 times slower and hit its timeout.

  • gate_slot sets DEVOPS_CLI_GATE_SLOT_HELD=1 while it holds a slot, so the pytest of a gate takes no second slot.
  • direct_run_slot holds a slot for a pytest run that no holder started, and gives at most the CPUs of the process over the number of slots.
  • The root conftest wraps the xdist hook pytest_xdist_auto_num_workers. xdist calls it only for -n logical or -n auto, before pytest_configure. A run with an explicit -n or --collect-only takes no slot.
  • CONTRIBUTING.md and docs/TESTING.md say which runs take a slot.

Closes #4525

Change: openspec/changes/archive/2026-11-12-4525-direct-pytest-runs-ignore-the-gate/

A direct uv run pytest with the addopts -n logical took no gate slot, so it
started one xdist worker for each CPU beside a devops ci gate that held the
only slot.

- gate_slot sets DEVOPS_CLI_GATE_SLOT_HELD=1 while it holds a slot, so the
  pytest that a gate starts takes no second slot.
- direct_run_slot holds a slot for a pytest run that no holder started, and
  gives at most the CPUs of the process over the number of slots.
- The root conftest wraps pytest_xdist_auto_num_workers, which xdist calls
  only for -n logical or -n auto, and caps the count of xdist.
- CONTRIBUTING.md and docs/TESTING.md say which pytest runs take a slot.
@dan-petty dan-petty added type/infra Type infra: the build, CI, images or cluster scope/ci GitHub Actions workflows, pre-commit hooks, CI gates, and runners labels Nov 12, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Proof and measurements

Before (origin/main): the root conftest has no hook, so xdist gives -n logical the CPU count (16 on the shared host) at once, also beside a gate. The issue measured the effect on 2026-11-11: the load average went from 2 to 41, and the test row of the gate hit its 1800 s timeout. During this work on 2026-11-12, direct uv run pytest runs of other worktrees ran beside gates at a load average of 47 on 16 CPUs.

After (this branch): a scratch data directory (DEVOPS_CLI_DATA_DIR), DEVOPS_CLI_CI_GATE_SLOTS=4, 16 CPUs, and all 4 slots held by flock -o <slot-N.lock> sleep. The base command is uv run pytest tests/ci/test_ci_gate_slots.py -k number_of_slots.

Run Waited Workers Result
A: base command Yes. The wait line came after 17 s, and the run still waited 30 s later. It started after the holders ended. 4 (created: 4/4 workers) 7 passed
B: with DEVOPS_CLI_GATE_SLOT_HELD=1 and PYTEST_XDIST_AUTO_NUM_WORKERS=2 No 2 7 passed
C: with -n 2 No 2 7 passed
D: with --co -q No none 22 tests collected

The wait line of A: Waiting for a CI gate slot. Allowed at one time: 4. Held by: another run.

CI: the job count and the runner-min do not change. The devops ci test row and its shards hold the slot in the devops process, so their pytest gets DEVOPS_CLI_GATE_SLOT_HELD=1 and keeps -n logical.

Cost: the hook adds one load_settings() (8.8 s) and one data path lookup (0.06 s) to the controller of a direct run, measured at a load average of 48 on 16 CPUs. The controller already imports devops-cli when it registers the support plugins.

Checks

  • Red: uv run devops ci test tests/ci/test_ci_gate_slots.py failed with ImportError: cannot import name 'direct_run_slot' before the implementation.
  • uv run devops ci test tests/ci/test_ci_gate_slots.py: 23 passed.
  • uv run devops ci test tests/ci/test_ci_gate_slots.py tests/ci/test_ci_gate_admission.py tests/invariants/test_hermetic_floor.py tests/core/test_subprocess_env_boundary.py tests/config/test_isolation_tripwire.py: 619 passed (before the child-environment test was added).
  • uv run devops ci fail-to-pass --base origin/main: errored on base: tests.ci.test_ci_gate_slots (collection failure), because the base has no direct_run_slot. This pull request adds behavior (perf); it is not a fix.
  • uv run devops ci docs and uv run devops openspec check pass. mypy reports no error in src/devops_cli/ci/gate_slots.py or in the new conftest lines.
  • Not run: the full local suite. The host load average was 40 to 50, so the CI runs of this pull request are the full-suite proof.

Owner steps

None. The change needs no setting, cluster or repository change.

@dan-petty

Copy link
Copy Markdown
Owner Author

CI and in-image results

  • CI Quality Gate run 43142771802 of this pull request: 16 jobs, 36 runner-min, 361 s run time. The 4 Tests & Coverage shards took 246, 164, 237 and 153 s. The test row holds the slot in the devops process, so this change does not alter these numbers.
  • The in-image suite calls pytest.main directly, not through devops ci, so there the hook runs as a direct run. The slot directory resolves under the writable project copy (/workspace/project/.data). A workflow_dispatch of Service Image Tests on this branch (run 43143507971) passed 5 of 6 shards. Shard 5 failed only tests/invariants/test_hermetic_floor.py::test_a_support_helper_called_outside_pytest_writes_nothing (No module named pytest in a child Python), and its other 4202 tests passed. That failure came with fix(tests): refuse test writes under the real home #4857 and fix(tests): the plain-Python helper test fails in the Service image #4891 tracks it.

@dan-petty
dan-petty marked this pull request as ready for review November 12, 2026 03:13
@dan-petty
dan-petty merged commit e80db62 into main Nov 12, 2026
32 of 33 checks passed
@dan-petty
dan-petty deleted the perf/4525-pytest-gate-slot branch November 12, 2026 03:13
dan-petty pushed a commit that referenced this pull request Nov 12, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.115.0](v0.114.1...v0.115.0)
(2026-11-12)


### Features

* **design:** add the design tokens and their build
([#4811](#4811))
([db4b19a](db4b19a))
* **roadmap:** find symbol definitions with tree-sitter
([#4820](#4820))
([3b3fddc](3b3fddc))


### Bug Fixes

* **ai:** the gateway group that answered decides the local label
([#4907](#4907))
([0da637f](0da637f))
* **ci:** replay a changed gate check in fail-to-pass
([#4898](#4898))
([59bfc57](59bfc57))
* **config:** read each config file as YAML 1.2
([#4858](#4858))
([c3130a3](c3130a3))
* **roadmap:** loosen the caps that turn a stage refusal into a loss
([#4869](#4869))
([4492fc3](4492fc3))
* **roadmap:** refine reads a dependency named by title
([#4877](#4877))
([2829f9c](2829f9c))
* **roadmap:** refine sends a judge refusal to an agent round
([#4874](#4874))
([e4fc6a9](e4fc6a9))
* **tests:** refuse test writes under the real home
([#4857](#4857))
([0f6ac1b](0f6ac1b))
* **tests:** the plain-Python helper test keeps PYTHONPATH
([#4914](#4914))
([99c109d](99c109d))


### Performance Improvements

* **ci:** direct pytest runs wait for a gate slot
([#4901](#4901))
([e80db62](e80db62))
* **roadmap:** status lane reads the snapshot, skips idle stops
([#4887](#4887))
([f285cf8](f285cf8))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/ci GitHub Actions workflows, pre-commit hooks, CI gates, and runners type/infra Type infra: the build, CI, images or cluster

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(ci): direct pytest runs ignore the gate slot

1 participant