Skip to content

fix(ci): the startup import budget counts what a command imports, not wall-clock seconds, so the gate does not fail on a busy machine #1687

Closed

Description

@dan-petty

Friction

Evidence

Checked at release/v0.2.37 a153042.

  • _measure_importtime (tests/test_cli_startup_imports.py:372-410) runs python -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 importtime reports 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_telemetry and 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, --version and each <command> --help, assert the set or number of devops_cli and third-party modules the path imports. Read it from sys.modules in a subprocess, or from -X importtime's module list, not its times. Keep the budget numbers in config/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.py passes 20 runs in a row with -n logical while two other devops ci runs 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 logical while two other devops ci runs 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_importtime function in tests/test_cli_startup_imports.py uses Python's -X importtime flag 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 --help and --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_SECONDS and CONST_STARTUP_IMPORT_BUDGET_HELP_SECONDS define 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_cli and third-party modules that a path imports, read from sys.modules in a subprocess or -X importtime's module list, not its times. (proposed)

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

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

    @dan-petty
    OwnerAuthor

    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.

    • Type: type/bug. The candidate fixes a defect in the CI test that causes false failures under load.
    • Priority: P1-High. The issue causes CI gate failures on correct changes and impacts gate speed, which is P0 per owner's rule.
    • Value: High. Fixes a flaky test that blocks the gate and forces reruns, affecting developer productivity and CI reliability.
    • Effort: Medium. Requires changing how import budgets are measured and updating tests, but not a major architectural change.
  3. added this to the v0.2.37 milestone on Oct 19, 2026
  4. added
    status/in-progress
    on Oct 19, 2026
  5. dan-petty commented on Oct 19, 2026

    @dan-petty
    OwnerAuthor

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

  6. added a commit that references this issue on Oct 19, 2026
    0510f6e
  7. removed
    status/in-progress
    on Oct 19, 2026
  8. added 4 commits that reference this issue on Oct 20, 2026
    954914e
    eced8fb
    1a8b26c
    f92399e
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

    source/agenttype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions