Skip to content

chore(ci): the local test row takes over 5 minutes #4405

Done

Description

@dan-petty

Problem

The local full check devops ci is slow under load. Measured on 2026-11-10 with several agents on one host (load about 28): the test row took 11 min 39 s, 16 min, 19 min and 23 min 37 s; the mypy step alone took 5 min 20 s; a run waited more than one hour on the lock .data/agent/ci.lock behind others. The project rule says a build or check that averages more than 5 minutes is a P0 bug (AGENTS.md rule 5).

What to find out

  1. The time of each step on an idle host (the test row, mypy, ruff, docs, openspec), for three runs.
  2. The share of the slowdown that comes from load (many agents run pytest with xdist at once) and the share that is the cost of the checks.
  3. The slowest test files and test setup costs (pytest --durations=50), and whether a few modules cost most of the time.
  4. The GitHub runner times of the same checks (they are the ones that gate a merge).
  5. Whether the lock policy should change: a limit on agents running the full check, a shared result cache keyed by tree hash, or scoped checks (devops ci for changed paths).

Done when

A table of times (idle and loaded), the top slow tests, and a ranked list of fixes are in this issue, with a fix issue for each. If an idle run exceeds 5 minutes, this issue becomes P0.

Related: the CI speed rule, tests/commands/test_scan.py failures (#4288, #4321) that add time.

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

Proposed design

Problem statement

The local full check devops ci and the required check Tests & Coverage take more than 5 minutes. AGENTS.md rule 5 calls a check that averages over 5 minutes and 1 minute of tolerance a P0 bug. The issue records the times, the slowest tests and a ranked list of fixes, each with its own issue. The gate names an over-budget check only for the test step, and it prints that line as plain text that the check page does not show. This change makes the gate name each check over 300 s, print the line as a ::warning:: workflow command, and list the 50 slowest tests.

Acceptance criteria

Requirement: Each check over the budget is named

The gate SHALL print one over-budget finding that names each check whose duration is more than 300 s and states the 300 s budget.

Scenario: A slow typecheck step is named

  • WHEN the typecheck step takes 320 s and the lint step takes 10 s in one run
  • THEN the finding names the typecheck step and the 300 s budget, and it does not name the lint step

Requirement: An over-budget check shows on the check page

The gate MUST print the over-budget finding as a GitHub Actions ::warning:: workflow command.

Scenario: A shard over the budget shows a warning

  • WHEN a test shard takes 393 s and the gate prints its over-budget finding
  • THEN the output line starts with ::warning:: and holds the check name, its duration and the 300 s budget

Requirement: The test row asks for the 50 slowest tests

The test row SHALL pass --durations=50 to pytest.

Scenario: The pytest arguments hold fifty durations

  • WHEN the test row builds its pytest arguments
  • THEN the arguments hold --durations=50 and hold no --durations=10

Requirement: A run inside the budget prints no finding

The gate MUST print no over-budget finding when every check takes 300 s or less.

Scenario: A run at the budget is quiet

  • WHEN every check takes 300 s or less
  • THEN the output holds no over-budget finding

Existing Tool Considered

The alternatives check of 2026-11-11 in the issue body records not-applicable (class chore, no search) and names no tool. The change uses two existing tools: pytest's built-in --durations=50 gives the slowest tests, and the documented GitHub Actions ::warning:: workflow command puts the over-budget line on the check page. The change extends the summary that devops ci already prints and builds no timing harness. A custom harness would cost about 40k tokens to build, 10k tokens a month to keep and fix, and 3 days.

Key questions

  • Which parts of the check report already exist in devops ci?: devops ci prints one summary row for each check with its duration. The test row parses pytest's durations report through slowest_tests in src/devops_cli/ci/diagnostics.py, and the count of entries is a constant in src/devops_cli/config/constants.py. One plain over-budget line exists for the test step at src/devops_cli/commands/ci.py:1385. The change extends these three points and adds no second timing script. [sources: src/devops_cli/commands/ci.py:1385, src/devops_cli/commands/ci.py, src/devops_cli/ci/diagnostics.py, src/devops_cli/config/constants.py]
  • Does the gate report a slow typecheck step today?: No. The over-budget line covers the test step only. On 2026-11-12 a devops ci typecheck run under a load average of 44 stopped with mypy ... --strict src timed out after 1800.0 seconds, and the gate named no over-budget step. [sources: src/devops_cli/commands/ci.py:1385, src/devops_cli/ci/typecheck.py]
  • How does an over-budget check reach the pull request check page?: Print the over-budget line as a ::warning:: workflow command. The runner turns it into a warning annotation on the check page, and no workflow file changes. (best practice) [sources: src/devops_cli/commands/ci.py:1385, .github/workflows/ci.yml]
    • Chosen: Print a ::warning:: workflow command. The runner shows the line as a warning annotation, and the check names and the budget stay in one place.
    • Rejected: Add an annotation step to ci.yml. It copies the check names and the 300 s budget into the workflow, so the two lists drift.
    • Rejected: Keep the plain line. The audit found that nobody sees the line on the check page, so an over-budget run stays silent.
  • How many slowest tests does the test row ask for?: Raise the count from 10 to 50. The issue asks for pytest --durations=50. The loaded run of 2026-11-11 needed 60 entries to show that 50 of the slowest tests are in tests/roadmap/, which is the largest block of the loaded test time. (best practice) [sources: src/devops_cli/config/constants.py, src/devops_cli/commands/ci.py, openspec/specs/ci-test-shards/spec.md]
    • Chosen: Raise the count to 50. The issue names --durations=50, and 10 entries hid the roadmap tests that hold most of the loaded test time.
    • Rejected: Keep the count at 10. The ten entries of the loaded run missed the slowest block, so the report could not rank the fixes.
  • Should the gate's lock policy change to a limit, a shared result cache or scoped checks?: Keep the limit on concurrent full checks, ci.gate_slots. A direct uv run pytest that starts workers from addopts now takes a slot too. Do not add a shared result cache: ADR 0014 records that the cache helped in only 1 of 186 passing runs. Do not gate on scoped checks: ADR 0014 rejects the changed tests as the gate, and ADR 0004 keeps CI authoritative. (best practice) [sources: CONTRIBUTING.md:108, src/devops_cli/ci/gate_slots.py, docs/adr/0014-required-checks-gate-the-merge-and-the-pre-push-hook-runs-the-fast-static-checks.md, docs/adr/0004-ci-is-the-authoritative-gate.md]
    • Chosen: Keep the ci.gate_slots limit. The project already implements it, records the wait, and tunes the slot count from that metric.
    • Rejected: Add a shared result cache keyed by tree hash. A cached verdict can pass a tree whose checks never ran, and ADR 0014 measured almost no reuse.
    • Rejected: Gate on scoped checks for the changed paths. ADR 0014 rejects the changed tests as the gate, and a scoped run can miss a regression outside the changed paths.
    • Rejected: Raise the number of slots. Two gates side by side ran past the 300 s test budget and used most of the 2048 process ids of the container.
  • Is the required check over the 5 minute budget?: Yes. The issue records a mean of 503 s (max 630 s) for Tests & Coverage over the last 20 push runs on main, and about 500 s for the local test row on an idle host at 22,497 items. Both exceed the 300 s budget plus the 60 s tolerance of AGENTS.md rule 5, so the issue is a P0 bug. [sources: AGENTS.md, openspec/specs/ci-job-time/spec.md, docs/adr/0014-required-checks-gate-the-merge-and-the-pre-push-hook-runs-the-fast-static-checks.md, src/devops_cli/config/defaults.py]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Moved to new items

#4427

Activity

  1. added
    source/agent
    type/chore
    scope/ci
    status/new
    value/medium
    effort/medium
    on Nov 10, 2026
  2. dan-petty commented on Nov 10, 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/chore. The chore prefix of the title gives the type.
    • Scope: scope/ci. The (ci) scope of the title gives the scope.
    • Priority: P2-Medium. The local check is slow under load but the project still functions; it blocks developer speed, not end users.
    • Value: Medium. Faster local checks reduce developer wait time and improve iteration speed for the team.
    • Effort: Medium. Requires three timed runs, xdist analysis, pytest durations, and a written report with a ranked fix list.
    • Related: fix(ci): devops ci quality gate finishes within five minutes #748, which asks for a different change. Both concern 'devops ci' exceeding the 5-minute budget, but the candidate delivers a diagnostic report with ranked fixes while #748 delivers the speed fix itself.
  3. added
    priority/p2-medium
    on Nov 10, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 10, 2026
  5. devops-cli-service commented on Nov 10, 2026

    @devops-cli-service
    Contributor

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

    Moved to new items: #4427.

  6. added
    owner/agent
    on Nov 11, 2026
  7. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Measurement of the check times (2026-11-11)

    Result: the required check Tests & Coverage takes more than 5 minutes on the GitHub runners, where no host load applies: 503 s on average over the last 20 runs on main. The estimate for the local test row on an idle host is also more than 5 minutes (about 500 s). By AGENTS.md rule 5, this is a P0 bug.

    1. Required checks on the GitHub runners

    Sources: the Actions API for ci.yml (141 successful runs from 2026-10-28 to 2026-11-11, 10 a day), and uv run devops ci job-time (the last 20 push runs on main). The test check is timed from the first shard start to the end of the join job.

    Check Runs Mean Median p90 Max
    Tests & Coverage, last 20 runs on main (devops ci job-time exits 1) 20 503 s 630 s
    Tests & Coverage, 2026-11-04 to 06 21 286 s 294 s
    Tests & Coverage, 2026-11-07 to 11 41 452 s 448 s
    Static Analysis, last 20 runs on main (devops ci job-time) 20 147 s 167 s
    Static Analysis, 2026-10-28 to 11-06 100 107 s 105 s 147 s 167 s
    Static Analysis, 2026-11-07 to 11 41 147 s 150 s 165 s 210 s
    Semantic PR title not measured (pr-title.yml was not in the sample)

    The parts of Tests & Coverage (means):

    Part 11-04 to 06 11-07 to 11
    Test step of one shard 159 s 254 s
    Setup of one shard job (checkout 4 s, uv 18 s, promtool 3 s, other) 33 s 35 s
    Spread between the slowest and the fastest shard 80 s 158 s
    Join job (combine, changed-line coverage) 47 s 52 s
    Wait between the last shard and the join job 5 s 5 s

    The mean test step of a shard grew by 60% from the first period to the second. The suite grew from 11,651 test functions in 782 files (2026-11-04) to 14,695 in 1,105 files (2026-11-11): +26%, about 430 functions a day. Run 42938256840 on main had 22,497 items in 4 shards, with 200.8 s, 299.6 s, 306.4 s and 368.9 s of pytest. With a perfect balance this gives 294 s for each shard and about 381 s for the check. Thus a balance alone (#4250) cannot bring the check under 300 s.

    2. The local check (devcontainer, 16 CPUs, WSL2)

    No idle run was possible: other agents ran pytest during the whole window. The idle column holds the records of src/devops_cli/config/defaults.py and a linear estimate.

    Step Idle 45 local gate logs of the last 5 days: median (min to max) Full gate today, load 40 to 55 Runner
    test 247 s for 11,189 items (2026-10-27); about 500 s for 22,497 items (estimate) 756 s (296 to 1,811 s) stopped at its 1,800 s timeout 4 shards, 201 to 369 s each
    typecheck (mypy) 177 s (5 to 596 s) 580 s every static row together: 84 to 90 s
    security (bandit) 21 s alone (record, a smaller suite) 278 s (159 to 1,575 s) 750 s
    test-tree 129 s (85 to 402 s) 221 s
    openspec 96 s (62 to 229 s) 147 s
    startup-imports 95 s (63 to 246 s) 154 s
    docs 40 s (23 to 142 s) 76 s
    lint 38 s (32 to 93 s) 46 s

    Today's full gate: uv run devops ci --check --no-cache at origin/main 776054b, from 02:22 UTC, the only holder of the gate slot. Then uv run pytest -p no:cacheprovider --durations=60 with no coverage, at a load of 35 to 50: 22,504 passed in 2,006 s. One worker hung for more than 16 minutes in decide_all (#4513), and pytest-timeout did not stop it.

    3. Where the time goes

    • The size of the suite. 22,497 items now, 11,189 on 2026-10-27. This is the largest cause, on the runner and on the host.
    • The roadmap tests. 50 of the 60 slowest tests of today's local run are in tests/roadmap/ (1,700 s of 2,296 s), mostly implement/ and stage/, at 25 to 53 s each under load and 4 to 11 s on the runner. No single test is the cause; this is the next area to profile.
    • Collection. Each xdist worker collects the whole suite (22,533 items) before it runs a test, so 16 local workers pay the collection 16 times in CPU.
    • Real waits: 105 s for each run, each in one worker. test_bootstrap_k8s_warns_when_docker_daemon_down waits 45 s (_wait_for_docker_daemon polls with time.sleep(2) and does not use the clock seam). Three tests of tests/roadmap/refine/test_roadmap_refine_failure_class.py wait 30 s, 15 s and 15 s, because a module fixture clock shadows the shared ClockFake.
    • One promtool case. [roadmap-service-activity] made 9,000 to 12,000 evaluation rounds: 63.8 s on the runner, 214 s today, a median of 147 s in 24 local logs. With --dist worksteal, the local row cannot end before its slowest test.
    • Real subprocesses. test_local_ai_commands_run_cleanly[ai ast graph]: 35.7 s on the runner, 115 s today.
    • The scan tests. tests/commands/test_scan.py runs on fakes now (fix(ci): scan tests reach the host scanner tools #4321, merged in test(scan): fake the scanners in the scan command tests #4440; test(scan): scan command tests reach real trivy and semgrep #4288 closed). It is not in the 60 slowest tests.

    4. The effect of the host load

    • The load average rose from 8 to 41 in the first minute of the gate. The gate runs about 25 checks at once and its test row starts 16 workers; other agents also ran tests.
    • A snapshot by the working directory of each process: the gate's test row 615% CPU (17 processes), a direct pytest over a list of test files in another worktree 458% (17 processes), other scripts about 250%. The 16 workers of the gate got 25% to 43% of a CPU each.
    • A direct uv run pytest takes no gate slot, so the slot limits only devops ci runs.
    • On the runner every static row together takes 84 to 90 s; on the loaded host mypy took 9 min 40 s and bandit 12 min 30 s.

    So the 11 to 30 minutes on the host are mostly load and queue. But the test row alone is over 300 s on the runner, and by the estimate on an idle host too.

    5. Ranked fixes

    Rank Fix Saves (estimate) Issue
    1 Split the test check into more shards (6 to 8) 100 to 150 s of the check #4473
    2 Balance the shards by measured time most of the spread of 158 s #4250
    3 Stop the hang of decide_all a hung worker until a job timeout #4513
    4 Evaluate the hour-scale promtool cases once each hour 64 s of one runner worker; the floor of the local row #4456, merged in #4462
    5 Use the shared ClockFake in the refine failure-class tests 60 s of real waits #4459
    6 Wait for the Docker daemon through the clock seam 45 s of real waits #4466
    7 Let a direct pytest run take part in the gate slot rule the load of a second run beside the gate #4525

    Two more points, with no issue:

    • Agents can run uv run devops ci test <paths> for the tests that they change, and let the required checks run the full suite, as docs/SDLC.md says. The full local gate is optional (ADR 0014).
    • The design in the body of this issue (a P0 mark for every check over 300 s, and 50 durations) is still to build. It reports the problem but does not make a check faster.
  8. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Alternatives check: not-applicable

    Class: chore. 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.

  9. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Scope from the CI audit (2026-11-11)

    Add one fact and one change to this issue.

    • Each CI shard prints '! Tests took 6m 33s, over the 5m budget' (src/devops_cli/commands/ci.py:1385) as a plain line with no annotation, and the shard passes. Nobody sees it on the check page.
    • Change: print the line as a ::warning:: workflow command, so that the PR check page shows it. The design of this issue already names each check that is over 300 s.
    • Added acceptance: a shard that takes more than 300 s shows a warning on the check page.

    The audit filed a fix issue for each measured cause of the slow test row, in plan order:

    1. perf(test): stage gate tests parse every test file per call #4509: parse only the test modules that name the registry
    2. perf(ci): run only the required checks on the release PR #4637: run only the required checks on the release PR
    3. fix(ci): run the job-time alarm on the schedule only #4634: run the job-time alarm on the schedule only
    4. refactor(pr): devops pr update acts only on a failed check #4674 and feat(git): refuse a push that does not hold origin/main #4670: stop pure rebases (folded into the iteration-lane push items)
    5. perf(ci): move the four path checks into filtered workflows #4653: move the four path checks into filtered workflows
    6. perf(ci): build the Service image once for its test shards #4642: build the Service image once for its test shards
    7. perf(ci): stop the cache export of pull request image builds #4646: stop the cache export of PR image builds
    8. perf(ci): cancel superseded CodeQL runs and idle triggers #4651: cancel superseded CodeQL runs and idle triggers
    9. perf(ai): compile one call pattern per symbol in ast graph #4662: compile one call pattern per symbol in ast graph
    10. fix(test): bootstrap-k8s test waits 45 s for the Docker poll #4466: bootstrap-k8s test busy-spin
    11. fix(test): refine failure tests wait 60 s on real retries #4459: refine failure tests real retries
    12. fix(github): pace mutations through the clock seam #4666: pace mutations through the clock seam
    13. chore(ci): keep the per-test times and skip reasons of CI #4673: keep the per-test times and skip reasons of CI
    14. fix(ci): test shards take up to 11 minutes, over the budget #4250: balance the test shards by measured time
    15. fix(ci): set job timeouts from the measured run times #4677: set job timeouts from the measured run times
    16. fix(ci): give the test row and the index build own timeouts #4683: give the test row and the index build own timeouts
    17. test(roadmap): run the limit and monitor tests with small limits #4688: run the limit and monitor tests with small limits
    18. fix(roadmap): judge the registry of the checked-out tree #4695: judge the registry of the checked-out tree
    19. perf(tests): parse the source trees once per worker #4700: parse the source trees once per worker
    20. perf(tests): remove fixed waste in six slow tests #4706: remove fixed waste in six slow tests
    21. fix(tests): refuse real sleeps in tests #4669: refuse real sleeps in tests
    22. fix(tests): close the UDP, DNS and git gaps of the network floor #4711: close the UDP, DNS and git gaps of the network floor
    23. fix(tests): repair the bwrap contract suite and gate it #4715: repair the bwrap contract suite and gate it
    24. test(roadmap): run each implement scenario once with subtests #4722: run each implement scenario once with subtests
    25. perf(ci): skip bytecode compile and unused caches in test jobs #4727: skip bytecode compile and unused caches in test jobs
    26. perf(ci): build the Runner and MCP images in one bake job #4649: build the Runner and MCP images in one bake job
    27. perf(k8s): put the dependencies in their own image layers #4550: sync dependencies before the source copy (folded)
    28. test(dry-run): drop repeated guards and twin cases #4731: drop repeated guards and twin cases
    29. refactor: Delete unused functions after manual caller check #1910: delete src symbols that only tests call
    30. chore(ci): the local test row takes over 5 minutes #4405: show the over-budget shard line as a warning (folded)
    31. perf(ci): direct pytest runs ignore the gate slot #4525: direct pytest runs take the gate slot
    32. perf(ci): run the in-image suite nightly and on image PRs #4644: run the in-image suite nightly and on image PRs (owner decision O1)
    33. perf(ci): build the devcontainer only on its own inputs #4658: build the devcontainer only on its own inputs (owner decision O2)
    34. perf(ci): test each merge once, on the main push #4639: test each merge once, on the main push (owner decision O3)
    35. ci(pages): build the docs site from a workflow with a docs filter #4656: build the docs site from a workflow with a docs filter (owner decision O5)
  10. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor

    A new measurement on 2026-11-12: uv run devops ci typecheck in a new worktree stopped at its own limit. The output was mypy ... --strict src timed out after 1800.0 seconds (elapsed 30 min 47 s). The load average was about 44 on 16 CPUs, with several agents on one host. mypy --strict on 2 changed modules finished with no issue in the same worktree.

  11. devops-cli-service commented on Nov 26, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See Moved to new items in the section Proposed design of the body.

  12. added
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 28, 2026
  13. removed
    status/in-review
    owner/agent
    on Nov 28, 2026
  14. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-28 17:56 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/chorevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions