Repository navigation
Description
Problem
Profiling one devops roadmap refine plan with five model requests showed load_settings called 31 times. track_request_spend calls pricing.is_local, whose _is_local_host re-reads settings about ten times per plan, and the SQLite spend ledger opens and closes a connection per request. That adds an estimated 50-100 ms to every model request, and to every test that drives an AI client, which counts against the 5-minute devops ci budget.
Proposed remedy
Resolve settings once per request and pass the resolved values down the spend path (or read them from the settings object the client already holds). Keep one ledger connection per process or per client, with the locking the ledger already uses.
Acceptance criteria
- One refine plan with five requests resolves settings at most once per request, measured the way the profile above was (a profile or a count at the settings-file read, not a patched devops-cli function).
- Spend records and their tests are unchanged.
- Tests are offline, each call phase stays under 1 s, and
uv run devops cipasses.
Found while delivering #1363. Related: #1363.
Proposed design
Problem statement
The spend pricing path calls load_settings multiple times per LLM request. A five-request plan calls it 31 times. The SQLite spend ledger opens and closes a connection per request. This adds 50-100 ms to every model request and to every test that drives an AI client. The extra time counts against the 5-minute devops ci budget.
Acceptance criteria
- Criterion 1: One refine plan with five requests resolves settings at most once per request.
Verification: Run a profile or a count at the settings-file read. The count must be at most 5 for five requests. Do not patch a devops-cli function. - Criterion 2: Spend records and their tests are unchanged.
Verification: Runuv run devops ci test tests/test_ai_spend_pricing.py. All tests pass with the same assertions. - Criterion 3: Tests are offline and each call phase stays under 1 s.
Verification: Runuv run devops ci. All tests pass. No test requires network access. Each call phase completes in under 1 s.
Key questions
- Where in the spend path is
load_settingscalled?:_is_local_hostinsrc/devops_cli/ai/spend/pricing.py:213reads settings.is_localat line 236 calls it.track_request_spendinsrc/devops_cli/ai/spend/ledger.pycallspricing.is_local. [sources: src/devops_cli/ai/spend/pricing.py:213, src/devops_cli/ai/spend/pricing.py:236, openspec/changes/archive/2026-10-24-1019-spend-ledger-failed-gateway-attempts/design.md] - Should settings be passed down the spend path or read from the client's existing settings object?: Read from the settings object the client already holds. This avoids changing function signatures and keeps the change small. (proposed)
- Should the ledger connection be per-process or per-client?: Keep one connection per client. The ledger already uses locking, so a per-client connection is safe and simpler than a per-process one. (proposed)
- How should the measurement work without patching
load_settings?: Use a profile or a count at the settings-file read.docs/TESTING.md:107states that no test patchesload_settingsorCONFIG_PATH. [sources: docs/TESTING.md:107]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsReady
- StatusShow more project fieldsNew
Activity
dan-petty-bot commentedon Oct 8, 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.
It saves 50-100 ms per request and eases the CI budget, but nothing is broken and no user-facing defect results.Reduces per-request latency and CI time for every AI client interaction, but the feature already works correctly without it.The fix is scoped to resolving settings once per request and reusing a single ledger connection, with clear acceptance criteria and no API changes.dan-petty commentedon Oct 26, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.
This is a performance issue that affects CI time and test execution speed.Improving performance for AI requests benefits all users of the CLI and CI system.It requires refactoring how settings are loaded and passed down, which is moderately complex.Both items are about AI spend tracking, but the candidate focuses on performance optimization and settings resolution while #1668 concerns dashboard telemetry.dan-petty commentedon Oct 28, 2026
Status set to Ready at d509dba (see proposed design in issue body).
chore(main): release 0.12.0 (#2552)