From 377ad56ffe4f0837ba2cb2ed912d7dd18bf6d5c1 Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Mon, 9 Nov 2026 17:42:58 +0000 Subject: [PATCH 1/2] feat(ai): a setting holds the price of a reference model --- docs/CONFIGURATION.md | 1 + k8s/README.md | 2 +- k8s/devops/configmap.example.yaml | 13 +- .../.openspec.yaml | 2 + .../design.md | 17 ++ .../proposal.md | 45 +++++ .../specs/ai-spend-pricing/spec.md | 34 ++++ .../specs/roadmap-service-deployment/spec.md | 12 ++ .../tasks.md | 24 +++ src/devops_cli/ai/spend/pricing.py | 34 +++- src/devops_cli/config/setting_keys.py | 25 ++- src/devops_cli/config/settings.py | 21 ++ .../spend/test_pricing_registry_overrides.py | 188 ++++++++++++++++++ tests/k8s/test_k8s_configmap.py | 14 ++ tests/k8s/test_k8s_configmap_keys.py | 9 + 15 files changed, 427 insertions(+), 14 deletions(-) create mode 100644 openspec/changes/4242-a-setting-holds-the-price-of/.openspec.yaml create mode 100644 openspec/changes/4242-a-setting-holds-the-price-of/design.md create mode 100644 openspec/changes/4242-a-setting-holds-the-price-of/proposal.md create mode 100644 openspec/changes/4242-a-setting-holds-the-price-of/specs/ai-spend-pricing/spec.md create mode 100644 openspec/changes/4242-a-setting-holds-the-price-of/specs/roadmap-service-deployment/spec.md create mode 100644 openspec/changes/4242-a-setting-holds-the-price-of/tasks.md create mode 100644 tests/ai/spend/test_pricing_registry_overrides.py diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md index 3884e2a88e..9844a35331 100644 --- a/docs/CONFIGURATION.md +++ b/docs/CONFIGURATION.md @@ -203,6 +203,7 @@ AI code review, multi-agent pipelines, RAG semantic search, and embeddings. | `reference_model` | `str` | `gpt-4o` | `DEVOPS_CLI_AI_REFERENCE_MODEL` | Hosted chat model whose genai-prices price values the local chat tokens in the AI spend reports | | `reference_embedding_model` | `str` | `text-embedding-3-small` | `DEVOPS_CLI_AI_REFERENCE_EMBEDDING_MODEL` | Hosted embedding model whose genai-prices price values the local embedding tokens in the AI spend reports | | `reference_provider` | `str` | `openai` | `DEVOPS_CLI_AI_REFERENCE_PROVIDER` | Provider in genai-prices of the two reference models | +| `price_overrides` | `dict` | `{}` | - | Price of a model that genai-prices does not know, by model name. A price in the file `pricing_overrides.json` of the data directory wins over the price here for the same model | | `hardware_cost_usd` | `float` | `0.0` | `DEVOPS_CLI_AI_HARDWARE_COST_USD` | Cost in USD of the local AI hardware, which `devops ai cost` compares with the savings | | `reasoning_effort` | `Union` | - | `DEVOPS_CLI_AI_REASONING_EFFORT` | AI reasoning effort level (low | medium | high) | | `supports_reasoning` | `bool` | `False` | - | - | diff --git a/k8s/README.md b/k8s/README.md index cf5909a92e..364604d3e6 100644 --- a/k8s/README.md +++ b/k8s/README.md @@ -687,7 +687,7 @@ kubectl -n devops logs -f job/ 17. Each repository has three lanes, and each lane runs one round at a time in its own clone (#1532, #1534). The status lane runs the rows `metrics`, `implement`, `stage_ready`, `release_comments`, `github_status` and `cloudflare_status` in the clone `clone`. The row `metrics` reads the project metrics. The rows `github_status` and `cloudflare_status` each read one status page, need no clone, and are due every 13 minutes and on a first run (#4052). A read that fails fails its own row: the row counts `error` in `devops_cli_service_jobs_total`, writes no stamp to `schedule.json`, and the alert `RoadmapServiceJobsFailing` names the row when every round of the row failed for 1 hour. The other rows are not affected. The triage lane runs the row `intake` in the clone `triage-clone`. The model lane runs the rows `refine`, `retitle`, `stage` and `alternatives` in the clone `model-clone`. The ConfigMap sets the same chat model for both lanes (item 19). A poll and a webhook go to all three lanes. The lanes share the file `schedule.json` of the repository, the ledger `service-failures.json` and the lock that each write of an item's job record takes (#2757). When intake places a critical fix or P0 item, it writes a `refine_due` timestamp to `schedule.json` so refinement becomes due in the next model-lane round; the timestamp is written even when the write of another candidate of the same round failed. An Item that a person changed between the plan and the write of intake is not a failed placement: nothing is written for it, the round does not fail, and the next round decides the candidate again (#4042). A `schedule.json` that exists and cannot be read fails the round with an error that names the file, and no row runs. A person repairs or removes the file; a removed file makes every row due once (#4042). The label `lane` of `devops_cli_service_jobs_total`, `devops_cli_service_job_seconds_total` and `devops_cli_service_queue_depth` is `status`, `triage` or `model`. The label `row` of `devops_cli_service_jobs_total` is the name of the row that ended, and the label `result` is `success`, `error` or `stopped` (the stop of the Service ended the row). The label `row` of `devops_cli_github_requests_total`, `devops_cli_service_job_suspended` and `devops_cli_service_job_retry_after_seconds` is the name of the row; the two gauges of the ledger have no label `lane`, as row names are unique. A model-lane round that has not ended does not delay a status-lane or triage-lane round. 18. The row `stage_ready` follows `implement` on the status lane (#2865). It calls no model and needs no clone. It is due every 3 minutes and on a first run. A round reads the open items whose record holds `stage.pr` and no `stage.ready` of the same number and no `implement.job`; with no such item it sends no request of its own, since the listing of the issues is the one that `metrics` and `implement` read in the round. For each such item it reads the pull request (`GET pulls/`). A pull request that is not an open draft is only recorded in `stage.ready`. An open draft goes to the function `draft_readiness` with its check runs (`GET commits//check-runs`): when every check ended and passed, the row marks the pull request ready with `gh pr ready` (the same function as the implement job) and records `stage.ready`. A draft with a failed, cancelled or running check, or with no check, stays a draft, and the row does not retry a check. The row reads only the pull request that the stage job recorded, and never the draft of a person. It reads the check runs and not the commit statuses, because the App token holds `checks: read` and no `statuses` permission. A draft that waits for its checks costs 2 requests a round (12 an hour) of `service.github_requests_per_hour`; a pull request that the row marks costs 2 more for `gh pr ready` and 2 to record it, once. A refusal of `gh pr ready` fails the round, names the item, and the ledger of failed rounds suspends the row after three rounds in a row: check that the App holds `pull_requests: write` and `contents: write` (ADR 0015). A pull request that the row marked ready is no longer a draft, so the implement job leaves its item until a person merges the plan and the item is Planned. The row counts under `row="stage_ready"` in `devops_cli_github_requests_total`. -19. The model of each stage comes from the settings `ai.tasks..model` of the ConfigMap `devops-cli-config` (#3155). The slot `analysis` serves the model lane: the stage job (planning), refine and the alternatives check. The slot `verification` names the model that reviews a plan; no code reads it before the verification pass of #3153 is built. The slots `chat` and `triage` and the default `ai.model` serve the other calls of the Service, such as intake and the retitle row. The slot `implement` serves every step of the implement job, and `roadmap.implement.ladder` names the same group as the one tier of each step class (#3573). By the owner decision of 2026-11-07 (#3874), the ConfigMap sets `deepseek-v4.1-flash-1017` for every chat slot but one: `ai.model`, `implement`, `verification`, `chat` and `triage`. The slot `analysis` is a trial by the owner decision of 2026-11-09 (#4204): it names `claude-sonnet-5-5` with `context_window` 200,000, because the stage job staged nothing with DeepSeek. A stage case costs about 0.27 USD (sample of #3566), and the stage row runs up to 3 items for each 37 minutes. The embedding slot stays `qwen3-embedding:0.6b`, because a chat model cannot embed. By the owner decision of 2026-11-09 (#4241), the ConfigMap also sets `ai.reference_model: qwen3.8:27b` and `ai.reference_embedding_model: qwen/qwen3-embedding-8b`, so the spend reports of the Service value local tokens at the hosted prices of those two models (0.035 USD input and 1.50 USD output, and 0.01 USD, per million tokens). genai-prices does not know both names, so the prices are overrides in the file `pricing_overrides.json` of the data volume of the Service; a new volume has none until `devops ai cost set-price` sets them again. The choice of slot models is temporary: undo it when most steps of the roadmap jobs work most of the time, and then name a model for each slot again. The prompts of intake and chat hold the titles and bodies of the issues of the repositories of the Service, and they leave the cluster to OpenRouter too (SECURITY.md rule 13). The window of `implement` is 256,000 tokens: the smallest that an fp8 provider of the group offers, where the group allows 1,048,576. A step has one tier, so a failure that selects `change_tier` ends the step; the item stops and waits for a retry. The prompts of a step hold the code of the repository, so they leave the cluster to OpenRouter (SECURITY.md rule 13). `claude-sonnet-5-5` serves the slot `analysis` only. The prompts of `analysis` hold the issue and the repository text that the planner reads, and they leave the cluster to Anthropic (SECURITY.md rule 13). A live run of `devops roadmap eval implement --model deepseek-v4.1-flash-1017 -F 2152-numeric-host-doubles` on 2026-11-05 passed every property in 281 s, with 42 model requests, 2,126,241 input tokens (the sum over the 42 requests) and 11,590 output tokens. The evaluation of 2026-11-02 chose them: on 16 golden cases the local `qwen3.8:27b` passed the stage gates in 3, `claude-sonnet-5-5` in 7 and `deepseek-v4.1-flash-1017` in 11, at about 0.002 USD a call for DeepSeek; in the review of 12 golden plans with 82 known defects, Sonnet 5.5 found 56% (68% of the major ones), DeepSeek 38% and the local models 22 to 23%. The plans of every model still need fixes, because the planner cannot read code (#3037). A failed Sonnet call falls back to DeepSeek at the gateway (#3152). The ConfigMap is not under Argo CD: change it with `kubectl -n devops patch configmap devops-cli-config`, then `kubectl -n devops rollout restart deployment/roadmap-service`; the CronJobs read it at each run. Measure a change of model with `devops roadmap eval stage --model `. +19. The model of each stage comes from the settings `ai.tasks..model` of the ConfigMap `devops-cli-config` (#3155). The slot `analysis` serves the model lane: the stage job (planning), refine and the alternatives check. The slot `verification` names the model that reviews a plan; no code reads it before the verification pass of #3153 is built. The slots `chat` and `triage` and the default `ai.model` serve the other calls of the Service, such as intake and the retitle row. The slot `implement` serves every step of the implement job, and `roadmap.implement.ladder` names the same group as the one tier of each step class (#3573). By the owner decision of 2026-11-07 (#3874), the ConfigMap sets `deepseek-v4.1-flash-1017` for every chat slot but one: `ai.model`, `implement`, `verification`, `chat` and `triage`. The slot `analysis` is a trial by the owner decision of 2026-11-09 (#4204): it names `claude-sonnet-5-5` with `context_window` 200,000, because the stage job staged nothing with DeepSeek. A stage case costs about 0.27 USD (sample of #3566), and the stage row runs up to 3 items for each 37 minutes. The embedding slot stays `qwen3-embedding:0.6b`, because a chat model cannot embed. By the owner decision of 2026-11-09 (#4241), the ConfigMap also sets `ai.reference_model: qwen3.8:27b` and `ai.reference_embedding_model: qwen/qwen3-embedding-8b`, so the spend reports of the Service value local tokens at the hosted prices of those two models (0.035 USD input and 1.50 USD output, and 0.01 USD, per million tokens). genai-prices does not know both names, so the ConfigMap also holds their prices in `ai.price_overrides` (#4242), and a new volume needs no hand step. A price that `devops ai cost set-price` saved in the file `pricing_overrides.json` of the data volume wins over the price in the ConfigMap for the same model. `ai.price_overrides` is a declared key of the section `ai`, which refuses an unknown key, so an image that is older than #4242 does not start with this key in its ConfigMap: apply the key after the new image runs or at the same time. The choice of slot models is temporary: undo it when most steps of the roadmap jobs work most of the time, and then name a model for each slot again. The prompts of intake and chat hold the titles and bodies of the issues of the repositories of the Service, and they leave the cluster to OpenRouter too (SECURITY.md rule 13). The window of `implement` is 256,000 tokens: the smallest that an fp8 provider of the group offers, where the group allows 1,048,576. A step has one tier, so a failure that selects `change_tier` ends the step; the item stops and waits for a retry. The prompts of a step hold the code of the repository, so they leave the cluster to OpenRouter (SECURITY.md rule 13). `claude-sonnet-5-5` serves the slot `analysis` only. The prompts of `analysis` hold the issue and the repository text that the planner reads, and they leave the cluster to Anthropic (SECURITY.md rule 13). A live run of `devops roadmap eval implement --model deepseek-v4.1-flash-1017 -F 2152-numeric-host-doubles` on 2026-11-05 passed every property in 281 s, with 42 model requests, 2,126,241 input tokens (the sum over the 42 requests) and 11,590 output tokens. The evaluation of 2026-11-02 chose them: on 16 golden cases the local `qwen3.8:27b` passed the stage gates in 3, `claude-sonnet-5-5` in 7 and `deepseek-v4.1-flash-1017` in 11, at about 0.002 USD a call for DeepSeek; in the review of 12 golden plans with 82 known defects, Sonnet 5.5 found 56% (68% of the major ones), DeepSeek 38% and the local models 22 to 23%. The plans of every model still need fixes, because the planner cannot read code (#3037). A failed Sonnet call falls back to DeepSeek at the gateway (#3152). The ConfigMap is not under Argo CD: change it with `kubectl -n devops patch configmap devops-cli-config`, then `kubectl -n devops rollout restart deployment/roadmap-service`; the CronJobs read it at each run. Measure a change of model with `devops roadmap eval stage --model `. 20. The row `release_comments` follows `stage_ready` on the status lane (#2917). It calls no model and needs no clone. It is due every 11 minutes and on a first run. A round reads the 30 newest releases and takes those that are published in the last 12 hours and are neither a draft nor a prerelease. For each one it takes the pull requests that the release body links as `([#N](url))`, reads the body of each pull request, and takes the closed issues that follow `Closes`, `Fixes` or `Resolves` at the start of a line. It posts `Released in ` on each such issue, and `Live since