Skip to content

perf(ci): measure coverage and branch cost #2373

Closed

Description

@dan-petty

Problem or Motivation

The owner asked on 2026-10-27 (the decision comment on #2356) whether measuring branches is worth its job time, as #2163 proposes. No clean number exists for what coverage costs the test job.

What is known, from #2356 on 2026-10-27 (16 CPUs, Python 3.14):

  • The gate runs pytest --cov=src --cov-report=term-missing --cov-report=xml with the default sysmon core, with parallel = true: each of 16 workers writes a data file, and the controller combines them and prints a report for 560 files after the last test. That work is serial.
  • Line coverage is 93.01%. With branches, the figure is 90.75% (19,776 of 23,918 branches).
  • One run with the ctrace core, per-test contexts and branches took 568 s, against 287 s for the gate row. That run changes three things at once, so it does not give the cost of branches.
  • A try to compare the suite with and without coverage on the same day failed. The host had a load average of 10 to 39 from other runs. The suite without coverage took 3,540 s of CPU in that try, and a cost of coverage cannot be told from the noise of that load. Two of the coverage runs also measured nothing (0.00% coverage), so their numbers were dropped.

This issue is a sub-issue of #2356.

Proposed Solution & Architectural Design

Measure, on an idle host (uptime under 2 before each run), CPU time (user plus system) and wall time, three runs of each configuration, with the options of the gate:

Configuration Options
no coverage none
lines --cov=src --cov-report=term-missing --cov-report=xml
lines and branches the same, with --cov-branch
lines, ctrace core the same as lines, with COVERAGE_CORE=ctrace

Then time the serial end of the run on the data of the "lines" run: coverage combine, coverage report --show-missing and coverage xml, each alone.

Report the table in the pull request, with the median of each configuration, and say what the branch measurement of #2163 costs in seconds of CPU and of job time. Then, from the numbers:

Acceptance: the table exists with three runs for each configuration on an idle host, the cost of branches is stated in seconds, and a change, if one is made, lowers the CPU time of the "lines" configuration without lowering any threshold.

Target Subsystem

SDLC, Git & PR Governance

Existing Tool Considered

  • coverage.py and pytest-cov are in use. The core (sysmon, ctrace) and branch measurement are options of coverage.py.
  • coverage combine/report/xml commands give the time of the serial end. Nothing new is built.

Source: #2356

Alternatives check of 2026-11-07: not-applicable.
Class: perf, no search.
Tool: none found.

Proposed design

Problem statement

The owner needs a clean number for what coverage and branch measurement cost the CI test job. Earlier tries were confounded by host load or changed several variables at once. The idle-host gate of the first plan also stopped the work at a load average over 3.9. This issue measures four configurations of one shard in three interleaved rounds on four pinned CPUs, times the serial coverage commands on the shard data files, records the result in docs/TESTING.md, and states the cost of branch measurement in seconds of CPU and of job time.

Acceptance criteria

Requirement: Coverage cost section

docs/TESTING.md SHALL hold a ### Coverage cost subsection with a table of the four configurations.

Scenario: Report present in the testing guide

  • WHEN A test reads docs/TESTING.md at the head of the pull request.
  • THEN It finds a ### Coverage cost subsection, and its table holds one row for each of the four configurations.

Requirement: Gate configurations named

The report MUST name the four gate configurations and the exact pytest options and environment of each.

Scenario: Configuration rows

  • WHEN The test parses the configuration table.
  • THEN The table holds no coverage, --cov=src --cov-report=, that command with --cov-branch, and that command with COVERAGE_CORE=ctrace, each with its exact options and environment.

Requirement: Pinned CPUs and no idle-host gate

The method MUST pin each run to four CPUs with taskset -c 0-3 and MUST NOT stop or discard a run because of the host load average.

Scenario: A loaded host does not stop a run

  • WHEN The test reads the method section of docs/TESTING.md.
  • THEN It finds taskset -c 0-3, and it finds no load-average limit that stops or discards a run.

Requirement: Three interleaved rounds

The report MUST hold the three runs of each configuration from three interleaved rounds.

Scenario: Round and run records

  • WHEN The test parses the run table.
  • THEN Each run row states its round number from 1 to 3, its user plus system CPU time in seconds, its wall time in seconds, and the load average before the run.

Requirement: Median of each configuration

The report SHALL state the median CPU time and the median wall time of each of the four configurations.

Scenario: Median table

  • WHEN The test reads the median table.
  • THEN The table holds four rows, and each median is the middle value of the three runs of that configuration.

Requirement: Cost of branches in seconds

The report SHALL state the cost of branch measurement as the difference between the lines configuration and the lines and branches configuration.

Scenario: Branch cost statement

  • WHEN The test reads the branch cost statement.
  • THEN It gives the difference in CPU seconds and in wall seconds for one shard, names the two configurations, and gives the whole-job CPU figure as four times the per-shard difference.

Requirement: Serial coverage commands timed

The report SHALL give the wall time of coverage combine, coverage report --show-missing and coverage xml on the four shard data files.

Scenario: Serial end timings

  • WHEN The test reads the serial table.
  • THEN The table holds three rows, one for each command, each with its wall time in seconds, and the report states that coverage xml runs only on pull requests.

Requirement: Serial share statement

The report SHALL state the serial end in seconds, as a percentage of the measured lines job time, and whether it reaches 15 s.

Scenario: Share threshold

  • WHEN The test reads the serial share statement.
  • THEN It gives the percentage, states whether the serial end is 15 s or more, and states whether a follow-up issue is needed.

Requirement: No threshold or gate option lowered

The change MUST NOT lower fail_under, lower the diff-cover --fail-under, or change the coverage options of the test row.

Scenario: Floors and gate options unchanged

  • WHEN The test reads pyproject.toml, the Changed-Line Coverage step and the command of _resolve_pytest_cmd at the head of the pull request.
  • THEN fail_under is 85, the diff-cover step holds --fail-under 90, and the test row still holds --cov=src --cov-report=term-missing with one shard and --cov=src --cov-report= with several shards.

Requirement: Plan names a tracked file

The change folder MUST hold tasks.md with at least one task group whose Changes: line names docs/TESTING.md.

Scenario: Task group present

  • WHEN The test parses the tasks.md of the change folder.
  • THEN The file holds at least one task group and at least one task in that group, and the group's Changes: line names docs/TESTING.md and no path under openspec/changes/.

Existing Tool Considered

The alternatives check of 2026-11-07 recorded not-applicable for a perf item, so it made no search and names no tool. coverage.py 7.16.1 and pytest-cov 7.1.0 are in use and cover the coverage need. sysmon and ctrace are their cores, and --cov-branch and --cov-report= are their options. coverage combine, coverage report and coverage xml give the serial end. They lack a benchmark harness that runs four configurations in interleaved rounds. hyperfine is the open, maintained command benchmarker, but no lock file holds it, and it runs the repetitions of one command together, so it does not interleave the four configurations. The bash time keyword gives user, system and wall time, and statistics.median gives the median. The scratch runner is about 40 lines of shell and 10 lines of Python: about 12,000 tokens to build, about 1,500 tokens to keep, and about 45 minutes to write and fix. It stays under .data/agent/scratch/ and is not committed.

Key questions

  • Why did the feasibility check return this item to New?: The check of 2026-11-07 failed per Rule 2: the plan required an idle host with a load average under 2.0 before each run, and the host load average was over 3.9. The plan now pins four CPUs with taskset -c 0-3 and uses CPU time as the primary metric, which is the measurement rule that docs/TESTING.md records. No run waits for an idle host, and the load average is only recorded with each run. [sources: docs/TESTING.md]
  • What coverage options does the CI test job use?: The workflow runs four test shards, and each shard runs devops ci --only test --shard n --shards 4. That command resolves to uv run pytest --durations=10 --cov=src --cov-report= --cov-fail-under=0 --snapshot-warn-unused plus the shard's test files. The job Tests & Coverage then runs coverage combine .data/shards/*/.coverage and coverage report, which enforces fail_under = 85. The step Changed-Line Coverage runs coverage xml -q on pull requests and fails below 90% of the changed lines. The unsharded local row keeps --cov-report=term-missing. The default core is sysmon on Python 3.14, and parallel = true writes one data file per worker. [sources: .github/workflows/ci.yml, src/devops_cli/commands/ci.py, pyproject.toml, docs/TESTING.md]
  • What is the known cost of coverage?: On the pinned full run of perf(ci): the Tests & Coverage check averages 382 s on main, over the 5-minute limit #2699 with four CPUs, the suite took 269 s without coverage and 324 s with it, a cost of 55 s (+20%). The terminal report for 560 files took about 9 s. On one combined data file, coverage report -m took 30.8, 33.9 and 26.8 s, and coverage xml took 24.7, 25.9 and 21.1 s, at a load of 13 to 29. The cost of branches alone is not established: the 568 s run changed the core, the contexts and the branches together. [sources: openspec/changes/archive/2026-10-30-2699-test-check-time/baseline.md, openspec/changes/archive/2026-10-30-2699-test-check-time/design.md, openspec/changes/archive/2026-10-29-1743-coverage-xml-in-ci/proposal.md, openspec/changes/archive/2026-10-27-2356-coverage-floor-and-test-cost/design.md]
  • How does the measurement tolerate a loaded host?: Pin each run to four CPUs with taskset -c 0-3 and run -n 4, the four workers of the CI runner. Take CPU time (user plus system) as the primary metric, because the wall time of a shared host varies by more than the change. Run the four configurations in three interleaved rounds. Record the 1-minute load average before each run, and report the median. Do not stop or discard a run for the load average. Drop a run only when its coverage is 0.00% or its pass and fail counts differ from the first round. (best practice) [sources: docs/TESTING.md, openspec/changes/archive/2026-10-30-2699-test-check-time/baseline.md]
    • Chosen: Pinned four CPUs with CPU time and three interleaved rounds. docs/TESTING.md records this measurement rule: use CPU time on pinned CPUs, because the wall time of a shared host varies by more than the change. Interleaving puts host drift on all four configurations alike.
    • Rejected: Idle-host gate with a load average under 2. The feasibility check of 2026-11-07 found a load average over 3.9 and stopped the work. The shared host does not reach load 2, so the gate gives no number.
    • Rejected: One run of each configuration. The 2026-10-27 try showed that host noise exceeds the effect, and two runs measured nothing.
    • Rejected: A new CI workflow on a dedicated runner. It adds a workflow and sixteen shard runs of runner time, and the runner size is a repository setting that only a person changes.
  • Which configurations does the measurement compare?: Compare four configurations of one shard: no coverage, lines, lines and branches, and lines with the ctrace core. Keep the worker count, the worksteal distribution and --durations=10 the same in all four, because addopts and the gate command set them. (best practice) [sources: pyproject.toml, src/devops_cli/commands/ci.py, openspec/changes/archive/2026-10-30-2699-test-check-time/design.md]
    • Chosen: Four configurations: none, lines, lines and branches, lines with ctrace. Each one answers a question the issue asks: what coverage costs, what branches add, and what the core adds. The worker count stays the same, so the runs differ in one option.
    • Rejected: Add the pytrace core. The archived design of perf(ci): the Tests & Coverage check averages 382 s on main, over the 5-minute limit #2699 already shows it at 136 s against 44 s for sysmon. It is slower and no decision waits on its cost.
    • Rejected: Add per-test contexts. Contexts are a third variable, and the 568 s run of 2026-10-27 shows that changing several variables at once gives no cost for any one.
  • Which metric decides the cost of branches?: CPU time (user plus system) decides the cost of the work. The report also gives the wall time of the same shard as the job-time figure, with the load average before each run. The job-time cost is the median wall-time difference of the paired lines and branches runs on one shard of four, because the gate runs four shards in parallel and the job time is the slowest shard plus the serial end. (best practice) [sources: docs/TESTING.md, openspec/changes/archive/2026-10-30-2699-test-check-time/design.md, openspec/changes/archive/2026-10-27-2356-coverage-floor-and-test-cost/design.md]
    • Chosen: CPU time per shard, with the wall time of the same shard as the job-time figure. The job pays one shard's wall time, and CPU time stays stable when the host is loaded. The same tests took 279 s and 425 s in perf(ci): the Tests & Coverage check averages 382 s on main, over the 5-minute limit #2699, so wall time alone cannot decide.
    • Rejected: Wall time of a full-suite run. The gate runs four shards in parallel, so a full-suite run is about four times the job's test time and overstates the job-time cost.
    • Rejected: Sum of test durations from --durations. It leaves out the start of the workers and the serial end, which are part of the cost.
  • Where does the measurement report live?: The report lives in a ### Coverage cost subsection of docs/TESTING.md, after ### Coverage. A task group can change a tracked path such as docs/TESTING.md. The table also goes into a comment on the pull request, and the branch cost goes into a comment on ci(coverage): Enable branch coverage and upload coverage xml as artifact #2163. The pull request body only links the document, because CONTRIBUTING.md keeps measurements out of the body. (best practice) [sources: docs/TESTING.md, CONTRIBUTING.md, src/devops_cli/roadmap/stage/stage_change.py, src/devops_cli/roadmap/stage/stage_paths.py, docs/adr/0010-openspec-is-the-spec-and-change-proposal-layer.md]
    • Chosen: A ### Coverage cost subsection of docs/TESTING.md. It is a tracked path that a task group can change, and it sits next to the run-time method and the coverage rules that it measures.
    • Rejected: A measurement.md in the change folder. The stage validator refuses every path under openspec/changes/, and the stage job writes only the plan files.
    • Rejected: The pull request body only. CONTRIBUTING.md keeps measurements out of the body, and a body is no repository file that a task group can change.
    • Rejected: The scratch directory .data/agent/scratch/. That path is not committed, so the plan would have no tracked path and the schema rejects the group.
  • Does this pull request change a coverage option or a threshold?: No. Each shard already runs --cov-report= and prints no report, and the job combines the data and runs coverage report. coverage report enforces fail_under, and coverage xml feeds diff-cover on pull requests, so neither serial command can be dropped. A measured saving becomes a follow-up issue with its own spec delta. This pull request changes no option and no threshold. (best practice) [sources: .github/workflows/ci.yml, src/devops_cli/commands/ci.py, pyproject.toml, docs/TESTING.md, openspec/changes/archive/2026-10-29-1743-coverage-xml-in-ci/proposal.md]
    • Chosen: No option change in this measurement pull request. The per-shard report is already off, and coverage report and coverage xml enforce the floor and the changed-line check. A change to show_missing alters an observable option and needs a MODIFIED ci-coverage-reports requirement and new tests.
    • Rejected: Set show_missing = false in this pull request. perf(ci): the local gate writes coverage XML only where CI reads it, and the cleanup keeps the combined data #1743 kept the term report for the missing-lines list. The change needs its own spec delta and tests, so it is a follow-up issue.
    • Rejected: Always drop --cov-report=term-missing. The shard row already prints no report, so this changes nothing, and the unsharded local row still needs the missing-lines list.
  • Does this issue turn on branch measurement in the gate?: No. The report states the cost of branches in seconds, and a comment on ci(coverage): Enable branch coverage and upload coverage xml as artifact #2163 gives the number to the owner. The owner sets the thresholds and decides on branch measurement. (best practice) [sources: openspec/changes/archive/2026-10-27-2356-coverage-floor-and-test-cost/design.md]
  • What counts as a large share of the run?: 15 s, which is 5% of the 300 s job budget. The report states the serial end in seconds and as a percentage of the measured lines job time. coverage combine plus coverage report are the steps that a push pays. coverage xml runs only on pull requests, so the report states it beside the figure and not in it. A share of 15 s or more states that a follow-up issue tests a cheaper report option. (best practice) [sources: AGENTS.md, docs/TESTING.md, .github/workflows/ci.yml]
    • Chosen: 15 s, 5% of the 300 s budget. AGENTS.md makes a check over 5 minutes a P0 bug, and 15 s is the same share of that budget. A fixed number does not move with the host.
    • Rejected: 5% of the measured shard wall time. A shard is about a quarter of the suite, so 5% of it is about 4 s and would hide a 15 s serial end that is a tenth of the budget.
    • Rejected: 10% of the budget. It would hide a serial end of 15 to 30 s that is a tenth of the budget on a slow runner.
    • Rejected: No threshold, state the seconds only. The issue asks for a decision on whether the report or combine step is a large share, and a number makes that decision repeatable.
  • Does the change need a spec delta?: No. The change edits docs/TESTING.md and changes no command, option, message, manifest or service behavior. The change folder sets skip_specs: true, which ADR 0010 allows for a change that alters nothing a consumer observes. (best practice) [sources: docs/adr/0010-openspec-is-the-spec-and-change-proposal-layer.md, openspec/changes/2373-measure-what-coverage-and-branch-measurement/.openspec.yaml]
    • Chosen: Set skip_specs: true. The change adds a document and changes no observable behavior, which ADR 0010 covers with skip_specs: true.
    • Rejected: Add a spec delta for the measurement record. A measurement document is not behavior that a consumer observes, and no product test can assert the scenarios of the benchmark.
  • How does the change folder satisfy the StageGroup schema?: The plan has at least one group, and each group changes at least one repository path. No group changes or creates a path under openspec/changes/. tasks.md is rendered from the groups, so it holds a group and its tasks and is never empty. The group's Changes: line is docs/TESTING.md. [sources: src/devops_cli/roadmap/stage/stage_change.py, src/devops_cli/roadmap/stage/stage_paths.py]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/infra
    on Oct 27, 2026
  2. dan-petty commented on Oct 27, 2026

    @dan-petty
    OwnerAuthor

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

    • Type: type/infra. The title uses the perf(ci) prefix, which maps to type/infra.
    • Priority: P2-Medium. It is needed to decide whether #2163's branch measurement is worth its job time, but it does not block other work.
    • Value: Medium. It gives the owner a number to decide on branch coverage, but it does not change user-facing behaviour.
    • Effort: Medium. It requires three timed runs per configuration on an idle host plus separate timing of serial coverage commands, but no new tool is built.
    • Related: ci(coverage): Enable branch coverage and upload coverage xml as artifact #2163, which asks for a different change. Both concern branch coverage in the CI test job; #2163 enables branch measurement, this candidate measures the seconds it costs.
  3. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at bb46660 (see proposed design in issue body).

  4. added
    priority/p2-medium
    status/ready
    value/medium
    effort/medium
    scope/ci
    on Oct 28, 2026
  5. devops-cli-service commented on Nov 1, 2026

    @devops-cli-service
    Contributor

    Staged: branch perf/2373-measure-what-coverage-and-branch-measurement, draft pull request #2987. The pull request plans the item and closes no issue.

    The task groups, with the tokens of the inputs of each step, for a budget of 40000 tokens:

    1. Run four coverage configurations and record medians: 3979 tokens
    2. Time the serial coverage commands: 4020 tokens
    3. State the cost and apply the conditional change: 3983 tokens

    These paths of the plan are no file on the default branch, and no group creates them: openspec/changes/2373-coverage-cost-measurement/benchmark-results.md, openspec/changes/2373-coverage-cost-measurement/design.md. A person checks that the plan names them right.

  6. 29 remaining items

  7. added
    status/new
    on Nov 7, 2026
  8. devops-cli-service commented on Nov 7, 2026

    @devops-cli-service
    Contributor

    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-07. A person decides what this means for the item. The check changes no label and closes no issue.

  9. added
    status/ready
    and removed
    status/new
    on Nov 8, 2026
  10. devops-cli-service commented on Nov 8, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at e74866d (see proposed design in issue body).

  11. added
    status/planned
    and removed
    status/ready
    on Nov 8, 2026
  12. added
    status/in-progress
    status/in-review
    and removed
    status/planned
    status/in-progress
    on Nov 8, 2026
  13. removed
    status/in-review
    on Nov 8, 2026
  14. devops-cli-service commented on Nov 8, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-08 16:19 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/infravalue/medium

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions