Skip to content

perf(ci): split the test check into more shards #4473

Closed as not planned
Closed as not planned

Description

@dan-petty

Problem Description

The required check Tests & Coverage takes more than the 300 s of AGENTS.md rule 5 on GitHub runners, where no other work shares the host. uv run devops ci job-time on 2026-11-11 reads a mean of 503 s over the last 20 push runs of ci.yml on main, and exits 1.

The cost grows with the suite. The test step of a shard had a mean of 159 s from 2026-11-04 to 2026-11-06 and 254 s from 2026-11-07 to 2026-11-11 (sample of 10 runs a day from the Actions API). In the same 7 days the suite grew from 11,651 to 14,695 test functions (+26%, about 430 a day) and from 782 to 1,105 test files.

The time of the check, run 42938256840 on main (2026-11-11):

Part Time
pytest of shard 1, 2, 3, 4 200.8 s, 299.6 s, 306.4 s, 368.9 s
Items of shard 1, 2, 3, 4 6,189, 5,009, 5,364, 5,935
Setup of a shard job (checkout, uv, promtool) about 35 s
Join job Tests & Coverage (combine, changed-line coverage) 37 s (mean 52 s since 2026-11-07)

Even with a perfect balance (#4250), the 1,176 s of pytest time over 4 shards gives 294 s for each shard, and about 381 s for the check with the setup and the join job. Thus balance alone cannot bring the check under 300 s.

Reproduction Steps

  1. Run uv run devops ci job-time.
  2. Read the mean of the last 20 runs.

Expected vs Actual Behavior

Expected: the check averages 300 s or less.

Actual: 503 s on average over the last 20 runs on main.

Proposed fix

Add shards to the matrix shard of test-shard in .github/workflows/ci.yml (docs/SDLC.md: the name, --shards and the split follow the count). With a perfect balance, 6 shards give about 196 s of pytest for each shard and about 283 s for the check, and 8 shards about 147 s and 234 s. Each new shard adds about 35 s of setup and the collection of its own files in runner time. The suite grows about 430 test functions a day, so 8 shards keep a margin for longer than 6. Do this with #4250, which balances the shards by measured time, and with the fixes of the slowest tests (#4456, #4459).

Environment Diagnostics

GitHub-hosted ubuntu-26.04 runners, 4 workers in each shard (-n logical).

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

The required check Tests & Coverage averages 503 s on main, over the 300 s bound of AGENTS.md rule 5. The suite grows about 430 test functions a day. Balance alone cannot meet the bound. This item adds four entries to the shard matrix of test-shard in .github/workflows/ci.yml, so eight shards run. With the measured balance of #4250, the check averages about 234 s. The duration check fails on most push runs, so a real break of main is hard to see.

Acceptance criteria

Requirement: Eight shard entries

The shard matrix of the test-shard job in .github/workflows/ci.yml SHALL list the eight shards 1 to 8.

Scenario: The matrix holds eight entries

  • WHEN a test parses the shard matrix of the test-shard job in .github/workflows/ci.yml
  • THEN the matrix holds exactly the entries 1, 2, 3, 4, 5, 6, 7 and 8.

Requirement: The count comes from the matrix

The test-shard job SHALL take its job name and its --shards value from strategy.job-total, and its name and command SHALL hold no literal shard count.

Scenario: No literal count in the job name or command

  • WHEN a test reads the test-shard job of .github/workflows/ci.yml
  • THEN the job name holds ${{ strategy.job-total }}, the test step sets SHARDS: ${{ strategy.job-total }}, and the job name and test command state no literal shard count.

Requirement: The aggregate job joins every shard

The Tests & Coverage job SHALL keep its name, need test-shard, and download the coverage data of every shard with the pattern coverage-shard-*.

Scenario: The aggregate job covers eight artifacts

  • WHEN a test reads the test job of .github/workflows/ci.yml
  • THEN the job name is Tests & Coverage, it needs test-shard, and its download step uses pattern: coverage-shard-*.

Requirement: The documents state eight shards

The comment above test-shard in .github/workflows/ci.yml and the section The Test Shards of docs/SDLC.md SHALL state eight shards, and the comment SHALL name nine as the next entry.

Scenario: No document states four shards

  • WHEN a test reads the comment above test-shard in .github/workflows/ci.yml and the section The Test Shards of docs/SDLC.md
  • THEN each states eight shards, the comment names nine as the next entry, and neither states four shards nor a fifth shard.

Requirement: A shard selects only its own files

A run with 8 shards MUST give each shard a disjoint list of test files, and the union of the eight lists MUST be every test file of the repository.

Scenario: The eight shards are disjoint and complete

  • WHEN a test calls shard_test_files for each shard 1 to 8 with a total of 8
  • THEN the eight lists share no file and their union equals the list that shard_test_files gives for one shard of one.

Requirement: The plan-only run still passes

A plan-only pull request SHALL run tests/invariants in shard 1 only, and the test-shard and test jobs SHALL skip the full gate and the coverage steps.

Scenario: Shards 2 to 8 skip the gate

  • WHEN a test reads the test-shard and test jobs of .github/workflows/ci.yml for a plan-only pull request
  • THEN the step Plan-Only Invariant Tests runs only when matrix.shard == 1, the quality gate and the coverage upload are skipped, and the test job skips its coverage steps.

Existing Tool Considered

No alternatives check has run. pytest-split (https://github.com/jerry-git/pytest-split) is an open, maintained tool that splits a pytest suite into groups by recorded durations. It lacks the devops ci --only test --shard --shards contract, the per-shard coverage artifact, and the aggregate Tests & Coverage job. This change adds four matrix entries and builds no splitter. The cost to build, keep and fix a splitter is zero tokens and zero elapsed time, because src/devops_cli/core/test_selection.py already holds shard_test_files.

Key questions

  • How many shards does the matrix hold?: 8. Eight shards give about 147 s of pytest for each shard and about 234 s for the check with the measured balance of fix(ci): test shards take up to 11 minutes, over the budget #4250. Six shards give about 283 s, which leaves little margin for a suite that grows about 430 test functions a day. (best practice) [sources: .github/workflows/ci.yml, docs/SDLC.md, AGENTS.md]
    • Chosen: 8 shards. It brings the check to about 234 s and keeps a margin of about 66 s for suite growth.
    • Rejected: 6 shards. It gives about 283 s for the check, and the growth of the suite uses the margin in days.
    • Rejected: 12 shards. It adds about 420 s of runner setup for a gain that 8 shards already give.
  • Does the aggregate job need a change for a new shard count?: No. The Tests & Coverage job downloads every artifact that matches coverage-shard-* and needs test-shard, so it joins any count. It keeps its name, which ADR 0004 binds the ruleset to. [sources: .github/workflows/ci.yml, docs/adr/0004-ci-is-the-authoritative-gate.md]
  • Which documents state the shard count?: The comment above test-shard in .github/workflows/ci.yml and the section The Test Shards of docs/SDLC.md state four shards. AGENTS.md rule 8 requires the same pull request to correct them. [sources: .github/workflows/ci.yml, docs/SDLC.md, AGENTS.md]
  • How does each shard select its test files?: The test step runs uv run devops ci --check --no-cache --only test --shard "$SHARD" --shards "$SHARDS". SHARDS comes from strategy.job-total. shard_test_files splits the test modules by line count, so each shard collects only its own files. [sources: .github/workflows/ci.yml, src/devops_cli/core/test_selection.py, docs/SDLC.md]
  • Which tool splits the suite?: Keep shard_test_files; this item adds no splitter. pytest-split lacks the shard contract, the per-shard coverage artifact, and the aggregate job. fix(ci): test shards take up to 11 minutes, over the budget #4250 adds the measured balance. (best practice) [sources: .github/workflows/ci.yml, src/devops_cli/core/test_selection.py]
    • Chosen: Keep shard_test_files. The split already exists, writes the coverage data that the aggregate job joins, and fix(ci): test shards take up to 11 minutes, over the budget #4250 adds measured balance.
    • Rejected: Adopt pytest-split. It adds a dependency and a second split, and it writes no per-shard coverage artifact.
    • Rejected: Raise the xdist worker count on one runner. One runner holds the whole suite, which took 355 s to 528 s before the shards.
  • Does the plan-only path change with 8 shards?: No. Shard 1 runs tests/invariants. Shards 2 to 8 skip the quality gate and upload no data. The Tests & Coverage job skips its steps and reports success. [sources: .github/workflows/ci.yml, docs/SDLC.md]
  • Does the service-image-test job change?: No. It is not the required check and it already runs 6 shards without coverage collection. This item changes only the shard matrix of test-shard. [sources: .github/workflows/ci.yml]
  • Which item must land first?: fix(ci): test shards take up to 11 minutes, over the budget #4250, which balances the shards by measured time. The 234 s estimate for 8 shards assumes that balance. perf(test): evaluate hour-scale promtool tests every hour #4456 and fix(test): refine failure tests wait 60 s on real retries #4459 lower the total time further and are no dependency. (best practice) [sources: .github/workflows/ci.yml, src/devops_cli/core/test_selection.py, docs/SDLC.md]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#4250

Activity

  1. added
    source/agent
    type/infra
    scope/ci
    status/new
    value/high
    effort/low
    on Nov 11, 2026
  2. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/infra. The perf prefix of the title gives the type.
    • Scope: scope/ci. The (ci) scope of the title gives the scope.
    • Priority: P1-High. A required check averages 503 s against a 300 s project rule, blocking fast feedback on every PR.
    • Value: High. Every developer waits for the check on each push and pull request.
    • Effort: Low. The change is a matrix count in ci.yml plus coordination with #4250 and slow-test fixes.
    • Related: fix(ci): test shards take up to 11 minutes, over the budget #4250, which asks for a different change. Both target the same Tests & Coverage check exceeding 300 s, but the candidate adds shards while #4250 rebalances the existing four by measured time.
  3. added
    priority/p1-high
    on Nov 11, 2026
  4. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at 54743c4 while the items below stay open. The next refine round looks at the item again when they close, or when a person replies in a comment or edits the body.

    The next refine round also looks at the item again when a commit on the default branch changes one of these files: src/devops_cli/core/test_selection.py.

  5. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Impact evidence from the defect inventory of 2026-11-11 (check runs from 2026-10-27 to 2026-11-10):

    • 297 of the 311 failed push runs of CI Quality Gate on main failed only in the job Test Job Duration.
    • On 8 of the 12 days from 2026-10-31 to 2026-11-10 (2026-10-31 to 2026-11-04 and 2026-11-08 to 2026-11-10), no push run of CI Quality Gate on main passed.
    • In the same time, 7 push runs on main failed in Static Analysis and 8 failed in Tests & Coverage. These runs show the same red result as a run that failed only for the duration. So a real break of main is hard to see while this job fails.
  6. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at 453aed0 while the items below stay open. The next refine round looks at the item again when they close, or when a person replies in a comment or edits the body.

    The next refine round also looks at the item again when a commit on the default branch changes one of these files: src/devops_cli/core/test_selection.py.

  7. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Closed as not planned (CI audit of 2026-11-11)

    More shards add 2-4 jobs to each push, and the account runs at most 20 concurrent jobs (measured). That makes the queue longer.

    The math of this issue gives 196 s of pytest per shard with 6 shards. The registry token check (#4509) gives about 191 s per shard with 4 shards at a 35% cut (estimated), and it also cuts Service Image Tests and Changed-Test Independence. The job-time alarm (#4634) finds a new breach.

    File a new issue with new data if the mean without queue time stays over 300 s after #4509 and the shard balance (#4250).

  8. removed
    status/new
    on Nov 11, 2026
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/lowpriority/p1-highscope/cisource/agenttype/infravalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions