Skip to content

feat(cli): stage-attributed spend ledger and one genai-prices price source #594

Closed

Description

@dan-petty

Context & Rationale

The ledger stores provider, served_by, model, tokens and cost per call (src/devops_cli/ai/spend/ledger.py:24-40) but not what the call was for: request_type holds transport labels (src/devops_cli/ai/client/unified.py:449, src/devops_cli/ai/direct.py:124) and AIConfig.for_task keeps no task name (src/devops_cli/config/settings.py:408-429). LLMRouter serves only the advisory devops ai route (src/devops_cli/commands/ai.py:1350); only tests call GatewayRouter.resolve_model. devops ai harness offload passes frontier_tokens=0 and prints 100%, target met, with no model call (src/devops_cli/commands/ai_harness.py:79-107). ai_spend_report and resource://ai/spend pass --group-by, which devops ai cost report rejects (src/devops_cli/ai/mcp/server.py:2831-2857). Prices disagree across the router (src/devops_cli/ai/router.py:249-252), the ledger's hand-kept dict (src/devops_cli/ai/spend/pricing_data.py:67) and an unpinned LiteLLM fetch (src/devops_cli/config/defaults.py:366); genai-prices is installed via pydantic-ai-slim but nothing imports it. vibes' 80/20 split and 85%+ savings cite no method or data.

Scope & Deliverables

  • Context & Rationale*: The ledger stores provider, served_by, model, tokens and cost per call (src/devops_cli/ai/spend/ledger.py:24-40) but not what the call was for: request_type holds transport labels (src/devops_cli/ai/client/unified.py:449, src/devops_cli/ai/direct.py:124) and AIConfig.for_task keeps no task name (src/devops_cli/config/settings.py:408-429). LLMRouter serves only the advisory devops ai route (src/devops_cli/commands/ai.py:1350); only tests call GatewayRouter.resolve_model. devops ai harness offload passes frontier_tokens=0 and prints 100%, target met, with no model call (src/devops_cli/commands/ai_harness.py:79-107). ai_spend_report and resource://ai/spend pass --group-by, which devops ai cost report rejects (src/devops_cli/ai/mcp/server.py:2831-2857). Prices disagree across the router (src/devops_cli/ai/router.py:249-252), the ledger's hand-kept dict (src/devops_cli/ai/spend/pricing_data.py:67) and an unpinned LiteLLM fetch (src/devops_cli/config/defaults.py:366); genai-prices is installed via pydantic-ai-slim but nothing imports it. vibes' 80/20 split and 85%+ savings cite no method or data.
  • Deliverable*: (1) Ship alone, first: delete TokenSavingsSummary, is_target_met and both "Token Savings" rows (src/devops_cli/commands/ai_harness.py:105,237), report files scanned and matches instead, and restate 85%+ in ROADMAP principle 5 and src/devops_cli/ai/harness/slots.py:6 as an unmeasured target with no replacement figure. (2) Add a nullable stage column in place, as served_by was (src/devops_cli/ai/spend/ledger.py:51-53), filled from a ContextVar scope like completion_cap (src/devops_cli/ai/client/network.py:55) set inside the review.file_review and review.verification spans (src/devops_cli/ai/review/pipeline.py:1723,2251), falling back to the ai.tasks.<task> name passed to LLMClient, through all track_request_spend sites. Add --by stage to devops ai cost and devops ai cost report (calls, tokens, cost side by side); point the MCP tool and resource at --by. (3) Make genai-prices the only lookup behind PricingRegistry.get_pricing, declared directly, with update-pricing using its updater; retire the dict, the LiteLLM fetch and DEFAULT_MODEL_PRICING (src/devops_cli/ai/router.py:253, src/devops_cli/ai/agents/embeddings.py:171). Local calls cost nothing unless devops ai cost set-price says otherwise. Add cost_usd to the call-observer payload (src/devops_cli/ai/spend/ledger.py:467-477) and ReviewProfile. (4) Then delete LLMRouter, devops ai route and GatewayRouter.resolve_model, moving TaskComplexity; wire one selector on the AITasksConfig vocabulary only if the ledger shows misrouted calls.
  • Constraint*: Mislabelled rows are worse than none: an unset scope records the task name or NULL, shown as unattributed. for_task accepts unknown names silently (src/devops_cli/config/settings.py:410), so record only AITasksConfig fields. Never record local AST work as spend. Step (3) lowers devops ai cost report totals and the Review, findings and AI spend metrics reach Prometheus #564 spend metrics for local calls; announce it. An all-hosted counterfactual prices the same tokens at one configured reference model on read, never stored. Any surviving selector keeps the per-role floors (src/devops_cli/ai/capability.py:47) and keeps security-critical work local. Port nothing from vibes' router or leaderboard.
  • Measured*: uv run python -c "from devops_cli.ai.harness.slots import TokenSavingsSummary as T; print(T.calculate(frontier_tokens=0, offloaded_tokens=14))" prints savings_percentage=100.0. One million qwen2.5-coder:7b prompt tokens cost 0.15 USD in the ledger table (uv run python -c "from devops_cli.ai.spend.pricing_data import DEFAULT_INDUSTRIAL_MODEL_PRICING as D; print(D['qwen2.5-coder:7b'].calculate_cost(1_000_000, 0))") and 0.0 in the router (uv run python -c "from devops_cli.ai.router import LLMRouter; print(LLMRouter._estimate_cost(None, 'ollama', 'qwen2.5-coder:7b', 1_000_000))"). grep -rn "request_type" src --include='*.py' | grep -v "^src/devops_cli/ai/spend/\|request_type=" | wc -l prints 0.
  • Source*: vibes observations/devops-cli/05-harness-slots-and-subagent-offloading.md, vibes tools/model_router.py, vibes observations/systems/25-multi-model-capability-boundaries-and-dynamic-routing-oracles.md, vibes tests/test_model_router.py, vibes tools/model_leaderboard.py, vibes tools/subagent_orchestrator.py, vibes benchmarks/benchmark_runner.py, vibes benchmarks/README.md, vibes README.md, vibes observations/systems/21-hierarchical-subagent-slot-offloading-and-epistemic-loss.md, vibes observations/systems/20-internet-grounded-information-foraging-and-self-improvement-loops.md

Strategic Alignment

  • Milestone: v0.2.23 (devops ai Review Quality, LLM Routing & Multi-Language Validation)
  • Roadmap Reference: docs/ROADMAP.md

Activity

  1. added this to the v0.2.23 milestone on Sep 25, 2026
  2. added
    type/feature
    scope/cli
    priority/p0-critical
    on Sep 25, 2026
  3. dan-petty commented on Sep 27, 2026

    @dan-petty
    OwnerAuthor

    Closed by #631, merged into release/v0.2.23.

    GitHub only acts on closing keywords when a pull request merges into the default branch, so this was closed by devops gh issues close-merged.

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

    priority/p0-criticalscope/clitype/feature

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions