Skip to content

fix(ai): an agent run on a local group counts as hosted #4523

Closed
1 of 1 issue completed
Closed

Description

@dan-petty

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 as served_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 a served_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

  1. 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"))'
  2. The output is False. With served_model=None, the output is True.
  3. The test test_a_run_on_a_local_group_that_no_reply_names_stays_local in tests/ai/client/test_roadmap_agent_run.py passes only because its reply names no model. A real LiteLLM reply names one: devops_cli_ai_model_answers_total shows answered equal to asked for each group that ran in the last 7 days (claude-sonnet-5-5 and deepseek-v4.1-flash-1017).

Expected vs Actual Behavior

  • Expected: an agent run on devops-coder through the cluster gateway records local="true", the pricing source local and 0 USD, and logs no warning.
  • Actual: it records local="false", the pricing source unknown and 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

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]
  • 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]
  • 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]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-11: none.
Tool: none found.

Sub-issues

Sub-issues

1 of 1 Issues completed
Loading 1 sub-issues

Activity

  1. added
    source/agent
    type/bug
    scope/ai
    status/new
    value/medium
    effort/medium
    on Nov 11, 2026
  2. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/bug. The fix prefix of the title gives the type.
    • Scope: scope/ai. The (ai) scope of the title gives the scope.
    • Priority: P2-Medium. It corrupts spend dashboard data for local runs but does not block work or expose a security risk.
    • Value: Medium. Users who run agents on local groups get wrong spend labels and lose local savings visibility.
    • Effort: Medium. The fix requires tier-based logic in is_local and a guard for gateway fallback pricing, touching two files.
    • Related: fix(ai): an agent run on a hosted group is not local spend #3665, which asks for a different change. Both change is_local classification for agent runs on gateway groups, but #3665 fixed hosted-to-local and the candidate fixes local-to-hosted.
  3. added
    priority/p2-medium
    on Nov 11, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 11, 2026
  5. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 5f75d25 (see proposed design in issue body).

  6. added
    owner/agent
    on Nov 11, 2026
  7. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    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_local and record_run_spend code, so the fix belongs in this repository rather than in a dependency.

    Tool: none found

    Lacks:

    • No tool classifies a gateway served_model against the project's own CONST_AI_GATEWAY_VIRTUAL_MODELS / CONST_AI_GATEWAY_HOSTED_MODELS lists or an ollama: prefix.
    • No tool sets the project's local label on devops_cli_ai_tokens_total or the ledger pricing source (local versus builtin:hosted_group_prices).
    • No tool implements the project's fallback rule of pricing a run at the group that answered the reply.
    • No tool suppresses the project's own unpriced hosted-model registry warning.

    Searches run:

    • LiteLLM model group spend tracking local vs hosted classification, results: 5
    • open source library classify LLM gateway model group as local or hosted pricing, results: 5
    • litellm spend logs cost per model group virtual key tracking, results: 5
    • prometheus counter label local vs hosted AI token spend library, results: 5

    Checked on 2026-11-11. A person decides what this means for the item. The check changes no label and closes no issue.

  8. added
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 12, 2026
  9. removed
    status/in-review
    owner/agent
    on Nov 12, 2026
  10. devops-cli-service commented on Nov 12, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-12 04:08 UTC

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

    effort/mediumpriority/p2-mediumscope/aisource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions