Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-11-01
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Design

## Decisions

None.

## Rejected alternatives

None.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Proposal

## Why

Issue #2369 reports that tests/commands/test_cli_startup_imports.py takes 204 s of the suite's 2,423 s. Each of its 56 probes starts a fresh interpreter under -X importtime, which adds per-import overhead to stderr and a Python parse of that text. The file is a structural budget and must stay, but its cost is the problem.

## What Changes

- Replace -X importtime with a sys.modules dump in the normal probe path
- Add a timed re-probe that runs with -X importtime only when a budget fails
- Keep all 56 probes, all four limits, and the control test unchanged
- The change fits one pull request.

## Capabilities

### New Capabilities

None.

### Modified Capabilities

- `ci-job-time`: startup-import-probe-mechanism

## Impact

- Tests: `tests/commands/test_cli_startup_imports.py`

## Feasibility

- The issue confirms the cost: 56 probes at about 4.2 s CPU each, with -X importtime adding per-import stderr lines and a Python parse. The file is at tests/commands/test_cli_startup_imports.py, and line 448 defines _probe_startup_imports.
- sys.modules provides the set of loaded module names at the end of a run, which is all the budget count needs. The identifier matches confirm the four limit constants at lines 33-36 of the file.
- First checks: run pytest tests/commands/test_cli_startup_imports.py -n 0 to get the baseline CPU time. Then run the same command after the change and confirm the total is at most half the baseline over three runs.

## Existing Tool Considered

python -X importtime is the existing tool. It stays for the failure diagnostic message. The normal probe uses sys.modules, a Python built-in that requires no new dependency. No new tool is introduced.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## ADDED Requirements

### Requirement: startup-import-probe-mechanism
The startup-import probe SHALL collect the set of loaded module names via sys.modules in the normal path, and SHALL use -X importtime only in the failure diagnostic path to report the ten slowest imports by cumulative seconds.

#### Scenario: normal probe uses sys.modules
- **WHEN** a startup-import probe runs and the budget passes
- **THEN** the probe collects module names from sys.modules without the -X importtime flag

#### Scenario: failure diagnostic uses importtime
- **WHEN** a startup-import probe runs and the budget fails
- **THEN** the probe re-runs with -X importtime and the assertion message includes the ten slowest imports by cumulative seconds
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Tasks

## 1. Replace -X importtime with sys.modules dump in the probe

Reads: none. Changes: `tests/commands/test_cli_startup_imports.py`.

- [ ] 1.1 Write a test that asserts the subprocess args of _probe_startup_imports do not include -X importtime. The test mocks subprocess.run and checks the args list. Before the change, the args include -X importtime, so the test fails, and verify that `uv run pytest tests/commands/test_cli_startup_imports.py -n 0 -x -q` fails on the base
- [ ] 1.2 Modify _probe_startup_imports to build a -c script that imports the entry point, runs the command, then prints sorted(sys.modules.keys()) to stdout. Remove -X importtime from the subprocess args. Parse stdout instead of stderr for the module list, and verify that `uv run pytest tests/commands/test_cli_startup_imports.py -n 0 -x -q` passes
- [ ] 1.3 Change no document, run `uv run devops docs generate --sync-readme`, and verify that `uv run devops ci docs` passes

## 2. Add timed re-probe for the failure diagnostic message

Reads: none. Changes: `tests/commands/test_cli_startup_imports.py`.

- [ ] 2.1 Write a test that asserts _probe_startup_imports_timed exists and returns a list of (module, cumulative_seconds) pairs sorted by cumulative_seconds descending. Before the change, this function does not exist, so the test fails, and verify that `uv run pytest tests/commands/test_cli_startup_imports.py -n 0 -x -q` fails on the base
- [ ] 2.2 Add _probe_startup_imports_timed that runs the same argv with -X importtime and parses stderr for the ten slowest imports by cumulative seconds. Update the assertion helpers: when the module count exceeds the limit, call _probe_startup_imports_timed and include its result in the assertion message, and verify that `uv run pytest tests/commands/test_cli_startup_imports.py -n 0 -x -q` passes
- [ ] 2.3 Change no document, run `uv run devops docs generate --sync-readme`, and verify that `uv run devops ci docs` passes

## Workflow follow-up

- Pending a person: review the diff in tuicr (tuicr -r <base>..HEAD).
Loading