Skip to content

fix(ai): price a hosted group call by the asked model - #4231

Merged
dan-petty merged 3 commits into
mainfrom
fix/3665-hosted-group-asked-model
Nov 9, 2026
Merged

dan-petty merged 3 commits into
mainfrom
fix/3665-hosted-group-asked-model

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

An agent run on a hosted gateway group is recorded as local spend at $0 (#3665). record_run_spend in src/devops_cli/roadmap/agent_run.py writes one record per run. When no reply names a model, the record has no served_by and no served_model, and is_local then decides from the gateway host: a gateway that is the cluster host is local. The production counter of job roadmap-service on 2026-11-09 shows 68 M claude-sonnet-5-5 prompt tokens as local=true at $0, while the gateway log prices them at $2 per million. The DeepSeek group shows $0 on the counter against $14 on the gateway. #3663 fixed a reply that names a model, and #4216 passes the model that a reply names. A run whose replies name no model is still wrong.

Closes #3665

Change: openspec/changes/archive/2026-11-09-3665-an-agent-run-on-a-hosted/

@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 9, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Test record for #3665.

Fail-to-pass (uv run devops ci fail-to-pass --base origin/main): 5 tests failed on the base. Each one saw a local record at 0 USD, (None, 'local', 0.0), where the asked model, a genai_prices source and a cost above 0 were expected. The other new tests pass on the base by design: a reply that names a model keeps its name, and a local group stays local.

Tests added: 6 cases in tests/ai/client/test_roadmap_agent_run.py and 3 cases in tests/ai/spend/test_ai_spend_ledger.py. They use fakes, with the gateway host set as the cluster host. No model call.

Full CI (uv run devops ci) on the final tree: all rows pass. The test row took 20m 41s on a shared host. That is over the 5 minute budget and is tracked by #3593. It is not a failure of this change.

Design: the rule sits in track_request_spend (src/devops_cli/ai/spend/ledger.py), where the asked model is known. A gateway call with no served_by, no served_model and a hosted group (CONST_AI_GATEWAY_HOSTED_MODELS) now takes the asked model as served_model. The price, the local label and the stored model then agree. A reply that names a model still wins (#4216). A local group keeps the local rule. The change touches no file of #4220. No setting is added, so the ConfigMap rollout rule does not apply.

Out of scope (not done here):

  • The counter showed 68 M local tokens against 27 M at the gateway. A double count or a fallback to another group may exist. It needs Service logs to decide.
  • Cache tokens are not passed to genai-prices: feat(ai): cache Claude prompts and price the cache tokens #3658.
  • DeepSeek has no price in genai-prices (LookupError), so its cost stays 0 with the existing "source unknown" warning. A person may decide whether to add a price source for it.
  • A local branch fix/3665-agent-run-hosted-spend (old header-list design, never pushed) is obsolete. A person may delete it.

@dan-petty
dan-petty force-pushed the fix/3665-hosted-group-asked-model branch from fa9be96 to dd75290 Compare November 9, 2026 14:06
@dan-petty
dan-petty marked this pull request as ready for review November 9, 2026 14:17
@dan-petty
dan-petty merged commit 7b85c91 into main Nov 9, 2026
26 checks passed
@dan-petty
dan-petty deleted the fix/3665-hosted-group-asked-model branch November 9, 2026 14:32
dan-petty pushed a commit that referenced this pull request Nov 9, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.101.0](v0.100.2...v0.101.0)
(2026-11-09)


### Features

* **config:** add task variables for the context window
([#4234](#4234))
([c034509](c034509))


### Bug Fixes

* **ai:** price a hosted group call by the asked model
([#4231](#4231))
([7b85c91](7b85c91))
* **ai:** Refuse uv audit when project is outside workspace
([#4239](#4239))
([1700648](1700648))
* **ci:** retry the download of a release asset
([#4235](#4235))
([cf0567e](cf0567e))
* **service:** use load_settings() in GET /config
([#4233](#4233))
([230d77c](230d77c))

---
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 hosted group is not local spend

1 participant