Skip to content

fix(ai): local savings use one reference price per request kind for every process, and an unknown model or reference warns instead of pricing at $0 #1672

Closed

Description

@dan-petty

Friction

  • Each process prices its local tokens against its own ai.reference_model, and the savings counter carries no reference label. The dashboard adds workstation savings priced at gpt-4o to roadmap-service savings priced at gpt-4o-mini.
  • Over 30 days roadmap-service shows $1.78 where gpt-4o pricing gives $29.69. The 30-day "Local Cloud Savings" is about $28 low on a gpt-4o basis, or the workstation part about 16.7x high on a gpt-4o-mini basis.
  • A reference model genai-prices does not know, such as the typo gpt-4o-mni, makes every local request's savings $0 with no warning.
  • A hosted model genai-prices does not know is stored at $0 with source "unknown", and nothing records that it went unpriced.
  • No effect in the last 24 h, when only the workstation emitted. Any range that includes Service activity mixes the two prices.

Evidence

Checked at main 3dd7fa6 (v0.2.36) on 2026-10-17, read-only. genai-prices 0.1.9 queried offline from its bundled snapshot.

  • _emit_local_cost_equivalent (src/devops_cli/ai/spend/ledger.py:601-617) resolves the reference inside the emitting process through SpendLedger._resolve_reference_model (:341-351), from settings.ai.reference_model.
  • The default is gpt-4o-mini (src/devops_cli/config/defaults.py:65). The emitted labels are provider, model, server and backend (ledger.py:700-705). Nothing is emitted when the result is 0 (:616).
  • The workstation's runtime config sets reference_model: gpt-4o. k8s/devops/configmap.example.yaml sets none, so the Service uses the default.
  • Live 30 d: savings divided by tokens at gpt-4o rates is about 1.00 for current workstation instances and 0.060 (0.15/2.5 = 0.6/10) for all 19 roadmap-service pods.
  • get_pricing falls back to ModelPricing(0, 0, source="unknown") (src/devops_cli/ai/spend/pricing.py:439-446). The ledger has no pricing-source column (ledger.py:33-51).
  • AIConfig.reference_model is an unvalidated str (src/devops_cli/config/settings.py:459).
  • Offline probe: gpt-4o-mni and gpt-9-preview resolve to 0/0 "unknown"; gpt-4o resolves to $2.50/$10.00 per million tokens.
  • src/devops_cli/ai/spend/models.py:148 and :173 hard-code "gpt-4o-mini" instead of DEFAULT_AI_REFERENCE_MODEL.

Remedy

Tests first, in tests/test_ai_spend_pricing.py, tests/test_ai_spend_ledger.py and tests/test_k8s_monitoring_dashboards.py, using genai-prices' bundled snapshot. No network:

  • Two processes configured with different ai.reference_model values produce savings the dashboard prices with one reference.
  • An unknown ai.reference_model or ai.reference_embedding_model logs one warning naming it, and devops ai cost says the savings are unpriced instead of printing $0.
  • A hosted request whose model resolves to "unknown" logs one warning per model per process and stores pricing_source="unknown" in a new ledger column.
  • No "gpt-4o-mini" literal remains outside src/devops_cli/config/defaults.py.

Code, proposed design (owner decision below):

  • Price savings in one place, at query time. devops-cli records which tokens ran locally, as a local label on devops_cli_ai_tokens_total or a devops_cli_ai_local_tokens_total counter.
  • A recording rule in k8s/monitoring/prometheus-values.yaml holds the reference price per operation and token type. A test checks the committed prices against genai-prices for the default chat and embedding references, so they cannot drift.
  • The savings panels multiply tokens by price. AI_LOCAL_COST_EQUIVALENT_USD_TOTAL and _emit_local_cost_equivalent are removed in the same change. A changed reference then re-prices history, and every process agrees.
  • Interim, if the owner keeps client-side pricing: set ai.reference_model in the cluster ConfigMap (k8s/devops/configmap.example.yaml and the live one) to the workstation's value, and add a reference_model label the panels group by.
  • Check both reference settings against the pricing registry when devops ai cost and devops config show run. A warning, not a load error, so a registry update cannot break config loading.
  • Persist ModelPricing.source on each ledger row as pricing_source.
  • Replace the models.py literals with DEFAULT_AI_REFERENCE_MODEL.

Key question for the owner: which reference prices savings (gpt-4o as on the workstation, or the gpt-4o-mini default), and whether savings move to query time.

Depends on: the embedding-recording item, which adds ai.reference_embedding_model and the operation label.

Proposed: type/bug, P2-Medium.

Proposed design

Problem statement

The current implementation of local AI spend tracking uses different reference models per process, causing inconsistent savings calculations. When an unknown model is specified, it silently prices at $0 without warning. Additionally, the dashboard mixes savings from different processes priced at different rates, making it difficult to interpret the actual cost savings.

Acceptance criteria

  • Criterion 1: Two processes configured with different ai.reference_model values produce savings that are priced consistently using one reference model
    Verification: Run tests in test_ai_spend_pricing.py, test_ai_spend_ledger.py and test_k8s_monitoring_dashboards.py using genai-prices' bundled snapshot to verify that savings from different processes are priced with a single consistent reference model.
  • Criterion 2: An unknown ai.reference_model or ai.reference_embedding_model logs one warning naming it, and devops ai cost shows unpriced savings instead of printing $0
    Verification: Verify that when an invalid reference model is configured, the system logs a warning message and displays 'unpriced' rather than zero cost in the devops ai cost output.
  • Criterion 3: A hosted request whose model resolves to "unknown" logs one warning per model per process and stores pricing_source="unknown" in a new ledger column
    Verification: Ensure that when a hosted model cannot be resolved, a warning is logged once per process and the ledger stores 'pricing_source' as 'unknown' for that record.
  • Criterion 4: No literal "gpt-4o-mini" remains outside src/devops_cli/config/defaults.py
    Verification: Search codebase to ensure no hardcoded "gpt-4o-mini" strings exist outside the defaults.py file, all references should use DEFAULT_AI_REFERENCE_MODEL.

Key questions

  • Which reference prices savings (gpt-4o as on the workstation, or the gpt-4o-mini default), and whether savings move to query time.: Based on the issue description, the decision is to use the gpt-4o model for pricing savings, matching the workstation's configuration. Savings will be priced at query time rather than client-side to ensure consistency. (proposed)
  • Should client-side pricing be kept or moved to query time?: The issue indicates that moving savings pricing to query time is preferred for consistency. Interim solution suggests setting ai.reference_model in the cluster ConfigMap to match workstation value. (proposed)

Fit

Needs splitting into 5 items:

  1. Move savings pricing from client-side to query time
  2. Implement unified reference model for all processes
  3. Add warning logs for unknown models
  4. Persist pricing source in ledger
  5. Remove hardcoded gpt-4o-mini literals

Suspected block

None.

Dependencies

#1673

Activity

  1. added
    source/agent
    type/bug
    on Oct 18, 2026
  2. dan-petty commented on Oct 18, 2026

    @dan-petty
    OwnerAuthor

    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.

    • Type: type/bug. The candidate describes a defect in how local AI savings are priced and reported.
    • Priority: P1-High. The defect causes significant misreporting of costs and savings, affecting financial accuracy.
    • Value: High. Correctly pricing local AI usage affects financial reporting and decision-making for users.
    • Effort: High. Fixing requires changes across multiple components including ledger, pricing, and dashboard logic.
  3. dan-petty commented on Oct 18, 2026

    @dan-petty
    OwnerAuthor

    Proposal needs splitting into 5 items at 25e2cda (see proposed design in issue body).

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

    source/agenttype/bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions