Repository navigation
Closed
Labels
Milestone
Description
Friction
tests/test_cli_startup_imports.py::test_cli_startup_import_budget_command_help(refactor(ai): startup import budget invariants and dry-run isolation tests (#1002) #1680, refactor(ai): delete the pass-through package facades and the two stagepipeline protocols nothing implements #1002) failed twice in one full run on 2026-10-18.[argv1]took 1.19 s and[argv2]took 1.54 s against its 1.0 s budget, at load average about 13 under-n 8, on a tree that changed no import. Both passed on a rerun at load 3.- The test is in every
devops ci, so a busy machine fails the gate on a correct change. Each failure costs a gate rerun of 3-13 minutes. The owner's rule is that CI gate speed is P0, and flaky gates teach agents to rerun failures instead of reading them (test(cli): tests wait for a background thread with one generous bound, not a 1-second deadline, so they pass under load #1664).
Evidence
Checked at release/v0.2.37 a153042.
_measure_importtime(tests/test_cli_startup_imports.py:372-410) runspython -X importtime -m devops_cli.entry <argv>several times, keeps the minimum cumulative time, and serializes the runs across xdist workers with.data/importtime.lock.-X importtimereports wall-clock microseconds per import. On a 16-CPU host shared by other test workers, an import waits for a CPU, and the minimum of a few runs does not remove that.- The neighbouring tests already pin startup structurally.
test_cli_help_imports_no_telemetryand refactor(ai): delete the pass-through package facades and the two stagepipeline protocols nothing implements #1002's dry-run isolation tests assert which packages a path does not import, and those checks are deterministic.
Remedy
- Make the gate's import budget structural: for
--help,--versionand each<command> --help, assert the set or number ofdevops_cliand third-party modules the path imports. Read it fromsys.modulesin a subprocess, or from-X importtime's module list, not its times. Keep the budget numbers inconfig/defaults.py. A heavy import added to a startup path then fails every run, at any load. - Keep the time measurement as a report, outside the pass/fail gate, so the slowest imports stay visible. Optionally, use CPU time (
resource.getrusage(RUSAGE_CHILDREN)) rather than wall time if a time budget stays in the gate. - No retry or rerun plugin: the structural budget removes the cause.
Acceptance criteria
- Tests first, offline: a startup path that imports one extra heavy package fails the structural budget; the same path passes whatever the load (run it while a CPU-bound scratch process occupies every core).
-
tests/test_cli_startup_imports.pypasses 20 runs in a row with-n logicalwhile two otherdevops ciruns share the host. - The time report still names the slowest imports in the test's output.
Proposed design
Problem statement
The CI startup import budget test uses wall-clock time measurements from Python's -X importtime to determine if a command's imports exceed the budget. On busy machines, this leads to false failures because CPU contention affects timing even when the actual module imports are consistent.
Acceptance criteria
- Criterion 1: A startup path that imports one extra heavy package fails the structural budget test.
Verification: Run a test that modifies the import behavior of a command to include an additional heavy module and verify that the new structural budget check fails. - Criterion 2: The test suite passes 20 consecutive runs with
-n logicalwhile two otherdevops ciruns share the host.
Verification: Execute the full test suite 20 times in a row with parallel execution enabled and verify all tests pass without any flaky failures. - Criterion 3: The time report still names the slowest imports in the test's output.
Verification: Run a test that should fail due to import time exceeding budget, and confirm that the output includes the list of slowest imports.
Key questions
- How does the current import timing mechanism work?: The
_measure_importtimefunction intests/test_cli_startup_imports.pyuses Python's-X importtimeflag to measure wall-clock time for each import. It runs the command multiple times, keeps the minimum cumulative time, and serializes measurements across parallel workers using a lock file. [sources: tests/test_cli_startup_imports.py:372] - What are the specific budget values for main/version and command help?: The budget is 0.5 seconds for
--helpand--version, and 1.0 second for each--help. [sources: tests/test_cli_startup_imports.py:415, tests/test_cli_startup_imports.py:435] - What are the constants used for import budgets?: The constants
CONST_STARTUP_IMPORT_BUDGET_MAIN_SECONDSandCONST_STARTUP_IMPORT_BUDGET_HELP_SECONDSdefine the time limits for main/version and command help respectively. [sources: src/devops_cli/config/constants.py] - How should the structural budget be implemented?: The structural budget should assert the set or number of
devops_cliand third-party modules that a path imports, read fromsys.modulesin a subprocess or-X importtime's module list, not its times. (proposed)
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty commentedon Oct 19, 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.
The candidate fixes a defect in the CI test that causes false failures under load.The issue causes CI gate failures on correct changes and impacts gate speed, which is P0 per owner's rule.Fixes a flaky test that blocks the gate and forces reruns, affecting developer productivity and CI reliability.Requires changing how import budgets are measured and updating tests, but not a major architectural change.dan-petty commentedon Oct 19, 2026
Status set to Ready at 0ae4ea4 (see proposed design in issue body).
fix(ci): the startup import budget counts what a command imports, not…
feat(release): v0.2.37 (#1720)
perf(tests): the startup-import checks start one interpreter per comm…
feat(release): v0.2.38 (#1799)
feat(release): v0.2.38 (#1798)