Skip to content

fix(ci): a narrowed run of fast tests starts 4 workers #5612

Done

Description

@dan-petty

Problem Description

A narrowed devops ci test run chooses its workers from the count of collected tests (#4472): up to 50 tests run serially, and more tests run on 4 workers. The count does not show the time of the tests. A module of fast tests just above the limit pays for a collection session and for the start of 4 xdist workers, and the run is about 2.5 times slower than a serial run.

Reproduction Steps

  1. On a host with 16 CPUs and a low load, with PYTEST_XDIST_AUTO_NUM_WORKERS not set, run uv run devops ci test tests/roadmap/test_roadmap_claim.py (52 tests).
  2. Run uv run devops ci test -n 0 tests/roadmap/test_roadmap_claim.py.

Expected vs Actual Behavior

Expected: a narrowed run of tests that take less than a second in total runs serially, and starts no collection session and no workers.

Actual: step 1 makes a collection session, then created: 4/4 workers, and takes 21.9 s to 22.3 s end to end. The 52 tests ran in 7.5 s on 4 workers. Step 2 takes 8.4 s to 8.8 s, and the 52 tests run in 0.3 s. The start of pytest (6 s to 8 s for each session) is most of the time.

Environment Diagnostics

devops-cli at the branch of #5606 (base b15faab), devcontainer, Python 3.14, pytest 9.2.0, pytest-xdist 3.8.0, load average 1.7 to 2.7 on 16 CPUs.

Logs, Traces, or Terminal Output

step 1: created: 4/4 workers ... 52 passed in 7.48s  (wall 21.9 s)
step 2: 52 passed in 0.39s                          (wall 8.8 s)

The #5606 fix bounds the collection and skips it on a 1-CPU pod and for more than 50 target modules, but it keeps the rule of 50 collected tests, so this cost stays on hosts with more CPUs. The design of #4472 rejected a duration cache because the project keeps none. Related: #4472, #5606, #1669.

Alternatives check of 2026-11-20: none.
Tool: none found.
Reason: Searches and package facts found only pytest-xdist, pytest-split and pytest-testmon: xdist starts the explicit -n it is given and reads no durations, pytest-split needs a stored durations file to split CI groups, and testmon selects affected tests; none chooses serial versus workers for a narrowed run.

Lacks:

  • No automatic serial choice from test duration
  • No skip of the collection session before choosing workers
  • Duration-based splitting needs a stored durations file
  • No rule that one target module runs serially

Proposed design

Problem statement

A narrowed devops ci test run chooses serial versus xdist workers from the count of collected tests. A fast module just over 50 tests pays a collection session and 4 xdist workers, and the run is about 2.5 times slower than a serial run. The change makes a narrowed run to one target module serial, starts no collection session and no worker, and keeps the count rule for two or more modules and the explicit -n override.

Acceptance criteria

Requirement: Single-module narrowed run is serial

A narrowed devops ci test run with no -n and one target test module SHALL run serially and start no collection session.

Scenario: One fast module over 50 tests

  • WHEN A test drives devops ci test tests/roadmap/test_roadmap_claim.py with PYTEST_XDIST_AUTO_NUM_WORKERS unset and records each pytest spawn.
  • THEN The test sees one pytest spawn with -n 0 and no spawn that holds --collect-only.

Requirement: Multi-module narrowed run keeps the count rule

A narrowed devops ci test run with no -n and two or more target modules SHALL keep the collected-test count rule.

Scenario: Two modules over the serial limit

  • WHEN A test drives devops ci test for two target modules on a host of 16 CPUs, and the collection reports 51 tests.
  • THEN The test sees a spawn that holds --collect-only, and the run spawn uses a worker count above 1.

Requirement: Explicit worker count wins

A devops ci test run with an explicit -n SHALL use that count and start no collection session.

Scenario: Explicit -n 2 on one module

  • WHEN A test drives devops ci test -n 2 tests/roadmap/test_roadmap_claim.py.
  • THEN The test sees one pytest spawn with -n 2 and no spawn that holds --collect-only.

Requirement: Help text states the single-module rule

The -n help text of devops ci test SHALL state that a narrowed run to one target module runs serially with no collection session.

Scenario: The -n help line

  • WHEN A test runs devops ci test --help and reads the line of -n.
  • THEN The line states that a narrowed run to one target module runs serially with no collection session.

Existing Tool Considered

The alternatives check in the issue body (2026-11-20) records verdict none and no tool. The block lists what it covers and what it lacks. The change builds its own code in the existing devops ci test wrapper. It covers the lacks that the block names, because the command knows the count of target modules before pytest starts. Written cost: about 8,000 tokens to build, 1,000 tokens a month to keep and fix, and half a day elapsed.

Key questions

  • Does pytest-xdist choose its worker count from test duration?: No. pytest-xdist starts the explicit -n that it is given. PYTEST_XDIST_AUTO_NUM_WORKERS affects only -n auto and -n logical, and the command applies that value to its explicit -n. The run has no duration input. [sources: docs/TESTING.md:174, src/devops_cli/commands/ci.py]
  • How does the command know the count of target modules before it collects?: The command resolves the targets to test modules before it collects. The fix(ci): narrowed test workers fall back and slow runs #5606 fix already skips the collection for more than 50 target modules, so the count is known with no pytest session. [sources: src/devops_cli/commands/ci.py]
  • Should the fix add a duration cache to choose workers?: No. The fix uses the count of target modules, which the command knows with no collection and no stored durations. (best practice) [sources: docs/TESTING.md:174, docs/commands/ci.md:51]
    • Chosen: One-module serial rule. The command knows one target module before pytest starts, so it starts no collection session and no worker.
    • Rejected: Duration cache. fix(ci): a narrowed ci test runs many slow tests serially #4472 rejected it because the project keeps no durations; it adds a write path and a first-run fallback.
    • Rejected: Raise the collected-test limit. The count still does not show the time of the tests, so a slow selection over the new limit pays the same cost.
  • How should a narrowed run with one target module choose workers?: Run it serially with -n 0 and skip the collection. Two or more target modules keep the existing collected-test count rule. (best practice) [sources: docs/TESTING.md:174, docs/commands/ci.md:51, src/devops_cli/config/defaults.py]
    • Chosen: One-module serial rule. It removes the collection session and the 4 workers from the reported 52-test module, where the pytest start is most of the 21.9 s.
    • Rejected: Keep the collected-test count rule. The 52 tests collect over the 50-test limit, so the run starts 4 workers and pays the collection session.
    • Rejected: Run every narrowed selection serially. It removes workers from large narrowed selections that take longer than the 6-8 s start of xdist.
  • Should an explicit -n still override the new rule?: Yes. A given -n keeps its worker count and gets no collection call. A person who knows that one module is slow keeps the worker count. (best practice) [sources: docs/TESTING.md:174, docs/commands/ci.md:51]
    • Chosen: Keep the explicit -n override. A person who knows that the module is slow keeps the worker count, and the change keeps the current contract.
    • Rejected: Let the one-module rule override -n. It breaks the documented contract of -n and removes the escape for a slow module.
  • Which files hold the worker choice, its defaults and its tests?: src/devops_cli/commands/ci.py holds the worker choice. src/devops_cli/config/defaults.py holds the default limits. tests/commands/test_test_selection.py holds the selection tests. docs/TESTING.md and docs/commands/ci.md state the rule. [sources: src/devops_cli/commands/ci.py, src/devops_cli/config/defaults.py, tests/commands/test_test_selection.py, docs/TESTING.md:174, docs/commands/ci.md:51]
  • Does the change need a new dependency or tool?: No. pytest-xdist is already the worker runner. The change uses the existing command wrapper and the existing default limits. [sources: docs/TESTING.md:174, src/devops_cli/config/defaults.py]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#5606

Activity

  1. added
    source/agent
    type/bug
    scope/ci
    status/new
    value/medium
    effort/medium
    on Nov 14, 2026
  2. dan-petty commented on Nov 14, 2026

    @dan-petty
    OwnerAuthor
  3. added
    priority/p2-medium
    on Nov 14, 2026
  4. devops-cli-service commented on Nov 18, 2026

    @devops-cli-service
    Contributor

    Waiting for the alternatives check to run. The next refine round looks at the item again after the check records a verdict.

  5. devops-cli-service commented on Nov 20, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.

    Searches (8)

    Tools considered:

    Searches run:

    • pytest plugin decide serial vs parallel based on test suite duration, results: 5
    • pytest-xdist choose number of workers automatically based on test duration, results: 5
    • pytest-xdist documentation "PYTEST_XDIST_AUTO_NUM_WORKERS" -n auto logical, results: 5
    • pytest-split test durations split tests across workers, results: 5
    • pytest-split PyPI, results: 5
    • pytest-xdist PyPI package, results: 5
    • test runner decides parallel execution overhead small test suite, results: 5
    • xdist worker count test duration github, results: 5

    Sources:

  6. added
    status/ready
    and removed
    status/new
    on Nov 21, 2026
  7. devops-cli-service commented on Nov 21, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  8. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 25, 2026
  9. removed
    status/in-review
    owner/agent
    on Nov 25, 2026
  10. devops-cli-service commented on Nov 25, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-25 17:24 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/cisource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions