Skip to content

fix(ci): the pytest step of devops ci exceeds the 5-minute budget #3593

Closed

Description

@dan-petty

What changed

The four host-state tests that this item listed are tracked in #3585. This item keeps the time budget of the pytest step.

Budget

A full devops ci run on the agent worktree took 6m 53s for the pytest step. The budget is 5 minutes. The slowest test is tests/commands/test_ai_local_dry_run.py::test_local_ai_commands_run_cleanly, at 58 s.

pytest-xdist is already a test dependency, and the test row of CI runs in four shards (#3050). The last 20 runs of Tests & Coverage took 290 s on average, and the limit is 300 s. The slow runs are local runs on a host that other agents also load.

Expected

The pytest step of devops ci meets the 5-minute budget.

Proposed design

Problem statement

Four tests fail on the agent worktree host because each one reads host state that it does not control. The same tests fail on a clean checkout of origin/main at d254410. The pytest step of devops ci also takes 6m 53s, and the budget is 5 minutes. This change isolates the host state that each test reads, and it runs the suite in parallel workers.

Acceptance criteria

Requirement: SSH prefix test controls the project config

The test test_get_ssh_key_prefix_resolution SHALL set the project-config layer it reads to a file under tmp_path, so no config on the host supplies the prefix.

Scenario: Host config in an ancestor

  • WHEN A config.yaml that names ssh.key_prefix: devops_cli sits in an ancestor of the temporary root, and the test runs.
  • THEN The test passes and asserts the prefix my_plain_repo.

Requirement: Project config path test controls the search root

The test test_find_project_config_path_skips_directory SHALL search from a base directory that the test controls, so a host file at /tmp/config.yaml does not change the result.

Scenario: Host file at the temporary root

  • WHEN /tmp/config.yaml exists and the test runs.
  • THEN The test passes, and _find_project_config_path returns None for the directory and the resolved path for the non-existent file.

Requirement: Install-tools status test controls tool detection

The test test_mark_only_commands_under_global_dry_run SHALL patch the tool detection that install-tools status reads, so the output does not depend on the programs on the host.

Scenario: Host has the tools installed

  • WHEN Every tool of the install list is on the host and the test runs.
  • THEN The test passes and the status output holds the not installed line that it asserts.

Requirement: Direct executor test controls the tool and the network

The test test_the_direct_executor_refuses_a_network_profile_before_it_starts_the_tool[direct] SHALL patch the popeye lookup and the kube API address it reads, so the refusal does not depend on the host.

Scenario: Host has popeye and a loopback listener

  • WHEN A popeye binary is on PATH and a listener answers on the kube API loopback port, and the test runs.
  • THEN The test passes with the SandboxError that names the network profile, and no process that it started stays after it.

Requirement: Pytest command uses parallel workers

The pytest command that devops ci test builds SHALL pass -n auto to pytest through pytest-xdist, which the project declares as a test dependency.

Scenario: Built pytest command

  • WHEN A test reads the pytest arguments that devops ci test builds.
  • THEN The arguments hold -n auto.

Requirement: Suite meets the five-minute budget

The pytest step of devops ci test SHALL finish in less than 300 seconds on the agent worktree host, with every test passing.

Scenario: Full suite on the agent host

  • WHEN The full suite runs on the agent worktree host with the parallel command.
  • THEN The step reports less than 300 seconds and no failed test.

Existing Tool Considered

No alternatives check has run. pytest covers host-state isolation through monkeypatch, tmp_path and skipif. pytest-xdist covers the duration through parallel workers. Both are open and maintained. What they lack: neither isolates a test's host state or splits the suite for you. The four tests need their own isolation edits. The parallel workers need those edits first, because shared host state breaks under them.

Key questions

  • Which host state does test_get_ssh_key_prefix_resolution read?: The test leaves the project-config layer to the host. It sets ssh.key_prefix to None, and it asks get_ssh_key_prefix for a directory under the temporary root. A config that the host holds in an ancestor of that root supplies devops_cli. [sources: tests/crypto/test_ssh.py:142, tests/crypto/test_ssh.py:144, src/devops_cli/crypto/ssh_keys.py, tests/telemetry/test_config_env_overrides.py]
  • Why does test_find_project_config_path_skips_directory resolve /tmp/config.yaml?: DEVOPS_CLI_CONFIG names a directory, and the function skips it. The search then walks up from base_dir, which is under the host's temporary root. A config.yaml at that root is the result. [sources: tests/telemetry/test_config_env_overrides.py, src/devops_cli/config/settings.py]
  • Why does test_mark_only_commands_under_global_dry_run report the tool as installed?: The test asserts the literal not installed in the output of install-tools status. That command reads the programs installed on the host. On a host with the tools installed, the line is absent. [sources: tests/commands/test_devcontainer_install_tools_dry_run.py, src/devops_cli/commands/install_tools.py]
  • Why does the direct executor test error at teardown on the agent host?: The test leaves two host facts to the host. The first is whether a popeye binary is on PATH. The second is whether the kube API loopback port has a listener. The agent host has both, so the test does not reach the refusal that it asserts, and its teardown reports the error. [sources: tests/ai/test_tool_executor_contract.py, src/devops_cli/security/tool_executor.py]
  • How does each test isolate the host state it reads?: Each test sets the host input that it reads to a value under tmp_path with monkeypatch. DEVOPS_CLI_CONFIG names a config file that the test writes. PATH or the tool lookup hides the host programs. The install-tools detector reports absent. A test uses pytest.mark.skipif only for a capability that it needs and cannot simulate, as the bwrap mark does. (best practice) [sources: tests/ai/test_tool_executor_contract.py]
    • Chosen: Set the input under tmp_path with monkeypatch. The test owns the value, so it passes on every host and keeps its coverage.
    • Rejected: Skip the test when the host state is present. The test stops checking on the hosts that show the defect, and the suite passes with the defect present.
    • Rejected: Run the test in a subprocess with a clean environment. It adds a second runner and slows the suite, and the budget is already over.
  • Which test sets the floor of the suite duration?: tests/commands/test_ai_local_dry_run.py::test_local_ai_commands_run_cleanly takes 58 s and runs 20 CLI commands. It is 9 percent of the 623 s. Cutting it alone leaves the step over the 5-minute budget. [sources: tests/commands/test_ai_local_dry_run.py]
  • How does the pytest step meet the 5-minute budget?: Run the suite with pytest-xdist workers through -n auto in the command that devops ci test builds. Do this after the four tests isolate host state. Add pytest-xdist to the test dependencies if the project does not declare it. (best practice) [sources: docs/adr/0004-ci-is-the-authoritative-gate.md, tests/commands/test_ai_local_dry_run.py]
    • Chosen: pytest-xdist with -n auto. The workers divide 623 s of independent tests, so the wall time falls well under 300 s on a host with four or more cores. The tool is open and maintained, and pytest-cov supports it.
    • Rejected: Shard the suite across CI jobs. ADR 0004 rejects per-check scoping and matrix required checks, and a matrix needs an aggregating job.
    • Rejected: Cut the slowest tests. The slowest test is 58 s of 623 s, so the step stays over 300 s.
    • Rejected: Raise the 5-minute budget. The issue sets the budget, and the change must meet it.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-07: in-use.
The item already names this tool.
Tool: pytest-xdist (https://pypi.org/project/pytest-xdist), MIT, last activity 2025-07-01, not maintained.

Activity

  1. added
    source/agent
    type/bug
    scope/ci
    status/new
    value/high
    effort/medium
    on Nov 5, 2026
  2. dan-petty commented on Nov 5, 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/bug. The fix prefix of the title gives the type.
    • Scope: scope/ci. The (ci) scope of the title gives the scope.
    • Priority: P1-High. The CI gate is failing and blocks all development work.
    • Value: High. A broken CI gate blocks all merges and pushes.
    • Effort: Medium. Four tests need host-state isolation and one needs a skip condition.
    • Possible duplicate: fix(ci): host state fails four tests and one case #3585, which may ask for the same change. The model names Make the four host-state-dependent tests hermetic so they pass on any host as the change that both ask for. Both items ask for the same four host-state tests to be fixed so they pass regardless of the host environment. A person closes one of the two if that is so.
  3. added
    priority/p1-high
    on Nov 5, 2026
  4. dan-petty commented on Nov 5, 2026

    @dan-petty
    OwnerAuthor

    The four host-state tests fail on a clean checkout of origin/main (commit d254410) in the devcontainer of this sandbox too:

    • tests/crypto/test_ssh.py::test_get_ssh_key_prefix_resolution
    • tests/telemetry/test_config_env_overrides.py::test_find_project_config_path_skips_directory
    • tests/commands/test_devcontainer_install_tools_dry_run.py::test_mark_only_commands_under_global_dry_run
    • tests/ai/test_tool_executor_contract.py::test_the_direct_executor_refuses_a_network_profile_before_it_starts_the_tool[direct]

    Each run is uv run devops ci test <file>. The change of feat/3039 does not touch these modules.

  5. dan-petty commented on Nov 5, 2026

    @dan-petty
    OwnerAuthor

    Evidence from the full uv run devops ci of feat/3276-negative-search-accepts-repeated-e, run in the devcontainer on this host.

    • The pytest step gives 4 failed, 18653 passed, 2 skipped and 1 error. The failures are the four tests of this issue. The change for feat(roadmap): let a negative search verify check more than one name #3276 does not touch them.
    • A clean worktree at origin/main d254410 gives the same failures for the three files and for tests/ai/test_tool_executor_contract.py.
    • The pytest step took 7m 14s and warned that the tests were over the 5m budget. The slowest test was tests/commands/test_ai_local_dry_run.py::test_local_ai_commands_run_cleanly at 70.7 s.

    The change for #3276 adds no test that takes time. Its new tests run in under a second each.

  6. added
    status/ready
    and removed
    status/new
    on Nov 5, 2026
  7. devops-cli-service commented on Nov 5, 2026

    @devops-cli-service
    Contributor

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

  8. dan-petty commented on Nov 5, 2026

    @dan-petty
    OwnerAuthor

    A review of the branch for #3276 found the same failures on this host.

    uv run devops ci on that branch ended with four failed tests and one error. The same four tests and the error also fail on a clean checkout of origin/main on this host:

    • tests/crypto/test_ssh.py::test_get_ssh_key_prefix_resolution. The checkout sits inside another repository.
    • tests/telemetry/test_config_env_overrides.py::test_find_project_config_path_skips_directory. A file exists at /tmp/config.yaml.
    • tests/commands/test_devcontainer_install_tools_dry_run.py::test_mark_only_commands_under_global_dry_run. The devcontainer tool is on the PATH.
    • tests/ai/test_tool_executor_contract.py::test_the_direct_executor_refuses_a_network_profile_before_it_starts_the_tool[direct]. A scanner binary of the host is reached, and a loopback port is bound by another process.

    The same run warned that pytest took 5m 21s, over the 5m budget. Another gate run held the one gate slot during that time.

    This comment adds evidence to this issue. It does not change its scope.

  9. dan-petty commented on Nov 5, 2026

    @dan-petty
    OwnerAuthor

    Timing observed on 2026-11-05 in the local run of uv run devops ci for pull request #3602. The pytest job took 6 min 43 s, over the 5 min budget. Its slowest test took 53.80 s (tests/commands/test_ai_local_dry_run.py::test_local_ai_commands_run_cleanly). A narrowed run of tests/roadmap, tests/ci, tests/invariants and tests/openspec took 7 min 02 s for 4696 items.

  10. 11 remaining items

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

    @devops-cli-service
    Contributor

    Pull request #4189 is ready for review. The checks passed.

    Spend: 27 model requests, 892239 input tokens, 9505 output tokens.

  14. devops-cli-service commented on Nov 8, 2026

    @devops-cli-service
    Contributor

    The runner Job devops-cli-runner-20261108-221536-6c53 ended: succeeded.
    Image digest: sha256:e625ddb622bcb2df4b4683329b37f666852516e9c7873fce95479b857cf7ab8b

    The last lines of its log:

    Tool call: shell, program grep, ok.
    Tool call: shell, started: grep -rn "docs" src/devops_cli/ci/specs.py src/devops_cli/ci/*.py | ...
    Tool call: shell, program grep, ok.
    Tool call: shell, started: grep -rn docs src/devops_cli/ci/specs/*.py | grep ...
    Tool call: shell, started: ls src/devops_cli/ci
    Tool call: shell, program grep, ok.
    Tool call: shell, program ls, ok.
    Tool call: read_file, ok.
    Tool call: edit_file, ok.
    Tool call: shell, started: uv run devops ci docs
    Tool call: shell, program uv, ok.
    Tool call: shell, started: uv run devops ci test tests/invariants/test_agents_md_claims.py
    Tool call: shell, program uv, ok.
    Tool call: edit_file, ok.
    Tool call: shell, started: uv run devops openspec check
    Tool call: shell, started: git diff
    Tool call: shell, program git, ok.
    Tool call: shell, program uv, ok.
    Tool call: shell, started: git diff --stat
    Tool call: shell, started: git diff -- docs/TESTING.md openspec/changes/3593-the-pytest-step-of-devops-ci/tasks.md
    Tool call: shell, program git, ok.
    Tool call: shell, program git, ok.
    Tool call: read_file, ok.
    Tool call: read_file, ok.
    Tool call: shell, started: git status --short
    Tool call: shell, program git, ok.
    Tool call: read_file, ok.
    Tool call: shell, started: git rev-parse --show-toplevel
    Tool call: read_file, ok.
    Tool call: shell, program git, ok.
    Tool call: shell, started: git status
    Tool call: shell, started: git diff HEAD --stat
    Tool call: shell, program git, ok.
    Tool call: shell, program git, ok.
    Tool call: shell, started: git log --oneline -6
    Tool call: shell, program git, ok.
    Tool call: shell, started: git show --stat --oneline HEAD
    Tool call: shell, program git, ok.
    ✓ Took 1 item(s) to a ready pull request, stopped 0.
    Elapsed: 18m 49s
    
  15. removed
    owner/service
    on Nov 8, 2026
  16. removed
    status/in-review
    on Nov 8, 2026
  17. devops-cli-service commented on Nov 8, 2026

    @devops-cli-service
    Contributor
  18. devops-cli-service commented on Nov 8, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-08 23:37 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/p1-highscope/cisource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions