Skip to content

perf(ci): faster commit hooks and more fast pre-push checks #4776

Done

Description

@dan-petty

Problem or Motivation

The commit hooks are slow, and the pre-push hooks catch too little.

  • The commit stage takes 4.4 s for 3 Python files at load 11, and 12-16 s at load 13-31. ast-grep-scan scans all of src and tests at each commit (4.6-5.2 s). ast-grep-test runs at each commit.
  • Ruff has two pins: the ruff-pre-commit rev and uv.lock. They were different from 2026-09-18 to 2026-09-28.
  • pre-commit-hooks is at v5.0.0. v6.0.0 is out since 2025-08-09.
  • language: system is the old name of unsupported (pre-commit 4.4.0). 17 stages: [pre-commit] lines repeat the default.
  • The pre-push stage runs only lint and format. In 14 days, 6 agent Static Analysis failures failed only in the rows constructs, swallowed-failures, deps or uv-check. 3 of the 4 constructs failures came from rules that landed on main the same day, which only a check after the rebase catches.

Proposed Solution & Architectural Design

Commit stage

  • ast-grep-scan takes the staged Python files of src/ and tests/ (files: ^(src|tests)/, types: [python]), not the whole tree.
  • ast-grep-test runs only when .ast-grep/ or sgconfig.yml changes (pass_filenames: false).
  • ruff-check and ruff-format become local hooks with uv run --no-sync ruff ..., so uv.lock is the one pin. The ast-grep hooks also use --no-sync.
  • openspec-gate keeps plain uv run and runs devops ci --only openspec --timeout 90. In a worktree with no synced venv, --no-sync runs the devops of the main venv.
  • Change pre-commit-hooks to v6.0.0.
  • Use language: unsupported and add minimum_pre_commit_version: 4.4.0.
  • Delete the stages: [pre-commit] lines that repeat the default.

Pre-push stage

Remove constructs from CONST_ROADMAP_IMPLEMENT_SCOPED_ROWS (src/devops_cli/config/constants.py), because the pre-push stage of the Job now runs it. #4635 changes the same constant.

The per-file ast-grep scan and the pre-push constructs row ship together, so the whole-tree scan still runs after each rebase.

Update CONTRIBUTING.md (the hook list), the local-runs line of ADR 0014 and tests/roadmap/test_roadmap_runner_tools.py.

Target Subsystem

SDLC, Git & PR Governance (.pre-commit-config.yaml, src/devops_cli/config/constants.py, CONTRIBUTING.md, ADR 0014).

Existing Tool Considered

pre-commit 4.6.2 keys (files, types, stages, minimum_pre_commit_version), ast-grep file arguments, uv run --no-sync and the devops ci rows. The change is configuration only. Rejected: prek (it saves 0.4-0.6 s for each commit after this change, and it is a 0.x tool in the commit gate of the Job). Cost (estimate): about 200,000 tokens and half a day to build, near 0 to keep.

Acceptance Criteria

  • The commit stage on the same 3 Python files takes at most 2 s at a load under 12 (4.4 s today).
  • The pre-push rows take at most 20 s warm on 16 CPUs and 25 s on 2 CPUs (11.6 s and 16.5 s measured).
  • The structural test of feat(ci): devops ci ends each row at a time limit #4775 passes: the gate fetch (20 s) plus the rows (60 s) plus the workflows hook (30 s) plus the start time is under 120 s.
  • The Job runs constructs once for each push.
  • pre-commit run --all-files passes on main after the change.

Dependencies

#4670, #4775. Related: #4635.

Source: #4771

Alternatives check of 2026-11-14: not-applicable.
Class: perf, no search.
Tool: none found.

Proposed design

Problem statement

The commit hooks are slow: ast-grep-scan scans all of src and tests, and ast-grep-test runs at each commit. Ruff has two pins, and the pre-push stage runs only lint and format. This change scans only staged files, runs ast-grep-test only on rule changes, makes Ruff local with uv run --no-sync, and adds the fast static rows to pre-push within the existing 94 s timeout budget.

Acceptance criteria

Requirement: Staged ast-grep scan

The ast-grep-scan hook SHALL pass only the staged Python files under src/ and tests/ to ast-grep.

Scenario: Three staged Python files

  • WHEN uv run pre-commit run ast-grep-scan --files src/devops_cli/config/constants.py tests/roadmap/implement/test_roadmap_implement_scoped_ci.py tests/gate/construct_gate.py runs.
  • THEN The command exits 0 and its output names only the three given paths and no path outside them.

Requirement: Config-only ast-grep test

The ast-grep-test hook SHALL run only when .ast-grep/ or sgconfig.yml changes.

Scenario: Source-only commit

  • WHEN uv run pre-commit run ast-grep-test --files src/devops_cli/config/constants.py runs.
  • THEN The command reports (no files to check)Skipped for ast-grep-test and exits 0.

Requirement: Single Ruff pin

The ruff-check and ruff-format hooks SHALL be local hooks that run uv run --no-sync ruff, so uv.lock is the only Ruff pin.

Scenario: Ruff hook command

  • WHEN uv run pre-commit run ruff-check --files src/devops_cli/config/constants.py --verbose and uv run pre-commit run ruff-format --files src/devops_cli/config/constants.py --verbose run.
  • THEN Both commands exit 0 and their output shows uv run --no-sync ruff and no ruff-pre-commit rev.

Requirement: No-sync ast-grep hooks

The ast-grep-scan and ast-grep-test hooks SHALL run ast-grep with uv run --no-sync.

Scenario: Ast-grep hook command

  • WHEN uv run pre-commit run ast-grep-scan --files src/devops_cli/config/constants.py --verbose and uv run pre-commit run ast-grep-test --files sgconfig.yml --verbose run.
  • THEN Both outputs show uv run --no-sync ast-grep and no uv sync.

Requirement: OpenSpec gate timeout

The openspec-gate hook SHALL keep plain uv run and run timeout 90 uv run devops ci --only openspec.

Scenario: OpenSpec gate command

  • WHEN uv run pre-commit run openspec-gate --files src/devops_cli/config/constants.py --verbose runs.
  • THEN The output shows timeout 90 uv run devops ci --only openspec and contains no --no-sync and no --timeout.

Requirement: Hook configuration validation

The configuration SHALL set minimum_pre_commit_version to 4.4.0, use language: unsupported for local hooks, and keep pre-commit-hooks at v6.0.0.

Scenario: Config validation

  • WHEN uv run pre-commit validate-config runs.
  • THEN The command exits 0 and reports the configuration as valid.

Requirement: Default stage cleanup

The configuration MUST remove the stages: [pre-commit] lines that repeat the default stage.

Scenario: Default stage run

  • WHEN uv run pre-commit run --all-files runs.
  • THEN Every hook runs at its default stage and the command exits 0.

Requirement: Pre-push fast rows

The devops-ci-pre-push hook SHALL run timeout 40 uv run devops ci --check --only lint,format,constructs,swallowed-failures,deps,uv-check,domain and keep UV_MALWARE_CHECK=0.

Scenario: Pre-push row selection

  • WHEN uv run pre-commit run devops-ci-pre-push --hook-stage pre-push --files src/devops_cli/config/constants.py --verbose runs.
  • THEN The output shows the seven rows including domain, the timeout 40 prefix, and UV_MALWARE_CHECK=0.

Requirement: Workflows timeout

The devops-ci-workflows-pre-push hook SHALL use timeout 30.

Scenario: Workflows hook timeout

  • WHEN uv run pre-commit run devops-ci-workflows-pre-push --hook-stage pre-push --files .github/workflows/ci.yml --verbose runs.
  • THEN The output shows timeout 30 and the command exits 0.

Requirement: Push gate first

The push gate hook of #4670 SHALL stay the first pre-push hook.

Scenario: Pre-push hook order

  • WHEN uv run pre-commit run --hook-stage pre-push --files src/devops_cli/config/constants.py --verbose runs.
  • THEN The output lists the push gate hook before devops-ci-pre-push.

Requirement: Constructs once per push

The roadmap Job SHALL run constructs once for each push after constructs leaves CONST_ROADMAP_IMPLEMENT_SCOPED_ROWS.

Scenario: Scoped rows test

  • WHEN uv run pytest tests/roadmap/implement/test_roadmap_implement_scoped_ci.py -q runs.
  • THEN The test passes and asserts that constructs is not in CONST_ROADMAP_IMPLEMENT_SCOPED_ROWS.

Requirement: Pre-push budget

The sum of the pre-push hook timeouts and the 25 s outside-hook time MUST stay under the 120 s agent shell limit.

Scenario: Workflow contracts test

  • WHEN uv run pytest tests/invariants/test_workflow_contracts.py -q runs.
  • THEN The test passes and the sum of the branch-current, devops-ci-pre-push and devops-ci-workflows-pre-push timeouts plus 25 s is less than 120 s.

Requirement: Gate structural budget

The structural test of #4775 SHALL pass with the gate fetch, the rows, the workflows hook and the start time under 120 seconds.

Scenario: Gate structural test

  • WHEN uv run pytest tests/gate/construct_gate.py -q runs.
  • THEN The test passes and its measured total is under 120 seconds.

Requirement: All files pass

pre-commit run --all-files MUST pass on main after the change.

Scenario: All-files run

  • WHEN uv run pre-commit run --all-files runs on main after the change.
  • THEN Every hook passes and the command exits 0.

Requirement: Pending a person after the merge

A person SHALL verify the hook documentation and the timing budgets after the merge.

Scenario: Post-merge hook review

  • WHEN A person reviews CONTRIBUTING.md and ADR 0014 and runs the three-file commit and warm pre-push benchmarks after the merge.
  • THEN The documents name the new hooks, the commit stage takes at most 2 s at load under 12, and the pre-push rows take at most 30 s on 16 CPUs and 40 s on 2 CPUs.

Existing Tool Considered

The alternatives check of 2026-11-14 records not-applicable for this perf item and names no tool (see the alternatives block in the issue body). The change uses existing pre-commit, ast-grep-cli, uv and devops ci configuration. It builds no new code. The written build cost is zero tokens and zero elapsed time.

Key questions

  • How does the proposal handle the newer merged work that already changed the hook configuration?: Keep pre-commit-hooks at v6.0.0, keep the domain row and UV_MALWARE_CHECK=0, and update tests/gate/construct_gate.py for the new command. (best practice) [sources: .pre-commit-config.yaml, tests/gate/construct_gate.py:372-403, src/devops_cli/config/constants.py:4083, tests/roadmap/implement/test_roadmap_implement_scoped_ci.py]
    • Chosen: Adapt to current configuration. The reply shows v6.0.0, domain and UV_MALWARE_CHECK=0 are already merged. The change keeps them and updates the construct gate test.
    • Rejected: Use the older body state. It would downgrade v6.0.0 and drop the domain row and the malware-check setting.
  • Which files should ast-grep-scan receive at commit time?: Pass only the staged Python files under src/ and tests/. Set files to ^(src|tests)/, types to [python], and update the construct gate test. (best practice) [sources: .pre-commit-config.yaml, tests/gate/construct_gate.py:372-403, sgconfig.yml]
    • Chosen: Staged Python files under src/ and tests/. This cuts the whole-tree scan. ast-grep accepts file arguments, and the construct gate test changes with the hook.
    • Rejected: Whole src/ and tests/ tree. This scans unchanged files and keeps the slow commit stage.
  • When should ast-grep-test run?: Run it only when .ast-grep/ or sgconfig.yml changes. Set pass_filenames false and a files pattern for those paths. (best practice) [sources: .pre-commit-config.yaml, sgconfig.yml]
    • Chosen: Only on .ast-grep/ or sgconfig.yml changes. No rule changes on a source-only commit.
    • Rejected: Every commit. It adds a full test run to commits that do not change rules.
  • How should Ruff be pinned?: Use local hooks with uv run --no-sync ruff check and uv run --no-sync ruff format. uv.lock is the only pin. (best practice) [sources: .pre-commit-config.yaml, uv.lock]
    • Chosen: Local uv hooks with --no-sync. This removes the second pin and the drift.
    • Rejected: Keep the ruff-pre-commit rev. Two pins can differ and do not update together.
  • Should the ast-grep hooks use uv run --no-sync?: Yes. Run uv run --no-sync ast-grep and keep the existing UV_MALWARE_CHECK=0 setting. (best practice) [sources: .pre-commit-config.yaml]
    • Chosen: Use --no-sync. It removes the uv sync and its OSV malware query from the commit path.
    • Rejected: Keep plain uv run. A network fault can stop a commit.
  • Should openspec-gate keep plain uv run?: Yes. Keep plain uv run and prefix the command with coreutils timeout 90: timeout 90 uv run devops ci --only openspec. Do not use --timeout. (best practice) [sources: .pre-commit-config.yaml, tests/invariants/test_workflow_contracts.py]
    • Chosen: Keep plain uv run with coreutils timeout 90. The gate must use the devops of the worktree or the main venv as it does today, and devops ci has no --timeout option.
    • Rejected: Use --no-sync. It can run the wrong devops in a worktree with no synced venv.
    • Rejected: Use --timeout 90. devops ci has no --timeout option, and the invariant test rejects flags absent from devops ci.
  • Should constructs leave CONST_ROADMAP_IMPLEMENT_SCOPED_ROWS?: Yes. Remove constructs from the constant because the pre-push hook runs it once for each push. (best practice) [sources: src/devops_cli/config/constants.py:4083, tests/roadmap/implement/test_roadmap_implement_scoped_ci.py, .pre-commit-config.yaml]
    • Chosen: Remove constructs from scoped rows. The pre-push row runs constructs once. The Job must not run it again.
    • Rejected: Keep constructs in scoped rows. The Job would run constructs twice for each push.
  • Which rows should the pre-push stage run, and with what timeout?: Run lint,format,constructs,swallowed-failures,deps,uv-check,domain with coreutils timeout 40 and UV_MALWARE_CHECK=0. Keep the workflows hook at timeout 30 and the push gate first. (best practice) [sources: .pre-commit-config.yaml, docs/adr/0014-required-checks-gate-the-merge-and-the-pre-push-hook-runs-the-fast-static-checks.md, tests/invariants/test_workflow_contracts.py:218-239]
    • Chosen: Seven fast rows including domain with timeout 40. The domain row is security-critical and already in the pre-push hook. The other rows caught six agent failures in 14 days. The sum of timeouts stays at 94 s, and 94 + 25 = 119 < 120.
    • Rejected: Six rows without domain. It would drop the security-critical domain row.
    • Rejected: Use --timeout 60. devops ci has no --timeout option, and 60 + 24 + 30 + 25 = 139 >= 120 fails the pre-push budget test.
  • Is pre-commit-hooks v6.0.0 a change in this issue?: No. The repository already has v6.0.0. The change keeps it and does not downgrade. [sources: .pre-commit-config.yaml]
  • Which documents and tests must change with the hooks?: Update CONTRIBUTING.md, the local-runs line of ADR 0014, tests/gate/construct_gate.py, and tests/roadmap/implement/test_roadmap_implement_scoped_ci.py. (best practice) [sources: CONTRIBUTING.md, docs/adr/0014-required-checks-gate-the-merge-and-the-pre-push-hook-runs-the-fast-static-checks.md, tests/gate/construct_gate.py:372-403, tests/roadmap/implement/test_roadmap_implement_scoped_ci.py]
    • Chosen: Update docs and both tests. The hook list, the construct gate command and the scoped rows must match the new config.
    • Rejected: Change only .pre-commit-config.yaml. The docs and tests would state the old hooks.
  • How does the proposal stay within the pre-push timeout budget?: Keep devops-ci-pre-push at timeout 40, branch-current at timeout 24, and devops-ci-workflows-pre-push at timeout 30. The sum is 94 s, and 94 + 25 = 119 < 120. (best practice) [sources: tests/invariants/test_workflow_contracts.py:218-239, .pre-commit-config.yaml]
    • Chosen: Keep the current 94 s sum. The invariant test requires the sum plus 25 s to be under 120 s. The current hooks already use the full budget.
    • Rejected: Raise devops-ci-pre-push to 60 s. 60 + 24 + 30 + 25 = 139 >= 120 fails the test, and lowering the threshold is forbidden.
  • How does the proposal replace the invalid --timeout flag?: Prefix each command with coreutils timeout <N>, such as timeout 40 uv run devops ci ... or timeout 90 uv run devops ci .... Do not pass --timeout to devops ci. (best practice) [sources: tests/invariants/test_workflow_contracts.py, .pre-commit-config.yaml]
    • Chosen: Use coreutils timeout prefix. devops ci has no --timeout option, and the invariant test rejects flags absent from devops ci.
    • Rejected: Use --timeout 60. devops ci has no --timeout option.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    on Nov 11, 2026
  2. added
    type/infra
    scope/ci
    status/new
    value/medium
    effort/medium
    on Nov 11, 2026
  3. dan-petty commented on Nov 11, 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/infra. The perf prefix of the title gives the type.
    • Scope: scope/ci. The (ci) scope of the title gives the scope.
    • Priority: P2-Medium. Improves hook speed and adds pre-push checks, but the system is functional today and no user is blocked.
    • Value: Medium. Cuts commit-hook time from 4.4 s to under 2 s and catches constructs and deps failures before push.
    • Effort: Medium. Configuration-only edits to .pre-commit-config.yaml, one constant, and docs; estimated half a day.
    • Related: feat(ci): fast execution caching when unchanged & pre-commit file change tracking integration #256, which asks for a different change. Both make pre-commit and pre-push checks faster, but #256 adds a caching engine while this candidate scopes existing hooks to staged files and adds new pre-push rows.
  4. added
    priority/p2-medium
    on Nov 11, 2026
  5. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    More evidence for the --no-sync item of this issue.

    On 2026-11-11, a commit in a worktree failed in the ast-grep-scan hook. The hook runs uv run ast-grep scan .... With UV_MALWARE_CHECK=1, the sync of uv run sends a query to OSV, and the DNS lookup failed:

    ast-grep scan (network constructs and working-directory reads in src, elapsed-time bounds in tests).......................Failed
    - hook id: ast-grep-scan
    - exit code: 2
    
    error: Malware check failed due to an error from OSV
      cause: Request failed after 3 retries
      cause: error sending request for url (https://api.osv.dev/v1/querybatch)
      cause: dns error
    

    The same commit passed at the second try. So a fault of the network stops a commit. uv run --no-sync in the ast-grep hooks, as this issue plans, removes the sync and its query. #1667 made the same change for the structural-invariants hook.

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

    @devops-cli-service
    Contributor

    Alternatives check: not-applicable

    Class: perf. The check makes no search and no model call for an item of this class.

    Tool: none found

    Checked on 2026-11-14. A person decides what this means for the item. The check changes no label and closes no issue.

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

    @devops-cli-service
    Contributor

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

  9. dan-petty commented on Nov 28, 2026

    @dan-petty
    OwnerAuthor

    Premise conflict: newer merged work (#4881, #5295, and v6.0.0) changed .pre-commit-config.yaml and tests/gate/construct_gate.py. Specifically: (1) tests/gate/construct_gate.py:372-403 asserts ast-grep-scan exact command ['uv', 'run', 'ast-grep', *CONST_AST_GREP_SCAN_ARGS] (which includes 'src tests'), rejecting --no-sync and staged-file-only args; (2) #5295 added the security-critical 'domain' row to devops-ci-pre-push, whereas the proposed row list omits 'domain'; (3) #4881 added 'env UV_MALWARE_CHECK=0'; and (4) pre-commit-hooks is already v6.0.0.

  10. 4 remaining items

  11. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  12. dan-petty commented on Nov 29, 2026

    @dan-petty
    OwnerAuthor

    Returning #4776 to status/new with evidence (AGENTS.md rule 2: cannot be built as specified):

    1. Nonexistent --timeout CLI option: Requirements OpenSpec gate sync, Pre-push fast rows, and Workflows timeout specify running uv run devops ci ... --timeout 60 / --timeout 90 / --timeout 30. uv run devops ci --help has no --timeout option; #5031 (1fa4e9cdb, closes #4775) deliberately rejected --timeout in favor of coreutils timeout <N>, and tests/invariants/test_workflow_contracts.py (test_every_devops_command_the_workflows_actions_and_hooks_run_resolves & test_the_pre_push_hooks_end_before_the_agent_shell_limit) rejects flags absent from devops ci and requires timeout <N>.
    2. Exceeds the #4775 / #6190 pre-push timeout budget: tests/invariants/test_workflow_contracts.py:218-239 requires sum(pre-push timeouts) + PUSH_OUTSIDE_HOOKS_SECONDS (25) < AGENT_SHELL_LIMIT_SECONDS (120) (cap 94 s). Current origin/main already uses the full budget: branch-current (timeout 24, #6190) + devops-ci-pre-push (timeout 40) + devops-ci-workflows-pre-push (timeout 30) = 94 s (119 s < 120 s). A 60 s budget for devops-ci-pre-push plus 24 s + 30 s + 25 s = 139 s >= 120 s, failing test_the_pre_push_hooks_end_before_the_agent_shell_limit without lowering the threshold (forbidden by AGENTS.md rule 5).

    Please re-refine #4776 around coreutils timeout limits within the 94 s pre-push sum (for instance, keeping timeout 40 after checking 2-CPU runtime margin — measured 24.38s real / 22s gate elapsed for all 7 rows on idle 16 CPUs — or splitting commit-stage hook speedups from pre-push row additions).

  13. added
    status/new
    and removed
    status/ready
    on Nov 29, 2026
  14. added
    status/ready
    and removed
    status/new
    on Nov 29, 2026
  15. devops-cli-service commented on Nov 29, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  16. added
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 29, 2026
  17. removed
    status/in-review
    on Nov 29, 2026
  18. devops-cli-service commented on Nov 29, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-29 16:50 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/p2-mediumscope/cisource/agenttype/infravalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions