Repository navigation
Closed
Labels
priority/p2-mediumPriority P2: standard workscope/ciGitHub Actions workflows, pre-commit hooks, CI gates, and runnerstype/testType test: a new or changed test
Milestone
Description
Problem
Every pytest-xdist worker imports and collects the whole suite before it runs its first test. The gate runs pytest with -n logical from pyproject.toml:126 (16 workers in the devcontainer), plus coverage [code: src/devops_cli/commands/ci.py:385-395]. The figures below were measured on 2026-10-07 at 36cfbbb, in the devcontainer and without coverage. Other work was running on the machine, so they are given as ranges over several runs.
- About a third of the run is start-up. With every test deselected (
uv run pytest -q -p no:cacheprovider -k zz_no_such_test_zz), 16 workers take 35-46 s and one process (-n0) takes 18-20 s. The full run takes 122-130 s wall for 9,278 passed, 23 skipped and 8 xfailed. Its summed test time is 997-1,016 s, about 62-64 s if spread evenly over 16 workers [measured]. - Start-up grows with the worker count. With every test deselected, 4 workers take 23 s, 8 take 26 s and 16 take 35-46 s [measured]. Each worker repeats the single-process work while the others compete for the same CPUs [inference]. Fewer workers is no free win: halving them saves about 11 s of start-up but doubles the evenly spread test time, from about 62 s to about 125 s [inference].
- Collection is mostly import. One process collects 9,309 tests in 11-12 s (16 s wall).
python -X importtimeover that collection records about 7.2 s of import: devops_cli 1.5 s, openai 0.9, anthropic 0.6, google 0.5, qdrant_client 0.5, textual 0.5, aiolimiter 0.3 and mcp_types 0.3 [measured]. - The model SDKs arrive through devops-cli modules, at module level. In that collection, the first import of
devops_cli.ai.agentstakes 4.2 s cumulative, of which openai, anthropic, google and mcp_types are 2.3 s [measured]. 32 modules undersrc/devops_cliimportpydantic_aiat module level [code:grep -rlE '^(import|from) pydantic_ai(\.| |$)' src/devops_cli]. - Deferring an import saves nothing by itself. Under the default
--dist load, most workers run tests from most packages. An import moved from collection to first use therefore still runs in most workers [inference]. A real saving has to show in the full run's wall time. - Not this item:
- Two session fixtures import the provider stack and the Qdrant client in every worker (
tests/conftest.py:59,:480). In a one-file run, the first test's setup, which runs the session fixtures, takes 4.5-9.4 s [measured]. test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310 deletes the Qdrant guard. The mock-provider registration leaves the root conftest in test(cli): every test file sits in the directory mirroring the package it tests or in tests/invariants/, and the root conftest holds only the hermetic floor #1313's split and is deleted with the legacy providers in test(ai): the remaining ai modules are tested through their public interfaces on edge fakes, and the legacy provider layer leaves src #1331. - Setup sums to 135-137 s across the suite, about 15 ms per test [measured:
--durations=0], and every test runs the root conftest's autouse fixtures (17 at 5c45b1e). That cost belongs to test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310's floor.
- Two session fixtures import the provider stack and the Qdrant client in every worker (
Acceptance criteria
- (person-run) Baseline first. At the item's base, on an otherwise idle devcontainer, the task file records:
- the median of three runs of
uv run pytest -q -p no:cacheprovider -k zz_no_such_test_zz(start-up and collection only); - the median of three runs of
uv run pytest -q -p no:cacheprovider(the full run); - the five largest import costs from
uv run python -X importtime -m pytest --collect-only -q -s -n0 -p no:cacheprovider.
- the median of three runs of
- (person-run) After the change, the start-up median is at least 15% below its baseline. The new figures are recorded in the task file.
- (person-run) The full-run median falls by at least half as many seconds as the start-up median did, so the saving is not moved into the tests.
- No test is lost. The full run collects as many tests as at the base, with the same passed, skipped and xfailed counts.
- The gate still measures coverage over
srcand still meetsfail_under = 90. -
changelog.d/<n>.mdrecords the change;CHANGELOG.mdanddocs/ROADMAP.mdare not edited. -
uv run devops cipasses.
Key questions
- Which lever? (proposed) Measure first, then try the cheapest:
- SDK imports on first use in the src modules that test modules import at collection, starting with the chain under
devops_cli.ai.agents; - fewer workers, if a sweep of
-n 4/8/12/16(recorded in the task file) shows that per-worker start-up outweighs parallelism; --dist loadfileorloadgroup, only together with lazy imports, and only if the slowest file does not then set the wall time (see perf(cli): the dashboard's reactive tests run in half today's time and still check every behaviour #1339).
- SDK imports on first use in the src modules that test modules import at collection, starting with the chain under
- Does a ratchet keep the saving? (proposed) Only if the lever is lazy imports. In that case, an invariant test lists the modules allowed to import the chosen SDKs at module level, in the style of
tests/test_cli_startup_imports.pyand in the same file wherever test(cli): every test file sits in the directory mirroring the package it tests or in tests/invariants/, and the root conftest holds only the hermetic floor #1313 and test(cli): Convert ratchets to bans and merge invariant tests #1336 have placed it undertests/invariants/. Otherwise the task file's figures are the record. - Is speed part of the test design? Decided 2026-10-07: no. This is a standalone item outside test(cli): tests double only process edges and mirror the source tree #1307's phases, and the roadmap jobs rank it.
Strategic alignment
- Milestone: none; the roadmap tooling places it. Depends on: none. Blocks: none. Related: test(cli): tests double only process edges and mirror the source tree #1307; test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310 (the session fixtures and the autouse floor); test(cli): every test file sits in the directory mirroring the package it tests or in tests/invariants/, and the root conftest holds only the hermetic floor #1313 (the conftest split); test(ai): the remaining ai modules are tested through their public interfaces on edge fakes, and the legacy provider layer leaves src #1331 (deletes the mock-provider registration with the legacy providers); perf(cli): the dashboard's reactive tests run in half today's time and still check every behaviour #1339 (the most expensive file); fix(ci): devops ci quality gate finishes within five minutes #748 (the gate's 5-minute budget).
- Evidence tags: [code: path:line] was read at 5c45b1e (release/v0.2.28). [measured: …] was run at 36cfbbb on 2026-10-07; the test count has grown since, so the baseline criterion re-measures at the item's base. [inference] marks a conclusion drawn from those measurements.
Metadata
Metadata
Assignees
Labels
priority/p2-mediumPriority P2: standard workscope/ciGitHub Actions workflows, pre-commit hooks, CI gates, and runnerstype/testType test: a new or changed test
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty-bot commentedon Oct 7, 2026
Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.
A meaningful CI speedup (≈5-7 s saved) that improves developer feedback loop but does not block any functionality or fix a defect.Every developer push and every CI run benefits from faster worker startup, but the gate already passes and the saving is a fraction of total wall time.Requires measuring baselines, deferring imports across ~32 modules that pull in pydantic_ai and the model SDKs, verifying no tests are lost, and confirming coverage still meets the 90 % floor.dan-petty commentedon Oct 8, 2026
Placed in v0.2.30 on 2026-10-08 at the owner's request ("Populate 10 security and ci issues into each v0.2.30, v0.2.31, and v0.2.32 milestone"). This is a person's placement. Release theme: P1 secret and sandbox-boundary fixes, the review tools lock, kube-linter finding identity and a faster gate. Position 9 of 10 in the release's planned merge order. Its board Status is set to Ready, so the release-start fill keeps it.
dan-petty-bot commentedon Oct 9, 2026
Moved to v0.2.31: v0.2.30 started with more than 12 items, and this was its lowest-ranked unstarted item. (devops roadmap reprioritize)
perf(ci): test workers start 25% faster by deferring model SDK imports (
dan-petty-bot commentedon Oct 9, 2026
What changed
#1483, merged into
release/v0.2.31as 0f945db.21 file(s) changed.
How it was verified
Check runs at 88c5c93:
Acceptance Criteria of
docs/agent/tasks/task-1338-test-worker-startup.md:uv run pytest -q -p no:cacheprovider -k zz_no_such_test_zz(start-up and collection only) -> 37.52s;uv run pytest -q -p no:cacheprovider(the full run) -> 152.32s;uv run python -X importtime -m pytest --collect-only -q -s -n0 -p no:cacheprovider->devops_cli,anthropic,kubernetes,google,qdrant_client.srcand still meetsfail_under = 90(measured 92.36%).changelog.d/1338.mdrecords the change;CHANGELOG.mdanddocs/ROADMAP.mdare not edited.uv run devops cipasses.feat(release): v0.2.31 (#1490)