Repository navigation
Description
Problem Description
On the shared 16-CPU devcontainer host, the local test row is slow because of load, not because of the cost of the checks. A direct uv run pytest takes no gate slot (ci.gate_slots, #2336), and addopts of pyproject.toml starts -n logical workers (16 here) for each run. So the gate slot limits only devops ci runs, and the runs of other agents still start 16 workers each beside a gate.
Measured on 2026-11-11 from 02:22 UTC, one full uv run devops ci --check --no-cache that held the only gate slot:
- The load average went from 2 to 41 within 2 minutes and stayed at 40 to 55 for the run.
- A snapshot by process working directory: the gate's test row used 615% CPU (17 processes); a direct
pytestover a list of test files in another worktree used 458% (17 processes, 16 workers); other scripts used about 250%. The 16 workers of the gate got 25% to 43% of a CPU each. - The test row hit its 1800 s timeout. mypy took 9 min 40 s and bandit 12 min 30 s, where the GitHub runner runs every static row in 84 to 90 s.
- Over 45 local gate logs of the last 5 days, the test row had a median of 756 s (minimum 296 s, maximum 1,811 s).
Each xdist worker also collects the whole suite (22,533 items) before it runs a test, so 16 workers pay the collection 16 times in CPU.
Reproduction Steps
- Start
uv run devops ci --check --no-cachein one worktree. - While it runs, start
uv run pytest <many test files>in another worktree. - Read
/proc/loadavgand the CPU of each pytest worker (top -b -n 2).
Expected vs Actual Behavior
Expected: a second large pytest run waits for the gate slot, or starts fewer workers, so the gate runs near its idle time.
Actual: both runs start 16 workers, and the gate runs 3 to 6 times slower than alone.
Proposed fix
Let a pytest run with more than one module take part in the gate slot rule. pytest-xdist has the hook pytest_xdist_auto_num_workers, which sets the number of workers for -n logical and -n auto. The root conftest.py can give the narrowed count DEFAULT_CI_TEST_NARROWED_WORKERS (4) when another process holds a gate slot. A run of devops ci keeps its count. Measure the gate time with a second large run before and after.
Environment Diagnostics
Devcontainer on WSL2, 16 CPUs, rootless Podman. Several agents work in their own worktrees at the same time.
Logs, Traces, or Terminal Output
Found by the measurement of #4405.
Pre-Submission Checklist
- I have verified that no sensitive credentials, private keys, or internal tokens are contained in this issue report.
- I have checked existing issues and pull requests to ensure this is not a duplicate.
Proposed design
Problem statement
Direct uv run pytest runs ignore the ci.gate_slots rule. On the 16-CPU host they start 16 xdist workers beside a gate run. The gate test row then times out and the static rows run 6 to 9 times slower. The change makes a direct pytest run narrow to 4 workers when another process holds a gate slot. A devops ci run keeps its count.
Acceptance criteria
Requirement: Direct pytest narrows on a held gate slot
A direct pytest run with -n logical or -n auto SHALL use DEFAULT_CI_TEST_NARROWED_WORKERS workers when another process holds a gate slot.
Scenario: Another process holds the gate slot
- WHEN a direct
uv run pyteststarts withaddopts-n logicaland another process holds the gate slot - THEN pytest starts 4 xdist workers, not 16.
Requirement: Gate run keeps its worker count
A devops ci test row SHALL keep its configured worker count when it holds a gate slot.
Scenario: The gate run owns the slot
- WHEN the
devops citest row starts pytest while it owns the gate slot - THEN the hook sees
DEVOPS_CI_GATE_RUN=1and returnsNone, soaddopts-n logicalselects the worker count.
Requirement: Gate run marks its pytest environment
The devops ci test row MUST set DEVOPS_CI_GATE_RUN=1 in the environment of its pytest process.
Scenario: Marker is present
- WHEN the
devops citest row starts its pytest process - THEN
DEVOPS_CI_GATE_RUN=1is present in that process environment.
Requirement: Explicit worker count is kept
A pytest run with an explicit -n value SHALL keep that value even when a gate slot is held.
Scenario: Explicit -n 8 during a held slot
- WHEN a user runs
uv run pytest -n 8while another process holds a gate slot - THEN pytest starts 8 xdist workers.
Requirement: Narrowed count comes from the constant
The narrowed worker count SHALL come from DEFAULT_CI_TEST_NARROWED_WORKERS.
Scenario: The constant changes
- WHEN a test sets
DEFAULT_CI_TEST_NARROWED_WORKERSto 2 and another process holds a gate slot - THEN the hook returns 2.
Requirement: Hook uses the existing gate lock
The hook MUST read the same gate-slot lock that devops ci uses and MUST NOT create a second lock.
Scenario: The gate lock is held
- WHEN the gate-slot lock records a held slot and
DEVOPS_CI_GATE_RUNis absent - THEN the hook treats the slot as held and returns the narrowed count.
Existing Tool Considered
No alternatives check has run. pytest-xdist 3.8.0, already a dev dependency in pyproject.toml, covers worker-count selection through the pytest_xdist_auto_num_workers hook. It lacks awareness of the gate slot. A small root conftest.py hook reads the slot and returns DEFAULT_CI_TEST_NARROWED_WORKERS. The change adds no new dependency and builds no worker pool.
Key questions
- Does pytest-xdist 3.8.0 provide a hook that sets the worker count for
-n logicaland-n auto?: Yes.pytest_xdist_auto_num_workers(config)returns the worker count for auto and logical detection. An explicit-nvalue bypasses the hook. [sources: pyproject.toml] - Where must the worker narrowing live so that a direct
uv run pytesttakes it?: In the rootconftest.pyas apytest_xdist_auto_num_workershook. A wrapper arounddevops cicannot affect a direct pytest run. (best practice) [sources: pyproject.toml]- Chosen: Root conftest hook. pytest loads it for every run, including a direct
uv run pytest, and it controls auto and logical worker selection. - Rejected: Fixed low worker count in
addopts. It would slow the full suite and the gate run, which need logical workers. - Rejected: Wrapper script or alias around pytest. A direct
uv run pytestbypasses the wrapper.
- Chosen: Root conftest hook. pytest loads it for every run, including a direct
- How does a direct pytest run know that another process holds a gate slot, while a
devops cirun keeps its count?: Thedevops citest row setsDEVOPS_CI_GATE_RUN=1in the environment of its pytest process. The hook narrows only when the marker is absent and the gate-slot lock is held. (best practice) [sources: src/devops_cli/commands/ci.py, src/devops_cli/config/defaults.py:470]- Chosen: Marker environment variable plus the existing gate-slot lock. It tells the owner from another process without guessing process ancestry.
- Rejected: Compare the lock owner PID with the pytest PID.
devops ciholds the lock in the parent process, not in pytest. - Rejected: Use the system load average. Load average does not say who holds the slot and changes between reads.
- Which worker count does a narrowed direct run use?:
DEFAULT_CI_TEST_NARROWED_WORKERS, currently 4, fromsrc/devops_cli/config/defaults.py. [sources: src/devops_cli/config/defaults.py:470, docs/TESTING.md:159] - Should the hook narrow every direct auto or logical run, or only a run with more than one module?: Narrow every direct auto or logical run when another process holds a gate slot. A single module still starts 16 workers and pays the collection and startup cost 16 times. (best practice) [sources: pyproject.toml, src/devops_cli/config/defaults.py:470]
- Chosen: Narrow every direct auto or logical run. It removes the contention for a single module as well as for many modules.
- Rejected: Narrow only a run with more than one module. A single module still starts 16 workers and pays the collection and startup cost 16 times.
- Should the change also reduce the duplicate collection that each xdist worker does?: No. Keep the change to the worker count. Duplicate collection is a separate cost and a separate change. (best practice) [sources: pyproject.toml]
- Chosen: Keep the change to the worker count. The issue measures worker contention. Collection is a second cause with a different fix.
- Rejected: Also change collection in this issue. It expands the change and mixes two risks.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Alternatives check of 2026-11-11: not-applicable.
Class: perf, no search.
Tool: none found.
Activity
dan-petty commentedon Nov 11, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
perfprefix of the title gives the type.(ci)scope of the title gives the scope.Severe local slowdown (3-6x, timeout hits) but limited to shared devcontainer hosts, not the production CI pipeline.Restores near-idle gate times for developers on shared 16-CPU hosts, removing a recurring source of failed local runs.The fix is a single pytest_xdist_auto_num_workers hook in the root conftest.py that reads the gate slot state and returns a narrowed count.Both address slow local test rows on a shared host; #4405 asks to measure and diagnose the cause, while this candidate proposes a specific fix (conftest.py hook to narrow workers when a gate slot is held).devops-cli-service commentedon Nov 11, 2026
Status set to Ready at 5f75d25 (see proposed design in issue body).
dan-petty commentedon Nov 11, 2026
Scope from the CI audit (2026-11-11)
Added facts (measured)
PYTEST_XDIST_AUTO_NUM_WORKERSfor-n logical(xdist/plugin.py:16-20), andbuild_subprocess_envalready lets it through (src/devops_cli/core/process.py:103-106).Solution
pytest_configureof the controller, take the slot withfilelock. Skip this in xdist workers and whendevops cialready holds the slot.PYTEST_XDIST_AUTO_NUM_WORKERSto the CPUs per slot for direct runs.Acceptance criteria
devops ciholds the only slot.-n logicalgives the CPUs-per-slot number of workers.Risk: a slot holder that hangs makes direct runs wait. The lock is released when the process stops.
devops-cli-service commentedon Nov 11, 2026
Alternatives check: not-applicable
Class: perf. The check makes no search and no model call for an item of this class.
Tool: none found
Checked on 2026-11-11. A person decides what this means for the item. The check changes no label and closes no issue.
devops-cli-service commentedon Nov 12, 2026
Released in v0.115.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.115.0
devops-cli-service commentedon Nov 12, 2026
Live since 2026-11-12 04:08 UTC