Repository navigation
Description
Problem Description
An agent run on a local gateway group, such as devops-coder, records its tokens as hosted. The tokens get local="false" on devops_cli_ai_tokens_total, the ledger row gets the pricing source unknown at 0 USD, and the registry logs the warning for an unpriced hosted model. The AI spend dashboard then leaves these tokens out of the local savings.
The cause is in two places:
record_run_spend(src/devops_cli/roadmap/agent_run.py) sends the model name of the last reply asserved_model. That name is the gateway group name that LiteLLM puts in the reply body. It is not the deployment model that a gateway header names.is_local(src/devops_cli/ai/spend/pricing.py) returns False for every gateway call that has aserved_model(fix(ai): a hosted gateway call is recorded as a local call at $0 #3656). So the reply name alone makes the call hosted, also when the group is local.
The tier must decide the label: a local gateway group (CONST_AI_GATEWAY_VIRTUAL_MODELS) or an ollama: tier is local, and a hosted group (CONST_AI_GATEWAY_HOSTED_MODELS) is hosted. A gateway fallback that answers with another group must still price the run at the group that answered (#4216).
Found during the check of the item "label hosted model tokens as not local". That item needs no work: #3665 (PR #4231) and PR #4216 fixed it on 2026-11-09, and no hosted model has a local="true" token since 2026-11-09 02:42 UTC.
Reproduction Steps
- In a checkout of
main, run:
uv run python -c 'from devops_cli.ai.spend.pricing import is_local; print(is_local(server="<gateway>.svc.cluster.local:4000", provider="gateway", served_model="devops-coder"))' - The output is
False. Withserved_model=None, the output isTrue. - The test
test_a_run_on_a_local_group_that_no_reply_names_stays_localintests/ai/client/test_roadmap_agent_run.pypasses only because its reply names no model. A real LiteLLM reply names one:devops_cli_ai_model_answers_totalshowsansweredequal toaskedfor each group that ran in the last 7 days (claude-sonnet-5-5anddeepseek-v4.1-flash-1017).
Expected vs Actual Behavior
- Expected: an agent run on
devops-coderthrough the cluster gateway recordslocal="true", the pricing sourcelocaland 0 USD, and logs no warning. - Actual: it records
local="false", the pricing sourceunknownand 0 USD, and logs the warning for an unpriced hosted model.
Environment Diagnostics
main at 8fec1f6. The default roadmap.implement.ladder names the local devops-coder group only, so a workstation implement run with the default settings shows the defect. The Service ladder names deepseek-v4.1-flash-1017 only, so the Service does not show it now.
Logs, Traces, or Terminal Output
PromQL, 30 days: sum by (asked, answered) (increase(devops_cli_ai_model_answers_total{asked!~"deepseek.*|claude.*"}[30d])) returns no data. So no local agent run happened in that time, and no live series is wrong now.
Pre-Submission Checklist
- I have verified that no sensitive credentials, private keys, or internal tokens are contained in this issue report.
- I have checked existing issues and pull requests to ensure this is not a duplicate. Related: fix(ai): a hosted gateway call is recorded as a local call at $0 #3656, fix(ai): an agent run on a hosted group is not local spend #3665 (closed), fix(roadmap): send tool choice auto to Claude and count answers #4216.
Proposed design
Problem statement
An agent run on a local gateway group records its tokens as hosted. The local label, pricing source and warning are wrong, so the AI spend dashboard leaves local savings out. The fix classifies the gateway group that answered, and the asked tier when no group answers.
Acceptance criteria
Requirement: Local gateway group is local
is_local SHALL return True for a gateway call whose served_model is in CONST_AI_GATEWAY_VIRTUAL_MODELS.
Scenario: Local group reply
- WHEN is_local runs with provider gateway and served_model devops-coder.
- THEN The function returns True.
Requirement: Hosted gateway group is hosted
is_local SHALL return False for a gateway call whose served_model is in CONST_AI_GATEWAY_HOSTED_MODELS.
Scenario: Hosted group reply
- WHEN is_local runs with provider gateway and served_model deepseek-v4.1-flash-1017.
- THEN The function returns False.
Requirement: Ollama tier is local
is_local SHALL return True for a gateway call whose served_model starts with ollama:.
Scenario: Ollama reply
- WHEN is_local runs with provider gateway and served_model ollama:qwen3-coder:30b.
- THEN The function returns True.
Requirement: Unknown served model stays hosted
is_local SHALL return False for a gateway call whose served_model is in neither group constant and does not start with ollama:.
Scenario: Unknown deployment model
- WHEN is_local runs with provider gateway and served_model openai/gpt-4o.
- THEN The function returns False.
Requirement: Asked local tier is local
is_local SHALL return True for a gateway call with no served_model when the asked model is in CONST_AI_GATEWAY_VIRTUAL_MODELS.
Scenario: Local tier with no reply model
- WHEN A gateway call has no served_model, asks for devops-coder, and uses server llm.example.com:4000.
- THEN The function returns True.
Requirement: Local run records local spend
record_run_spend SHALL record a run on a local gateway group with the pricing source local and a cost of 0 USD.
Scenario: Local group spend record
- WHEN record_run_spend records a run asked for devops-coder and its reply names devops-coder.
- THEN The spend row has served_model devops-coder, pricing source local, and cost 0.
Requirement: Local run logs no unpriced warning
The pricing registry MUST NOT log the unpriced hosted model warning for a run on a local gateway group.
Scenario: Local group warning
- WHEN A run on devops-coder records spend and its reply names devops-coder.
- THEN The pricing logger records no warning that names devops-coder.
Requirement: Local token label
devops_cli_ai_tokens_total SHALL carry local=true for the tokens of a run on a local gateway group.
Scenario: Local group token label
- WHEN A run on devops-coder records spend and its reply names devops-coder.
- THEN The token counter has the label local with value true.
Requirement: Fallback prices at answered group
calculate_request_cost SHALL price a gateway fallback at the group that the reply names.
Scenario: Hosted fallback
- WHEN A run asks for devops-coder and the reply names deepseek-v4.1-flash-1017.
- THEN The spend row has served_model deepseek-v4.1-flash-1017 and pricing source builtin:hosted_group_prices.
Requirement: Local fallback is local
calculate_request_cost SHALL return the local pricing source when a hosted asked tier falls back to a local gateway group.
Scenario: Local fallback
- WHEN A run asks for deepseek-v4.1-flash-1017 and the reply names devops-coder.
- THEN The spend row has pricing source local and cost 0.
Existing Tool Considered
No check has run. No open, maintained tool or library covers this internal classification defect. The project builds the fix in its own code. Estimated cost: 40000 tokens to build, 10000 tokens per year to keep, 5000 tokens to fix, and 0.5 engineer-day.
Key questions
- How should is_local classify a gateway served_model that names a gateway group?: Check the name against CONST_AI_GATEWAY_VIRTUAL_MODELS and CONST_AI_GATEWAY_HOSTED_MODELS. Return True for a local group or an ollama: prefix. Return False for a hosted group. Keep an unknown deployment model hosted. (best practice) [sources: src/devops_cli/ai/spend/pricing.py, src/devops_cli/config/constants.py, src/devops_cli/roadmap/agent_run.py, tests/ai/client/test_roadmap_agent_run.py]
- Chosen: Classify served_model by the gateway group constants. The reply names the group that answered. The rule fixes the local group and keeps the hosted deployment model rule.
- Rejected: Remove the served_model hosted rule. This regresses fix(ai): a hosted gateway call is recorded as a local call at $0 #3656 for a hosted deployment model that a gateway reply names.
- Rejected: Treat every gateway reply as local when the asked tier is local. This prices a hosted fallback incorrectly and breaks fix(roadmap): send tool choice auto to Claude and count answers #4216.
- Which name decides when the asked tier and the reply group differ?: The reply group decides. Use served_model before the asked model. Price and label the run at the group that answered. (best practice) [sources: src/devops_cli/ai/spend/pricing.py, src/devops_cli/roadmap/agent_run.py, tests/ai/client/test_roadmap_agent_run.py]
- Chosen: The reply group decides. A fallback must price the run at the group that answered (fix(roadmap): send tool choice auto to Claude and count answers #4216).
- Rejected: The asked tier decides. A local asked tier would hide a hosted fallback.
- Should the asked tier decide when the reply names no model?: Yes. A gateway call with no served_model SHALL be local when the asked model is a local group or an ollama: tier. It SHALL be hosted when the asked model is a hosted group. (best practice) [sources: src/devops_cli/ai/spend/pricing.py, src/devops_cli/ai/spend/ledger.py, src/devops_cli/roadmap/agent_run.py, tests/ai/client/test_roadmap_agent_run.py]
- Chosen: Use the asked tier when the reply names no model. The tier is the only name of the target, and the body says the tier must decide the label.
- Rejected: Keep the server host as the only rule. A local group behind a public gateway would stay hosted.
- Should record_run_spend stop sending the reply model as served_model?: No. Keep the last reply model as served_model. It names the group that answered and is necessary for fallback pricing. (best practice) [sources: src/devops_cli/roadmap/agent_run.py, src/devops_cli/ai/spend/pricing.py, tests/ai/client/test_roadmap_agent_run.py]
- Chosen: Keep the reply model in served_model. The price and the label need the group that answered (fix(roadmap): send tool choice auto to Claude and count answers #4216).
- Rejected: Clear served_model for a local group. This loses the answer group and prices a fallback from a hosted tier incorrectly.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Alternatives check of 2026-11-11: none.
Tool: none found.
Activity
dan-petty commentedon Nov 11, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
fixprefix of the title gives the type.(ai)scope of the title gives the scope.It corrupts spend dashboard data for local runs but does not block work or expose a security risk.Users who run agents on local groups get wrong spend labels and lose local savings visibility.The fix requires tier-based logic in is_local and a guard for gateway fallback pricing, touching two files.Both change is_local classification for agent runs on gateway groups, but #3665 fixed hosted-to-local and the candidate fixes local-to-hosted.devops-cli-service commentedon Nov 11, 2026
Status set to Ready at 5f75d25 (see proposed design in issue body).
devops-cli-service commentedon Nov 11, 2026
Alternatives check: none
Reason: Four web searches on gateway spend tracking and local-versus-hosted model classification returned only unrelated documentation pages, and no open, maintained tool or library classifies a gateway group as local for token labels, pricing source and the unpriced-model warning. The defect is in the project's own
is_localandrecord_run_spendcode, so the fix belongs in this repository rather than in a dependency.Tool: none found
Lacks:
served_modelagainst the project's ownCONST_AI_GATEWAY_VIRTUAL_MODELS/CONST_AI_GATEWAY_HOSTED_MODELSlists or anollama:prefix.locallabel ondevops_cli_ai_tokens_totalor the ledger pricing source (localversusbuiltin:hosted_group_prices).Searches run:
Checked on 2026-11-11. A person decides what this means for the item. The check changes no label and closes no issue.
devops-cli-service commentedon Nov 12, 2026
Released in v0.115.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.115.0
devops-cli-service commentedon Nov 12, 2026
Live since 2026-11-12 04:08 UTC