Repository navigation
Closed
Labels
Milestone
Description
Friction
- The structural-invariants pre-commit hook is a sub-second AST walk, but its entry is
uv run, so every run first syncs the venv: a bytecode pass over 17,910 files and an OSV malware query for all locked packages. - The hook is not
require_serial, so pre-commit splits the staged files into up to 16 batches, and each batch pays its own sync. The batches queue on the venv lock. - When OSV is slow or down, this hook fails the commit even though it needs no packages: about 8-10 s per refused sync, about 50 s when the connection hangs.
Evidence
Checked at release/v0.2.37 30b8fdd.
- Entry
uv run python3 -m devops_cli.core.code_metricswith norequire_serial(.pre-commit-config.yaml:54-60). src/devops_cli/core/code_metrics.pyimports only the standard library (:15-22), andpython3 -P src/devops_cli/core/code_metrics.pygives the same output and exit code, including on a violating file.- On one file, 3 interleaved runs at load 15-22:
uv run python3 -m ...2.80 / 1.43 / 1.59 s and about 4 CPU-s;python3 -P <path>0.21 / 0.10 / 0.05 s and 0.1 CPU-s. - With 20 staged files at load 43-59, the hook took 17.2 s and 25.3 CPU-s (5 syncs) against 7.4 s and 2.3 CPU-s with the stdlib entry. With 64 files at load around 100 (3 runs), 101 s against 25 s with
require_serial: truealone and 30 s with one sync and--no-syncbatches; the stdlib entry was not timed at 64 files. - A test pins the entry string (
tests/test_code_metrics.py:286-299), and the hook comment (.pre-commit-config.yaml:47-53) says the package inits load config and typer. /usr/bin/python3is 3.14 in the devcontainer, which the sources need (they use PEP 758except A, B:). No GitHub workflow runs pre-commit.
Remedy
- Set the entry to
python3 -P src/devops_cli/core/code_metrics.pyand addrequire_serial: true; keepargs: [--max-depth, "5"]. If hosts outside the devcontainer matter, useuv run --no-sync python -P src/devops_cli/core/code_metrics.pyinstead, which keeps the project interpreter without a sync. - Update the pinned test and the hook comment in the same change.
- The
devops ci testhook keeps its synceduv run, so each commit still runs one malware-checked sync. No check or cap changes.
Acceptance criteria
- Tests first, offline: the pinned-entry test expects the new entry,
require_serial: trueand the same args. - A test runs the new entry on a file that breaks the depth cap and on one that does not, in a
tmp_pathcopy, and checks the exit codes and output match the module run. - A commit staging 20 Python files runs the hook in one process (pre-commit
--verboseshows one run).
Proposed design
Problem statement
The structural-invariants pre-commit hook uses uv run to execute a Python script that only requires the standard library. This causes unnecessary overhead as uv run synchronizes the virtual environment on every invocation, including performing bytecode passes over thousands of files and OSV malware queries for all locked packages. The hook is not marked as require_serial, so pre-commit splits staged files into batches, each paying for its own sync, which leads to long commit times and failures when OSV is slow or down.
Acceptance criteria
- Criterion 1: The test that pins the entry string expects the new entry with
require_serial: trueand the same arguments.
Verification: Run the testtest_the_commit_hook_runs_this_module_at_the_default_cap()and verify it passes with updated entry string,require_serial: true, and the same args. - Criterion 2: A test verifies that the new entry correctly handles files that breach or do not breach the depth cap.
Verification: Create a test that runs the new entry on a file that breaks the depth cap and one that does not, in atmp_pathcopy, and checks the exit codes and output match the module run. - Criterion 3: A commit staging 20 Python files runs the hook in one process.
Verification: Stage 20 Python files and run pre-commit with verbose mode; observe that only one run of the hook is executed, confirmingrequire_serial: trueworks as intended.
Key questions
- What is the current entry point for the structural-invariants hook?: The current entry point is
uv run python3 -m devops_cli.core.code_metrics. [sources: .pre-commit-config.yaml:54-60] - Does the code_metrics.py module only use the standard library?: Yes, according to the documentation in
src/devops_cli/core/code_metrics.py, it imports only the standard library and does not importdevops_cli. [sources: src/devops_cli/core/code_metrics.py:15-22] - Should the fix use
python3 -Poruv run --no-sync python -P?: If hosts outside the devcontainer matter, useuv run --no-sync python -P src/devops_cli/core/code_metrics.pyto keep the project interpreter without a sync. (proposed) - What should be updated in addition to the hook entry?: The pinned test and the hook comment in
.pre-commit-config.yamlshould be updated in the same change. (proposed)
Open questions
- What performance difference was observed between
uv runand direct Python invocation? (missing verified source) - How does the performance degrade with more staged files? (missing verified source)
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 18, 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 improves CI infrastructure by optimizing a pre-commit hook.Improves developer experience and CI performance but is not critical.Reduces commit time and network usage for developers, improving workflow efficiency.Involves changing the hook entry and adding a flag, with minimal code changes.dan-petty commentedon Oct 18, 2026
Amendment (2026-10-18): folded here by intake under the agent filing quota
The cycle's agent filing allowance (#1153) was used, so
devops roadmap intakefiled nothing and named this item as the nearest. The candidate below is related work that can land with this item or be filed on its own in a later cycle. Candidate title: "fix(ci): devops ci test reads the test tree once per run and shows which staged sources no test covers".Friction
devops ci test <staged paths>re-reads all 478 test modules (about 8 MB) once for every staged source file, about 0.4 CPU-s each.--fallbackhelp say the opposite: that unmapped sources fall back to the full suite.src/devops_cli/lang/en/help.py.Evidence
Checked at release/v0.2.37 30b8fdd.
_map_src_tree_pathcallsselect_tests_for_sources([path])per path, and each call reads every test file again (src/devops_cli/core/test_selection.py:177-180).src/devops_cli/commands/ci.py:1373-1374); pre-commit hides the output of a passing hook (pre_commit/commands/run.py:217); the hook comment (.pre-commit-config.yaml:62-64) and the help text (src/devops_cli/lang/en/help.py:628-631) promise a fallback.ci.pymaps paths with its own code (_resolve_test_targets,:1334-1380), not the sound policy the coverage index module already has:select_from_indexandneeds_full_run(src/devops_cli/core/coverage_index.py:191,:324) are not called from ci.py.config/constants.py,config/defaults.pyandlang/en/messages.pyselects about 90 of 478 test modules. Hook-like runs had a median of 66 s and a p90 of 186 s.devops ci testselects tests from a coverage index built on demand bydevops ci coverage --build-index#406 built the index on demand; fix(ci): coverage index treats module-level and import-time changes as unindexed #884 made module-level changes unindexed. Neither covers the points above.Remedy
--fallbackhelp andMESSAGES.ci.no_covering_teststo say the narrowed run is advisory for unmapped sources and the pre-pushdevops ciis the gate; setverbose: trueon the devops-ci-test-changed hook so the unmapped list is shown.select_from_indexandneeds_full_run, and delete the path that loses. Building the index as a by-product of the pre-push test row must not lengthen the push; measure its cost first.Acceptance criteria
devops ci testcall with three staged sources and expects one pass over the tree.devops docs checkpasses.dan-petty commentedon Oct 18, 2026
Amendment (2026-10-18): folded here by intake under the agent filing quota
The cycle's agent filing allowance (#1153) was used, so
devops roadmap intakefiled nothing and named this item as the nearest. The candidate below is related work that can land with this item or be filed on its own in a later cycle. Candidate title: "fix(ci): devops ci's uv children keep the malware check and the project uv cache, and leave the one sync to the hook".Friction
devops cistrips everyUV_*variable from theuvcommands it starts. Its child syncs therefore run no malware check and use~/.cache/uvinstead of the project cache.uv run devops cialready ran one checked sync. A baredevops ci(the.venv/bin/devopson PATH) or a run in a new worktree installs packages through the children with no malware check.Evidence
Checked at release/v0.2.37 30b8fdd.
src/devops_cli/core/process.py:45-102has noUV_entry, and ci.py passes noextra_allowed_env(src/devops_cli/commands/ci.py:217,:350,:1875).UV_MALWARE_CHECKturns the check on. The--preview-features malware-check,check-commandthat ci.py prepends (:189-190,:215-216,:345-346) only silences the preview warning and repeatspyproject.toml:231-232.install_tools.py:200already passes a_UV_ENVset through for its ownuvcalls.--no-syncon the children.devops ciwould repeat the hook's OSV query:uv run truetook a median 1.48 s against 0.57 s withUV_MALWARE_CHECKunset, 3 interleaved runs at load 13-23. That is about 0.9 s per push, more than the child syncs cost.Remedy
_UV_ENVintosrc/devops_cli/config/constants.py(for exampleCONST_UV_PASSTHROUGH_ENV = frozenset({"UV_MALWARE_CHECK", "UV_CACHE_DIR", "UV_LINK_MODE"})) and pass it asextra_allowed_envfrom every ci.pyuvcall site. The deny patterns still apply.UV_COMPILE_BYTECODEstays out.--no-syncright after therunandchecksubcommands at the three injection points (:189,:215,:345;_captureat:1872goes through:189), so no child syncs.uv run devops cistays the one malware-checked sync. A baredevops cithen installs nothing through its children, which closes the unchecked-install gap.uv syncinsidedevops ci: under the hook it would repeat the OSV query and cancel the saving. A guard for bare runs is the owner's call, at one OSV query per push.--preview-featuresinjection.uv lock --checkstays.Acceptance criteria
UV_MALWARE_CHECKandUV_CACHE_DIRkept and every variable matched by the deny patterns (src/devops_cli/core/process.py:104-112) still dropped.uv runanduv checkcarries--no-sync.dan-petty commentedon Oct 19, 2026
Amendment (2026-10-19):
devops test run --changedneeds a base other thanmainFound in #1312 PR 2's review.
devops test run --changedlists changes against the literalmain(src/devops_cli/commands/test_cmd.py). There is no--baseoption, and a failedgit diffis ignored.release/vX.Y.Z, so on any topic branch the listing covers the whole release. On test(cli): tests find the repository root and fixtures from any depth, import no other test module and build test data with shared builders, and devops test maps a change to its mirror directory #1312 PR 2 that was 877 paths, which selects the full suite.The follow-up, which fits this item's commit-time selection work:
devops test run --base/-b, defaulting to the merge base with the branch's upstream (@{upstream}), else the active release branch, elseCONST_GIT_MAIN_BRANCH;git.operations.resolve_merge_baseand validated with_is_safe_revision;mutate_base_missingandmutate_base_refusederrors when the ref is absent or refused, instead of ignoringgit diff's exit status.Test it with a temporary repository whose topic branch sits on a release branch:
--changedlists only the topic's own changes.dan-petty commentedon Oct 19, 2026
Amendment (2026-10-19): the covering-test selector matches imports in text, including string literals
#1312 PR 2's selection review found that
select_tests_for_sourcesdecides "imports it" with a regex over each test file's text.tests/test_test_runner.py(16 IDs) is selected for anydevops_cli/ai/review/*ordevops_cli/ai/__init__.pychange, because of the literals at its lines 22-24 and 84-86.This item already reads the test tree once per run. The same pass can parse each test module with
astand build an import graph:Measured on the last 40 commits: selection takes a median of about 1 s, and 10-22 s for release-size diffs, almost all of it the per-source regex over all 480 test files.
feat(test): devops test and devops ci test choose tests through one s…
feat(release): v0.2.37 (#1720)
perf(ci): structural-invariants hook runs in one pass without uv sync (…
dan-petty commentedon Oct 20, 2026
What changed
#1760, merged into
release/v0.2.38as dbdb009.5 file(s) changed.
How it was verified
Check runs at 415d613:
Acceptance Criteria of
docs/agent/tasks/task-1667-structural-invariants-hook-one-pass.md:No Acceptance Criteria section.
dan-petty commentedon Oct 20, 2026
What changed
#1760, merged into
release/v0.2.38as dbdb009.5 file(s) changed.
How it was verified
Check runs at 415d613:
Acceptance Criteria of
docs/agent/tasks/task-1667-structural-invariants-hook-one-pass.md:No Acceptance Criteria section.
feat(release): v0.2.38 (#1799)
feat(release): v0.2.38 (#1798)