Skip to content

fix(ai): the gateway group that answered decides the local label - #4907

Merged
dan-petty merged 4 commits into
mainfrom
fix/4523-local-group-spend-label
Nov 12, 2026
Merged

dan-petty merged 4 commits into
mainfrom
fix/4523-local-group-spend-label

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

An agent run on a local gateway group, such as devops-coder, recorded its tokens as hosted: local=false, the pricing source unknown at 0 USD, and the warning for an unpriced hosted model. The reply of the run names the group that answered, and is_local made each gateway reply that names a model hosted (#3656). is_local decides a gateway reply with no backend by the model that it names: a local gateway group (CONST_AI_GATEWAY_VIRTUAL_MODELS) or an ollama: model is local, and each other model, a hosted group included, stays hosted. When the reply names no model, the asked model decides when it is a local tier. calculate_request_cost gives is_local the asked model. So a fallback is priced and labeled at the group that answered (#4216). A local group outside the constant and the Ollama model of a local fallback stay hosted: #4886.

Closes #4523

Change: openspec/changes/archive/2026-11-12-4523-an-agent-run-on-a-local/

A gateway reply that names no backend is local when it names a local
gateway group or an ollama: model. When the reply names no model, the
asked model decides. Each other model stays hosted (#3656), so a
fallback is priced at the group that answered (#4216).

Refs #4523.
@dan-petty dan-petty added type/bug Type bug: the code does not do what it must scope/ai AI review pipeline, personas, prompts, LLM client, or RAG labels Nov 12, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Test record

Local runs on the final code before the rebase onto 3b3fddc07. The rebase changed none of the files of this change, and the pre-push lint and format rows ran after it.

  • uv run devops ci test tests/ai/spend tests/ai/client/test_roadmap_agent_run.py tests/ai/agents/test_ai_agent_capabilities.py tests/commands/test_ai_runs_cost_cache_dry_run.py tests/telemetry/test_telemetry_instruments.py: 305 passed.
  • uv run devops ci --check --only lint,format,docs,constructs,openspec,test-settings,test-tree,startup-imports,swallowed-failures: all rows pass.
  • uv run mypy src/devops_cli/ai/spend/pricing.py: no issues.
  • uv run ruff check and ruff format --check on the 3 changed Python files: pass.
  • uv run devops openspec archive 4523-an-agent-run-on-a-local: every spec and change validates.

No model call ran: the tests use the FunctionModel and _GatewayModel fakes.

Fail-to-pass

uv run devops ci fail-to-pass --base origin/main (exit 0):

failed on base: tests.ai.client.test_roadmap_agent_run::test_a_run_on_a_local_group_whose_reply_names_the_group_is_local (assert (('devops-cod...ion_rate>'."]) == (('devops-cod... {'true'}, []))
failed on base: tests.ai.client.test_roadmap_agent_run::test_a_hosted_group_that_a_local_group_answers_is_local (AssertionError: assert ('devops-code...unknown', 0.0) == ('devops-coder', 'local', 0.0))
failed on base: tests.ai.spend.test_ai_spend_pricing::test_the_gateway_group_that_answered_decides_whether_a_call_is_local[deployment-model] (TypeError: is_local() got an unexpected keyword argument 'model')
failed on base: tests.ai.spend.test_ai_spend_pricing::test_the_gateway_group_that_answered_decides_whether_a_call_is_local[local-group] (TypeError: is_local() got an unexpected keyword argument 'model')
failed on base: tests.ai.spend.test_ai_spend_pricing::test_the_gateway_group_that_answered_decides_whether_a_call_is_local[asked-local-group] (TypeError: is_local() got an unexpected keyword argument 'model')
failed on base: tests.ai.spend.test_ai_spend_pricing::test_the_gateway_group_that_answered_decides_whether_a_call_is_local[hosted-group] (TypeError: is_local() got an unexpected keyword argument 'model')
failed on base: tests.ai.spend.test_ai_spend_pricing::test_the_gateway_group_that_answered_decides_whether_a_call_is_local[ollama] (TypeError: is_local() got an unexpected keyword argument 'model')
failed on base: tests.ai.spend.test_ai_spend_pricing::test_the_gateway_group_that_answered_decides_whether_a_call_is_local[local-group-falls-back-to-hosted] (TypeError: is_local() got an unexpected keyword argument 'model')
failed on base: tests.ai.spend.test_ai_spend_pricing::test_the_gateway_group_that_answered_decides_whether_a_call_is_local[hosted-group-falls-back-to-local] (TypeError: is_local() got an unexpected keyword argument 'model')
9 failed on base (9 failed and 89 passed in tests/ai/client/test_roadmap_agent_run.py, tests/ai/spend/test_ai_spend_pricing.py; 0 errored).

The is_local cases fail on the base because the argument model does not exist there. The two record_run_spend cases fail on the assertion: the base records devops-coder with the pricing source unknown and logs the unpriced warning.

Follow-up

#4886: a local group outside CONST_AI_GATEWAY_VIRTUAL_MODELS (such as qwen3.8:27b) and the Ollama model of a local fallback (ollama_chat/qwen3.8:27b) still count as hosted.

No live step is necessary.

@dan-petty
dan-petty marked this pull request as ready for review November 12, 2026 03:16
@dan-petty
dan-petty merged commit 0da637f into main Nov 12, 2026
27 checks passed
@dan-petty
dan-petty deleted the fix/4523-local-group-spend-label branch November 12, 2026 03:36
dan-petty pushed a commit that referenced this pull request Nov 12, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.115.0](v0.114.1...v0.115.0)
(2026-11-12)


### Features

* **design:** add the design tokens and their build
([#4811](#4811))
([db4b19a](db4b19a))
* **roadmap:** find symbol definitions with tree-sitter
([#4820](#4820))
([3b3fddc](3b3fddc))


### Bug Fixes

* **ai:** the gateway group that answered decides the local label
([#4907](#4907))
([0da637f](0da637f))
* **ci:** replay a changed gate check in fail-to-pass
([#4898](#4898))
([59bfc57](59bfc57))
* **config:** read each config file as YAML 1.2
([#4858](#4858))
([c3130a3](c3130a3))
* **roadmap:** loosen the caps that turn a stage refusal into a loss
([#4869](#4869))
([4492fc3](4492fc3))
* **roadmap:** refine reads a dependency named by title
([#4877](#4877))
([2829f9c](2829f9c))
* **roadmap:** refine sends a judge refusal to an agent round
([#4874](#4874))
([e4fc6a9](e4fc6a9))
* **tests:** refuse test writes under the real home
([#4857](#4857))
([0f6ac1b](0f6ac1b))
* **tests:** the plain-Python helper test keeps PYTHONPATH
([#4914](#4914))
([99c109d](99c109d))


### Performance Improvements

* **ci:** direct pytest runs wait for a gate slot
([#4901](#4901))
([e80db62](e80db62))
* **roadmap:** status lane reads the snapshot, skips idle stops
([#4887](#4887))
([f285cf8](f285cf8))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/ai AI review pipeline, personas, prompts, LLM client, or RAG type/bug Type bug: the code does not do what it must

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant