Repository navigation
Description
Problem
No alert fires on the Claude spend. On 2026-11-09 a stage task on claude-sonnet-5-5 spent about 21 USD per hour while every round failed, and nobody saw it until the owner read the cost page. The 24 h Anthropic costs of the owner for 2026-11-03 to 2026-11-09 were 1.65, 1.72, 3.74, 0.39, 0.13, 0 and 5.59 USD. The cost of 2026-11-09 was about 58 USD after the failed stage burst.
The budgets per item and per day (#3066) wait for the stage baseline (#3566). They count tokens and seconds, and they hold the Service rows. They do not alert on dollars, and they do not cover the CLI.
The counter devops_cli_ai_spend_usd_total also cannot carry the alert yet. A hosted agent run is recorded as local spend at 0 USD (#3665). In the ledger of 2026-11-05 these rows were two thirds of the hosted prompt tokens. An alert on the counter would stay quiet in a burst like that of 2026-11-09.
k8s/monitoring/prometheus-values.yaml has no rule group for spend.
Expected
- A rule group
ai-spendink8s/monitoring/prometheus-values.yamlwith two alerts of severitywarning:ClaudeSpendDailyHigh:sum(increase(devops_cli_ai_spend_usd_total{model="claude-sonnet-5-5"}[24h])) > 15.HostedSpendDailyHigh:sum(increase(devops_cli_ai_spend_usd_total[24h])) > 25. A local request adds 0 to the counter, so this sums the hosted models.
- The thresholds are above the highest normal day of the owner (5.59 USD) and under the burst (58 USD). The failed burst of 21 USD per hour passes 15 USD in under one hour. Change a threshold with the data of a month.
- A promtool fixture,
tests/fixtures/prometheus_rules/ai_spend_tests.yaml, run bytests/prometheus/test_k8s_monitoring_alerting.py. - A row for each alert in the alert table of
k8s/README.md, with the first step: read the cost page of the AI spend dashboard, find the caller by theend_userlabel, and stop the job. - The work waits for fix(ai): an agent run on a hosted group is not local spend #3665, so that the counter prices hosted agent runs. The gateway series
litellm_spend_metric_total(the LiteLLMprometheuscallback, enabled ink8s/llm/gateway/config.yaml) is an option that needs no fix(ai): an agent run on a hosted group is not local spend #3665. Not verified: that the live scrape holds this series with a Claude cost. Check with a query before the work, and use the series that prices the calls. Do not use both.
Acceptance criteria
- The promtool fixture has a series that rises by 1 USD per hour for 24 hours with the label
model="claude-sonnet-5-5", and asserts thatClaudeSpendDailyHighfires. It fails today, because the rule group does not exist. - The fixture has a normal series of 5.59 USD in 24 hours, and asserts that both alerts stay quiet. It fails today for the same reason.
- The fixture has a series that resets to 0 in the middle of the window (a pod restart), and asserts that the alert still fires on the sum of the increases. It fails today for the same reason.
- The fixture has a series of another hosted model of 30 USD in 24 hours, and asserts that
HostedSpendDailyHighfires andClaudeSpendDailyHighstays quiet. - A test asserts that the alert table of
k8s/README.mdhas a row for each alert of the groupai-spend. It fails today. - A test asserts that the spend of a hosted agent run is above 0 USD in the counter (the test of fix(ai): an agent run on a hosted group is not local spend #3665). It is not part of this change. The change waits for it.
Existing tool considered
Prometheus alert rules and promtool cover this, and the repository uses them (research, roadmap-service). The LiteLLM budget feature (max_budget per key) can stop a key at a limit, but it does not alert, and the owner wants a signal and not a hard stop before the baseline (#3566). No new tool is built.
Cost
Tokens to build: about 50,000 (two rules, one fixture, one README row, one test). Tokens to keep: none. Tokens to fix a later fault: about 10,000 for a threshold change. Elapsed time: about 1 hour, after #3665.
Related
#3066 (budgets per item and per day), #3665 (hosted agent run is not local spend), #3658 (price the cache tokens of Claude), #3655 (dashboard and alerts for the pipeline).
Proposed design
Problem statement
No alert fires on the Claude spend. On 2026-11-09 a failed stage burst on claude-sonnet-5-5 cost about 58 USD in one day, and nobody saw it until the owner read the cost page. The change adds the rule group ai-spend to k8s/monitoring/prometheus-values.yaml with two warning alerts on the daily spend in USD. It also adds a promtool fixture and a README row for each alert. The alerts stay quiet for hosted agent runs until #3665 lands, because the counter now records such a run as 0 USD.
Acceptance criteria
Requirement: Claude daily spend alert fires
The rule ClaudeSpendDailyHigh of the group ai-spend SHALL fire with severity warning when the 24 hour increase of the spend of claude-sonnet-5-5 is above 15 USD.
Scenario: Claude spend rises 1 USD per hour
- WHEN The promtool fixture feeds a series with
model="claude-sonnet-5-5"that rises by 1 USD per hour for 24 hours. - THEN The alert
ClaudeSpendDailyHighfires at the end of the window.
Requirement: Normal day stays quiet
Both alerts of the group ai-spend MUST stay quiet on the highest normal day of the owner.
Scenario: Normal day of 5.59 USD
- WHEN The promtool fixture feeds a series with
model="claude-sonnet-5-5"that adds 5.59 USD in 24 hours. - THEN Neither
ClaudeSpendDailyHighnorHostedSpendDailyHighfires.
Requirement: Counter reset keeps the sum
The alerts SHALL sum the increases of a series that resets to 0 in the middle of the window.
Scenario: Pod restart in the window
- WHEN The promtool fixture feeds a Claude series that resets to 0 in the middle of the window and adds more than 15 USD in total.
- THEN The alert
ClaudeSpendDailyHighstill fires.
Requirement: Hosted alert counts every model
The rule HostedSpendDailyHigh SHALL fire when the 24 hour increase of the spend of all models is above 25 USD, and ClaudeSpendDailyHigh MUST count the model claude-sonnet-5-5 only.
Scenario: Another hosted model spends 30 USD
- WHEN The promtool fixture feeds a series of another hosted model that adds 30 USD in 24 hours.
- THEN The alert
HostedSpendDailyHighfires andClaudeSpendDailyHighstays quiet.
Requirement: Rules pass the existing rule tests
The two new rules SHALL carry severity warning, a wait, a summary and a description, and the test file MUST list the counter as a served series, the two alerts in the baseline rule set, and the group in the list of unit-tested groups.
Scenario: Rule file checks
- WHEN The tests of
tests/prometheus/test_k8s_monitoring_alerting.pyrun against the new group. - THEN The tests for served series, baseline rules, rule fields and
promtoolpass, and the fixturetests/fixtures/prometheus_rules/ai_spend_tests.yamlruns for the groupai-spend.
Requirement: README lists each alert
The alert table of k8s/README.md SHALL have a row for each alert of the group ai-spend, with the first step: read the cost page of the AI spend dashboard, find the caller by the end_user label, and stop the job.
Scenario: README rows present
- WHEN A test reads the alert table of
k8s/README.mdand the alert names of the groupai-spend. - THEN Each alert name has a row in the table.
Existing Tool Considered
No alternatives check has run for this item. Prometheus alert rules and promtool cover the need, and the repository already uses them for roadmap-service and research. They need no new code beyond two rules, one fixture, two README rows and one test. The LiteLLM max_budget per key stops a key at a limit, but it sends no alert, so it lacks the signal that the owner wants. No tool is built. Cost of the change: about 50,000 tokens to build, no tokens to keep, about 10,000 tokens for each later threshold change, and about 1 hour of elapsed time after #3665.
Key questions
- Which series carries the spend alert?: Use
devops_cli_ai_spend_usd_total, as the rules of the issue name it. After fix(ai): an agent run on a hosted group is not local spend #3665 the counter prices hosted agent runs, and itsmodellabel is the model that the client asked for, such asclaude-sonnet-5-5. Do not also uselitellm_spend_metric_total, because the two series would count the same spend twice. (best practice) [sources: docs/TELEMETRY.md, src/devops_cli/telemetry/instruments.py, tests/fixtures/metrics/litellm.yaml]- Chosen: devops_cli_ai_spend_usd_total. The project owns it, a test pins it, and it carries the
modellabel. It is correct for hosted agent runs once fix(ai): an agent run on a hosted group is not local spend #3665 lands. - Rejected: litellm_spend_metric_total. It needs no fix(ai): an agent run on a hosted group is not local spend #3665, but its live scrape with a Claude cost is not verified, and its
end_userandmodellabels differ from the counter. - Rejected: Both series. The issue forbids it, because the spend would count twice.
- Chosen: devops_cli_ai_spend_usd_total. The project owns it, a test pins it, and it carries the
- Does the counter record a hosted agent run at a price today?: No. The issue states that a hosted agent run is recorded as local spend at 0 USD (fix(ai): an agent run on a hosted group is not local spend #3665). The alerts stay quiet in a burst like that of 2026-11-09 until fix(ai): an agent run on a hosted group is not local spend #3665 lands. This item depends on fix(ai): an agent run on a hosted group is not local spend #3665. [sources: docs/TELEMETRY.md, src/devops_cli/telemetry/instruments.py]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 9, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
featprefix of the title gives the type.(k8s)scope of the title gives the scope.It prevents unnoticed financial loss (58 USD burst) but is a signal, not a hard stop, and depends on #3665.It catches a costly burst before the owner reads the cost page, but a dashboard already shows the spend.Two alert rules, one promtool fixture, one README row, and one test; the body estimates about 1 hour.Both bound AI spend, but #3066 adds budgets that hold rows (hard stop) while this adds Prometheus alerts that signal (no stop).devops-cli-service commentedon Nov 9, 2026
Refine cannot set this item to Ready at 111adc5 while the items below stay open. The next refine round looks at the item again when they close, or when a person replies in a comment or edits the body.
The next refine round also looks at the item again when a commit on the default branch changes one of these files:
src/devops_cli/telemetry/instruments.py.devops-cli-service commentedon Nov 9, 2026
Status set to Ready at c034509 (see proposed design in issue body).
devops-cli-service commentedon Nov 9, 2026
Released in v0.102.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.102.0
devops-cli-service commentedon Nov 9, 2026
Live since 2026-11-09 17:57 UTC