Repository navigation
Description
Problem
The fix of #4472 (PR #5547, merged 2026-11-14 as 2126dc6, released in v0.136.0) does not work for the selection that #4472 reports, and it slows down narrowed test runs. An agent vet of the merged change found one blocking and two major defects. Each one was reproduced.
- The collection exits 1, so the fix falls back.
_collection_cmd(src/devops_cli/commands/ci.py:1937) runsuv run pytest -n 0 --collect-only -q <targets>. syrupy makes this command exit 1 when a selected module has unused snapshots ("Re-run pytest with --snapshot-update")._collected_test_countreads exit 1 as a failed collection, prints "Could not collect the selected tests ... exit code 1" and goes back to the file count. So the 7 modules of the fix(ci): a narrowed ci test runs many slow tests serially #4472 reproduction (422 tests) still run with-n 0. Example:tests/output/test_output.pycollects 55 tests and exits 1. The shard rows (ci.py:697) already pass--snapshot-warn-unused. The unit test fakes exit 0, so it cannot find this. - An explicit
-n 4ignoresPYTEST_XDIST_AUTO_NUM_WORKERS. When more than 50 tests are collected,_narrowed_workers(ci.py:1981) returns the literal4. A runner pod with 1 CPU (PYTEST_XDIST_AUTO_NUM_WORKERS=1) then runs 4 workers on 1 CPU. Measured on 1 pinned CPU with 52 tests:-n 0took 33.6 s, the new default took 104 s. The implement job runsuv run devops ci test <file>many times in each attempt. - Each narrowed run starts a second pytest session. The collection took 23 to 47 s of wall time at a high host load (most of it in
tests/support/bootstrap.pyregister_support_plugins). A 52-test module took 86 to 103 s against 42 to 44 s with-n 0.design.mddoes not measure this cost.
Minor points from the same vet:
- The collection uses
DEFAULT_SUBPROCESS_TIMEOUT_SECONDS(1800 s), against the nested-timeout rule. - The warning at
ci.py:1966has nosafe=True, so brackets in a target or a-kvalue become Rich markup or raiseMarkupError. src/devops_cli/ai/knowledge_base/devops_cli/tasks/ci_quality_gate.md:69still states the old file-count rule (AGENTS.md rule 8).- No test proves that a
--repeatrun makes no collection, and the 12-module boundary test was deleted.
Expected behavior
- A selection that collects more than 50 tests runs on the capped workers, also when a module has unused snapshots.
- A pod with
PYTEST_XDIST_AUTO_NUM_WORKERS=1runs serially and starts no collection session. - The extra collection costs a measured, bounded time, with a short timeout of its own.
Fix
- Add
--snapshot-warn-unusedto the collection argv, with a unit case that fails when the flag goes away, and record a real collection of the fix(ci): a narrowed ci test runs many slow tests serially #4472 selection (exit 0, 422 items,-n 4). - Use
min(DEFAULT_CI_TEST_NARROWED_WORKERS, PYTEST_XDIST_AUTO_NUM_WORKERS)when the variable is set, run serially at 1, and skip the collection when the result cannot change the worker count. - Add
DEFAULT_CI_TEST_COLLECTION_TIMEOUT_SECONDSwith the measured time, give the warningsafe=True, fix the knowledge-base page, and restore the boundary and--repeattests.
Evidence
- Vet workflow wf_787e57b7-144 (11 agents; two lenses and two verifiers reproduced the blocking finding).
- Follows fix(ci): a narrowed ci test runs many slow tests serially #4472 (closed as completed by fix(ci): Size narrowed test workers by collected tests #5547).
Source: #5547
Proposed design
Problem statement
The fix of #4472 does not work for the reported selection and slows narrowed test runs. The collection exits 1 when a selected module has unused snapshots, so the run falls back to the file count. An explicit -n 4 ignores PYTEST_XDIST_AUTO_NUM_WORKERS, and each narrowed run starts a second pytest session. The change corrects these defects and restores the missing tests.
Acceptance criteria
Requirement: Collection command tolerates unused snapshots
The narrowed test collection command SHALL include --snapshot-warn-unused.
Scenario: Unused snapshot in a selected module
- WHEN a selected module has an unused snapshot and the collection command is built
- THEN the command argv contains
--snapshot-warn-unusedand the test fails when the flag is absent.
Requirement: The #4472 selection collects 422 tests
A recorded collection of the seven #4472 modules SHALL exit 0 and report 422 test items.
Scenario: Recorded #4472 collection
- WHEN the recorded stdout of the seven fix(ci): a narrowed ci test runs many slow tests serially #4472 modules is read
- THEN
_collected_test_countreturns 422 and the run uses-n 4.
Requirement: Environment caps the narrowed workers
When PYTEST_XDIST_AUTO_NUM_WORKERS is above 1, the narrowed worker count SHALL be the minimum of DEFAULT_CI_TEST_NARROWED_WORKERS and that value.
Scenario: Two-worker pod with 52 tests
- WHEN
PYTEST_XDIST_AUTO_NUM_WORKERS=2and the collection reports 52 tests - THEN the run uses
-n 2.
Requirement: One worker runs serial
When PYTEST_XDIST_AUTO_NUM_WORKERS is 1, the run SHALL use -n 0 and SHALL make no collection call.
Scenario: One-worker pod with 52 tests
- WHEN
PYTEST_XDIST_AUTO_NUM_WORKERS=1and the selection has target paths - THEN the command argv contains
-n 0and the fake process records no--collect-onlycall.
Requirement: Explicit worker count skips collection
The run SHALL skip the collection when an explicit -n value already sets the worker count.
Scenario: Explicit worker count
- WHEN the user passes
-n 2and the selection has target paths - THEN the fake process records no
--collect-onlycall and the run uses-n 2.
Requirement: Collection has a short timeout
The collection SHALL use DEFAULT_CI_TEST_COLLECTION_TIMEOUT_SECONDS and not DEFAULT_SUBPROCESS_TIMEOUT_SECONDS.
Scenario: Collection timeout value
- WHEN a test starts the collection command
- THEN the process fake receives
DEFAULT_CI_TEST_COLLECTION_TIMEOUT_SECONDSas its timeout.
Requirement: Failed collection keeps the fallback
A collection that exits non-zero for a reason other than unused snapshots SHALL keep the file-count fallback and print the warning.
Scenario: Collection exits 3 over 13 modules
- WHEN the fake collection exits 3 over 13 target files
- THEN the run prints the fallback warning and uses
DEFAULT_CI_TEST_NARROWED_WORKERS.
Requirement: Fallback warning keeps brackets literal
The collection fallback warning SHALL pass safe=True so a target or -k value with brackets prints literally.
Scenario: Bracketed keyword
- WHEN a collection fails for a
-kvalue that holds brackets - THEN the warning prints the brackets literally and raises no
MarkupError.
Requirement: Knowledge base states the collected-test rule
The CI quality gate knowledge-base page SHALL state the collected-test worker rule and the serial cap.
Scenario: Knowledge-base page content
- WHEN the page
ci_quality_gate.mdis read - THEN it says that a selection over 50 tests uses the capped workers and a selection at or below 50 runs serially.
Requirement: Repeat run makes no collection
A --repeat run SHALL make no collection call.
Scenario: Repeat run with a target
- WHEN the user passes
--repeat 2and a target path - THEN the fake process records no
--collect-onlycall.
Requirement: File-count fallback keeps the 12-module boundary
The file-count fallback SHALL use DEFAULT_CI_TEST_NARROWED_WORKERS above 12 target modules and -n 0 at 12 or fewer.
Scenario: Twelve target modules
- WHEN a collection fails and the targets name 12 modules
- THEN the run uses
-n 0; a 13-module case usesDEFAULT_CI_TEST_NARROWED_WORKERS.
Requirement: Collection cost is measured and bounded
The change SHALL record the measured collection time and SHALL set DEFAULT_CI_TEST_COLLECTION_TIMEOUT_SECONDS above it.
Scenario: Measured collection time
- WHEN the design records the measured collection time of the fix(ci): a narrowed ci test runs many slow tests serially #4472 selection
- THEN the constant is greater than the measured time and shorter than
DEFAULT_SUBPROCESS_TIMEOUT_SECONDS.
Existing Tool Considered
No alternatives check has run. No open, maintained tool or library covers this internal worker-selection fix. The change extends existing code in src/devops_cli/commands/ci.py. Estimated cost to build, keep and fix it: about 12,000 output tokens and 3 hours.
Key questions
- Should the collection argv include
--snapshot-warn-unused?: Yes. The shard rows already pass it, and syrupy exits 1 on an unused snapshot without it. (best practice) [sources: src/devops_cli/commands/ci.py:697, src/devops_cli/commands/ci.py:1937, openspec/changes/archive/2026-11-13-4472-a-narrowed-ci-test-runs-many/design.md:35]- Chosen: Add
--snapshot-warn-unusedto the collection argv. The shard rows already pass it, and it stops syrupy from failing an unused snapshot. - Rejected: Read collection exit 1 as success. Exit 1 also covers real collection failures, so this would hide them.
- Rejected: Disable syrupy snapshots in the collection. The collection must import the same test modules as the run.
- Chosen: Add
- How should
PYTEST_XDIST_AUTO_NUM_WORKERScap the narrowed workers?: Usemin(DEFAULT_CI_TEST_NARROWED_WORKERS, PYTEST_XDIST_AUTO_NUM_WORKERS)when the variable is set. At 1, use-n 0and skip the collection. (best practice) [sources: docs/CLUSTER.md:63, k8s/devops/cronjob-runner.yaml:86, k8s/devops/roadmap-service/admissionpolicy.yaml:222, src/devops_cli/commands/ci.py:1981]- Chosen: Cap with the environment value. The pod sets the variable to its CPU limit. Four workers on one CPU took 104 s against 33.6 s serial.
- Rejected: Keep the literal 4. It overrides the CPU limit of the pod.
- Rejected: Use the environment value with no default cap. It can start more than the 4 workers that the design measured.
- When should the run skip the collection?: Skip when
PYTEST_XDIST_AUTO_NUM_WORKERSis 1, when-nis explicit, or when the run has no targets. (best practice) [sources: src/devops_cli/commands/ci.py:2071, src/devops_cli/commands/ci.py:1981, docs/CLUSTER.md:63]- Chosen: Skip when the worker count cannot change. It removes the second pytest session on a one-CPU pod and for an explicit
-n. - Rejected: Always collect. It adds 23 to 47 s to each narrowed run.
- Rejected: Never collect. It keeps the file-count rule and misses a module with many tests.
- Chosen: Skip when the worker count cannot change. It removes the second pytest session on a one-CPU pod and for an explicit
- What timeout should bound the collection?: Add
DEFAULT_CI_TEST_COLLECTION_TIMEOUT_SECONDSabove the measured collection time and belowDEFAULT_SUBPROCESS_TIMEOUT_SECONDS. (best practice) [sources: src/devops_cli/commands/ci.py:1937, src/devops_cli/config/defaults.py:383]- Chosen: Dedicated short timeout. The collection took 23 to 47 s, and 1800 s is too long for it.
- Rejected: Keep
DEFAULT_SUBPROCESS_TIMEOUT_SECONDS. It lets a stuck collection hold the run for 1800 s. - Rejected: No timeout. It can stall a narrowed run.
- Should the fallback warning pass
safe=True?: Yes. A target or-kvalue with brackets must print literally. (best practice) [sources: src/devops_cli/commands/ci.py:1966, tests/output/test_output.py]- Chosen: Pass
safe=True. It stops Rich markup andMarkupErroron a valid bracket. - Rejected: Escape the text before the call. It duplicates the safe path and can miss a caller.
- Rejected: Leave the warning as is. It can raise
MarkupErroron a valid-kvalue.
- Chosen: Pass
- Should the knowledge-base page change in the same pull request?: Yes. AGENTS.md rule 8 says to fix a document that the change makes wrong in the same pull request. (best practice) [sources: AGENTS.md, src/devops_cli/ai/knowledge_base/devops_cli/tasks/ci_quality_gate.md:69]
- Chosen: Update the page in the same pull request. The page still states the old file-count rule.
- Rejected: File a separate docs issue. It leaves the old rule in the knowledge base.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 14, 2026
A merged fix in v0.136.0 regressed the original selection and made narrowed runs slower than before.The regression commit 2126dc6 does not set P0: the author has no write access, and no caller attached it as evidence. A person can set P0 with the label priority/p0-critical.Both target narrowed CI test worker selection, but #4472 asked for multi-worker runs and the candidate fixes defects in that delivered fix.devops-cli-service commentedon Nov 14, 2026
Status set to Ready at b15faab (see proposed design in issue body).
devops-cli-service commentedon Nov 14, 2026
Released in v0.136.2: https://github.com/dan-petty/devops-cli/releases/tag/v0.136.2
devops-cli-service commentedon Nov 14, 2026
Live since 2026-11-14 04:20 UTC