Skip to content

feat(usage): persist resolvedModel on provider_usage events - #5

Merged
FabioLeitao merged 3 commits into
mainfrom
feat/resolved-model-provider-usage
Sep 30, 2026
Merged

FabioLeitao merged 3 commits into
mainfrom
feat/resolved-model-provider-usage

Conversation

@FabioLeitao

Copy link
Copy Markdown
Owner

Summary

  • Decode provider-echoed model from OpenAI-compatible streaming chunks into Usage.ResolvedModel, merge on collect (last non-empty wins), and persist as resolvedModel on provider_usage events.
  • Does not change pricing model (registry.Require / CalculateCost unchanged); observability only (omitempty).
  • Codex /responses path sets ResolvedModel from response.model when present.
  • Merges upstream/main at 99721c76 (OpenCode session headers fix(providers): send stable session headers to OpenCode Twigpine/zero#1060) alongside this change.

Motivation

Routed providers (e.g. openrouter/free) need per-prompt attribution of the concrete model that served the request (herding-vicuna measurement). PATCHSPEC: PATCHSPEC_zero_resolved_model_attribution_2026-09-30 (operator vault).

Test plan

  • go test ./internal/providers/openai ./internal/usage ./internal/zeroruntime (incl. new unit tests)
  • make lint
  • make vulncheck — no vulnerabilities
  • Local go build -o zero-patched ./cmd/zero

Pre-existing / environment (not blocking this PR)

TestResolveReportsExplicitMaxTurns (internal/config) fails identically on isolated bases without this patch:

Local Lynis umask 0007: permission-sensitive tests need ( umask 0022; make test ); with 0022, only config (above) + tui TestRelativeAgeFormatsLastActivity remain red (also unrelated to this diff).

make lint-static: 4 staticcheck QF* on main (unchanged). gosec ./...: repo baseline exit 1 (331 issues); none in touched paths.

Upstream (GBCU)

Generic for any router echoing model — propose to Gitlawb/zero via Discussions after merge here (no PR to upstream in this change).

anandh8x and others added 3 commits September 16, 2026 07:58
Decode OpenAI-compatible stream `model` into Usage.ResolvedModel, merge on
collect (last non-empty wins), and write `resolvedModel` in EventUsage payload
without changing pricing `model` (registry.Require unchanged).

PATCHSPEC_zero_resolved_model_attribution_2026-09-30; base 95c8fc1.
GBCU: generic for any router echoing `model` — candidate for Gitlawb/zero upstream.
…ne#1060)

Merge upstream/main at 99721c7 into feat/resolved-model-provider-usage,
keeping resolvedModel attribution alongside upstream provider header fix.
@github-actions

Copy link
Copy Markdown

Zero automated PR review

Verdict: No blockers found

Blockers

  • None found.

Validation

  • [pass] Diff hygiene: git diff --check
  • [pass] Tests: go test ./...
  • [pass] Build: go run ./cmd/zero-release build
  • [pass] Smoke build: go run ./cmd/zero-release smoke

Scope

Head: 063b75f4ecf2
Changed files (15): internal/providers/anthropic/provider.go, internal/providers/factory.go, internal/providers/factory_test.go, internal/providers/openai/codex_responses.go, internal/providers/openai/provider.go, internal/providers/openai/provider_test.go, internal/providers/openai/tool_state.go, internal/providers/openai/types.go, internal/providers/providerio/headers.go, internal/usage/report.go, internal/usage/report_test.go, internal/usage/token_economy_test.go, and 3 more

This deterministic review checks validation status and basic diff hygiene. A human reviewer still owns product judgment and design quality.

@FabioLeitao
FabioLeitao merged commit 5be0c62 into main Sep 30, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants