Skip to content

perf(test): stage gate tests parse every test file per call #4509

Closed

Description

@dan-petty

Problem Description

A test that calls check_proposal or check_gates with no registry argument makes the registry gate call registry_table(Path.cwd()). That function parses every test file of the repository with ast.parse (1,313 files). One call takes about 6 seconds, and the result is not kept between calls.

At least 18 test files in tests/roadmap/stage/ call check_proposal with no registry. For example, tests/roadmap/stage/test_roadmap_stage_trace_subject.py has 12 cases and takes about 50 seconds with -n0. With registry=[], the same call takes about 3 ms.

This adds minutes of CPU time to the test row, which #4405 measures against the 5 minute budget.

Reproduction Steps

  1. In a short script, build plan = make_stage_proposal() and time check_proposal(plan, ["comment-thread"], StagedTree(["src/devops_cli/sample.py"]), trace=TraceFacts()).
  2. Time it again with registry=[].

Expected vs Actual Behavior

Expected: a unit test of one gate does not parse the whole repository.

Actual: each call takes about 6 s (cProfile: registry_table 6.2 s, of which ast.parse 4.2 s in 1,313 calls).

Possible fixes: the tests pass registry=[] (or a fixture value) unless they test the registry gate, or registry_table keeps its result for a tree that did not change.

Environment Diagnostics

  • DevOps CLI: main at c653bde
  • Execution environment: DevContainer

Logs, Traces, or Terminal Output

first 6.85 s
second 6.18 s
registry=[] 0.0027 s

Pre-Submission Checklist

  • I have verified that no sensitive credentials, private keys, or internal tokens are contained in this issue report.
  • I have checked existing issues and pull requests to ensure this is not a duplicate.

Proposed design

Problem statement

The stage gate tests parse every test file of the repository on each call. check_proposal and check_gates call registry_table(Path.cwd()) when the caller passes no registry, and that function parses 1,313 test files with ast.parse. One call takes about 6 seconds, and the result is not kept. At least 18 test files in tests/roadmap/stage/ make this call, so the test row spends minutes of CPU time on work that no test needs.

Acceptance criteria

Requirement: Explicit registry in stage gate tests

Each test in tests/roadmap/stage/ that calls check_proposal or check_gates MUST pass a registry value, unless the test checks the registry gate.

Scenario: A gate test passes the empty registry

  • WHEN A test calls check_proposal with registry=[].
  • THEN The call returns the same problems as the same call with the table of the repository.

Requirement: Guard on the default registry

The conftest.py of tests/roadmap/stage/ MUST make a gate call with no registry raise an error that names the fixture.

Scenario: A gate test omits the registry

  • WHEN A test calls check_proposal or check_gates with no registry argument.
  • THEN The call raises AssertionError, the message names registry, and no test file is parsed.

Requirement: Registry gate tests keep the real table

Each test that checks the registry gate MUST pass the table from registry_table as the registry argument.

Scenario: The registry gate test builds the table

  • WHEN A registry gate test calls registry_table(Path.cwd()) and passes the result.
  • THEN The test reads the real entries, and the guard leaves the call alone.

Requirement: No parse of the tests tree from a gate call

A test MUST assert that check_proposal with registry=[] calls ast.parse zero times.

Scenario: The counter test runs

  • WHEN A test replaces ast.parse with a counter and calls check_proposal with registry=[].
  • THEN The counter reads zero, and the call returns the same problems as before.

Existing Tool Considered

No check has run. pytest covers the need, because the tests already use it and it gives fixtures and monkeypatch. It lacks a cheap registry_table, so the tests must pass the registry themselves. A cache inside registry_table instead costs about 15,000 tokens to build, keep and fix, and about half a day of elapsed time.

Key questions

  • Which fix removes the repeated parse: pass an explicit registry in the tests, or cache registry_table?: The tests pass an explicit registry. registry_table stays uncached, because a cache keyed by the root path serves a stale table after the tests tree changes. (best practice) [sources: openspec/changes/archive/2026-11-08-4057-cache-registry-table-in-stage-eval/design.md, src/devops_cli/roadmap/stage/stage_registry.py, src/devops_cli/roadmap/stage/stage.py]
    • Chosen: Pass the registry in each test. The archived design of change 4057 rejected a process-wide cache, and an empty list takes about 3 ms.
    • Rejected: Add functools.lru_cache to registry_table. The cache is keyed only by root and serves a stale table on a later round at the same path.
    • Rejected: Key the cache on a stat of the tests tree. It adds a staleness rule and code that the project keeps and tests.
  • Which value does the shared fixture return?: An empty list. A gate that reads no entry reports no problem, and a test that needs an entry builds that entry. (best practice) [sources: tests/roadmap/stage/test_roadmap_stage_registry.py, src/devops_cli/roadmap/stage/stage_registry.py]
    • Chosen: Empty list. The issue measures 3 ms with registry=[], and no stage gate test needs an entry that it does not build.
    • Rejected: A fixed table of the repository entries. It hides the input of the test and makes the test pass for a reason that it does not state.
  • How does the suite stop a new test from parsing the tests tree again?: An autouse fixture in the conftest.py of tests/roadmap/stage/ replaces registry_table in the stage call sites. The replacement raises AssertionError and names the registry fixture. (best practice) [sources: src/devops_cli/roadmap/stage/stage_change.py, src/devops_cli/roadmap/stage/stage_eval_gates.py, src/devops_cli/roadmap/stage/stage_paths.py]
    • Chosen: Autouse guard that raises. The failure names the fix at once, and the call costs no parse.
    • Rejected: No guard, and review catches the omission. The cost is invisible, because the test passes in about 6 seconds.
    • Rejected: A wall-clock limit on the stage suite. A shared runner makes a time limit flaky.
  • How does a test prove that the gate parses no test file?: A test replaces ast.parse with a counter and asserts zero calls from check_proposal with registry=[]. (best practice) [sources: tests/roadmap/stage/test_roadmap_stage_trace_subject.py]
    • Chosen: Count the calls of ast.parse. The count is exact and does not depend on the speed of the runner.
    • Rejected: Assert a wall-clock limit per call. A busy runner makes the assertion fail with no defect.
  • Which stage tests need the real registry table?: test_roadmap_stage_registry.py, test_roadmap_stage_eval_gates.py and test_roadmap_stage_split_gates.py call registry_table and keep the real table. [sources: tests/roadmap/stage/test_roadmap_stage_registry.py, tests/roadmap/stage/test_roadmap_stage_eval_gates.py, tests/roadmap/stage/test_roadmap_stage_split_gates.py]
  • Do check_proposal and check_gates accept a registry argument?: Yes. check_proposal takes a registry argument, and check_gates passes it to each gate. [sources: src/devops_cli/roadmap/stage/stage_change.py, openspec/changes/archive/2026-11-08-4057-cache-registry-table-in-stage-eval/design.md]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/infra
    source/agent
    status/new
    value/medium
    effort/low
    on Nov 11, 2026
  2. 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: none. The title has the scope test, and .github/labels.yml declares no scope/test label. Add the label to the file to give the scope to this item.
    • Priority: P2-Medium. It adds minutes to the CI test row against a 5-minute budget, but does not block delivery or affect users.
    • Value: Medium. It saves developer CI time and keeps the test row within budget, but does not change product behaviour.
    • Effort: Low. The fix is to pass registry=[] in test files or add a simple cache to registry_table.
    • Related: perf(roadmap): cache registry_table in stage eval replay #4057, which asks for a different change. Both hit the same expensive registry_table ast.parse loop, but #4057 cached it for the replay command while the candidate asks to fix the test-suite calls.
  3. added
    priority/p2-medium
    on Nov 11, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 11, 2026
  5. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

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

  6. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Scope from the CI audit (2026-11-11)

    The CI and test audit measured this cost again, and it adds a fix in the product code. Keep the explicit registry in the stage tests of the current design, and add the scope below.

    Problem (measured)

    • registry_table (src/devops_cli/roadmap/stage/stage_registry.py:88-101) runs ast.parse on each of 1,332 test modules on each call, with no cache. One call takes 2.04 s.
    • check_gates falls back to registry_table(Path.cwd()) (stage_change.py:2220-2223), and implement.py:417, plan_check.py:380, plan_recheck.py:359 and stage_eval_gates.py:551 pass no table.
    • The 985 tests that get to it use 11,023.6 s, which is 55.6% of the junit time of a local full run with per-test contexts. In CI, 29 of the 40 top-10 rows of run 43018712031 get to it (238.3 of 403.0 s).
    • A per-process cache cut tests/roadmap/implement from 2,534 s to 709 s of test time (-72%). Changed-Test Independence spent 181 of 205 s in 130 calls for 4 files.

    Added solution

    In counts_in, return () when the source text does not hold REGISTRY_COUNTS, before ast.parse. A module that declares the counts must hold the name, so the result does not change. Only 9 of 1,332 modules hold the token. Measured: 0.092 s per call (from 2.04 s), with the same 7 entries. This is not a cache, so nothing goes stale in the long-lived Service. It agrees with the rejected cache of the current design.

    Added acceptance criteria

    • registry_table on the repository takes 0.2 s or less (from 2.04 s) and gives the same entries.
    • A unit test shows that a module with the token only in a comment gives no entry.
    • tests/roadmap/implement with -n 6 and no coverage takes 900 s of test time or less (from 2,534 s).
    • Over 5 PR runs, the sum of shard pytest times falls by 20% or more (from 1,162 s), and the Changed-Test Independence maximum is 300 s or less (from 614-685 s).

    Saving

    Estimated 22-47% of each Tests & Coverage shard (100-170 s on the 317-371 s shards), the same share of each Service Image Tests shard, about 16 runner-min per push at a 35% cut, and 40-50% of the local full test row.

    Items that wait for this item

    #4695 (the production callers pass the table of the judged checkout), #4722 and #4250 (the shard balance). #4473 (more shards) closes as not planned in favor of this item.

  7. added
    owner/agent
    status/in-progress
    and removed
    status/ready
    on Nov 11, 2026
  8. removed
    status/in-progress
    owner/agent
    on Nov 11, 2026
  9. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-11 19:36 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/lowpriority/p2-mediumsource/agenttype/infravalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions