Skip to content

perf(config): roadmap.decisions imports pydantic_ai at load #4501

Closed

Description

@dan-petty

Problem Description

When roadmap.decisions is not empty, the validator _check_decisions of the settings (src/devops_cli/config/settings.py, RoadmapConfig) imports devops_cli.roadmap.decision_registry. The registry imports devops_cli.roadmap.decision_point and devops_cli.roadmap.stage.stage_jev_screen. Both import pydantic_ai.models.decision at module level. Thus a light devops command that reads a config with this key loads pydantic_ai and about 590 more modules, and it starts 4 to 7 s slower.

k8s/devops/configmap.example.yaml now holds roadmap.decisions: {stage.verify_screen: shadow}, and devops k8s deploy-stack renders it into ConfigMap devops-cli-config. The runner Jobs set DEVOPS_CLI_CONFIG=/config/devops-cli.yaml, so each devops child command of an implement step pays this cost. The Service and the MCP server pay it at each start.

The startup-imports row of devops ci (tests/gate/startup_imports.py) runs with a config that does not hold the key, so it does not find the cost.

The review of PR #4453 found this problem (major).

Reproduction Steps

  1. On main, write two config files: no-decisions.yaml with ai: {provider: gateway}, and with-decisions.yaml with the same ai section and roadmap: {decisions: {stage.verify_screen: shadow}}.
  2. For each file, run DEVOPS_CLI_CONFIG=<file> python -X importtime -c 'from devops_cli.entry import main; main()' config get ai.provider.
  3. Count the import time: lines and look for pydantic_ai.

Expected vs Actual Behavior

Expected: the key roadmap.decisions does not change what a light command imports. The command imports no pydantic_ai.

Actual (main at 0ac2f76, three runs each without -X importtime):

Config Modules pydantic_ai Wall time
no roadmap.decisions 816 no 4.0 s, 4.8 s, 5.3 s
roadmap.decisions set 1403 yes 8.5 s, 9.1 s, 12.3 s

Fix, one of these:

  1. Check the settings against a light table of point names and cuts paths that imports no pydantic_ai, for example a map of name to cuts path in a small module. Add a test that REGISTRY gives the same names and paths as the table.
  2. Make decision_point.py and stage_jev_screen.py import the question types of pydantic_ai.models.decision only when a point asks the model.

Then add a case with roadmap.decisions set to the startup-imports gate, so that a return of the cost fails the gate.

Environment Diagnostics

main at 0ac2f76, which holds the merge of PR #4453 (b73e97a). Python of the repository .venv.

Logs, Traces, or Terminal Output

import time:     10326 |    4072471 |         pydantic_ai
import time:     50284 |    4123740 |     pydantic_ai.models.decision
import time:     62652 |    4301104 |   devops_cli.roadmap.decision_point
import time:     18211 |      28103 |   devops_cli.roadmap.stage.stage_jev_screen
import time:      3158 |    4332364 | devops_cli.roadmap.decision_registry

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. perf(cli): cut the CPU time of the startup-import row by half #3550 is about the CPU time of the startup-imports row and is a different problem.

Source: #4453

Proposed design

Problem statement

A config that sets roadmap.decisions makes a light devops command import pydantic_ai. The settings validator imports the decision registry, and the registry imports point modules that load pydantic_ai.models.decision. The command loads about 590 more modules and starts 4 to 7 s slower. The startup-imports gate does not set the key, so it misses the cost. The change validates the key from a light table and adds a gate probe.

Acceptance criteria

Requirement: Light decision validation

The settings validator SHALL validate roadmap.decisions without importing devops_cli.roadmap.decision_registry or pydantic_ai.

Scenario: A config with a decision point loads

  • WHEN A test loads settings in a fresh interpreter from a config file that sets roadmap.decisions: {stage.verify_screen: shadow}.
  • THEN The test asserts that pydantic_ai is not in sys.modules after the load.

Requirement: Point table matches registry

The light table of point names and cuts paths MUST give the same names and paths as REGISTRY.

Scenario: The table and registry are compared

  • WHEN A test imports the light table and devops_cli.roadmap.decision_registry.REGISTRY.
  • THEN The test asserts that the names and cuts paths are equal.

Requirement: Unknown point refused

The settings validator SHALL refuse a roadmap.decisions key that names no registered point.

Scenario: An unknown point is set

  • WHEN A test loads settings with roadmap.decisions: {stage.unknown: shadow}.
  • THEN The test asserts a validation error that names the unknown point.

Requirement: On requires cuts

The settings validator SHALL refuse on for a point whose fitted cuts file is absent.

Scenario: An on point has no cuts file

  • WHEN A test loads settings with roadmap.decisions: {stage.verify_screen: on} and the table names a cuts path that does not exist.
  • THEN The test asserts a validation error that names the point and the missing cuts file.

Requirement: Startup gate covers decisions

The startup-imports gate SHALL run a probe with roadmap.decisions set and MUST fail when that probe imports pydantic_ai.

Scenario: The decisions probe runs

  • WHEN The gate runs devops config get ai.provider in a fresh interpreter with a config file that sets roadmap.decisions.
  • THEN The probe fails if pydantic_ai is in the imported modules.

Existing Tool Considered

No alternatives check has run. No open, maintained tool or library covers this need: the change is an internal import boundary in this project. The change builds its own code: about 3,000 tokens to build, 1,000 tokens to keep and fix, and 2 hours of elapsed time.

Key questions

  • Which fix removes the eager pydantic_ai import from roadmap.decisions validation?: Use a light table of point names and cuts paths in a small module. RoadmapConfig._check_decisions reads the table and never imports REGISTRY or the point modules. A test keeps the table equal to REGISTRY. (best practice) [sources: src/devops_cli/config/settings.py:1379, src/devops_cli/roadmap/decision_registry.py, tests/gate/startup_imports.py]
    • Chosen: Light point table. It removes the registry import from settings and needs no pydantic_ai at validation. One sync test controls the duplicated data.
    • Rejected: Lazy imports in point modules. It keeps the settings dependent on every point module and on each module staying free of eager imports.
    • Rejected: No change. It leaves the 4 to 7 s startup cost and the gate gap.
  • What causes the eager pydantic_ai import when roadmap.decisions is set?: RoadmapConfig._check_decisions imports devops_cli.roadmap.decision_registry. The registry imports decision_point and stage.stage_jev_screen, and both import pydantic_ai.models.decision at module level. [sources: src/devops_cli/config/settings.py:1379, src/devops_cli/roadmap/decision_registry.py, src/devops_cli/roadmap/decision_point.py, src/devops_cli/roadmap/stage/stage_jev_screen.py]
  • How does the light table keep the on cuts check?: The table maps each point name to its cuts path. The validator refuses on when that path is absent. A test compares the table with REGISTRY. (best practice) [sources: src/devops_cli/config/settings.py:1379, src/devops_cli/roadmap/decision_registry.py]
    • Chosen: Name-to-cuts table. It keeps the current validation of a key and of on without importing the point modules.
    • Rejected: Names only. It would lose the on cuts check that the settings have today.
  • Where should the regression check for the startup cost live?: Add a probe to tests/gate/startup_imports.py. The probe writes a config with roadmap.decisions, sets DEVOPS_CLI_CONFIG, runs devops config get ai.provider in a fresh interpreter, and fails if pydantic_ai is imported. (best practice) [sources: tests/gate/startup_imports.py, src/devops_cli/config/settings.py:1379]
    • Chosen: Startup-imports probe. It is the gate that must fail when the cost returns.
    • Rejected: Unit test only. A unit test does not guard the startup budget of the command.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/infra
    scope/config
    status/new
    value/high
    effort/medium
    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: scope/config. The (config) scope of the title gives the scope.
    • Priority: P2-Medium. It adds 4 to 7 s to every light devops command, the Service, and the MCP server, but does not break functionality. The regression commit b73e97a 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.
    • Value: High. Every child command of an implement step and each service start pays the 4 to 7 s penalty.
    • Effort: Medium. Two small fixes are described (light name table or lazy import) plus one test case in the startup-imports gate.
    • Related: fix(cli): cli start-up imports no telemetry when the bridge is off, and timing tests stop asserting host speed #858, which asks for a different change. Both reduce unnecessary CLI startup imports, but #858 targets telemetry imports and this targets the pydantic_ai import chain from roadmap.decisions.
  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 453aed0 (see proposed design in issue body).

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

    @devops-cli-service
    Contributor
  9. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-11 14:13 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/configsource/agenttype/infravalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions