fix(usage): preserve provider-billed zero totals#101177
Conversation
|
Addressed the review direction from #101163 by replacing the provider/model-specific core rule with an explicit provenance contract:
Validation so far:
Known CI blocker not introduced by this diff:
@clawsweeper review-pr |
|
🦞🧹 I asked ClawSweeper to review this item again. |
6bcc50c to
d94a866
Compare
|
Codex review: stale review; fresh review needed. Summary Next step Review history (3 earlier review cycles)
|
|
Updated the PR body with current-head evidence for Added proof covers the requested provider-billed zero-total path through a redacted transcript summary, durable cache, and session-log spend path on a test server, plus exact-head GitHub Actions links. @clawsweeper review-pr |
|
🦞🧹 I asked ClawSweeper to review this item again. |
d94a866 to
6b81113
Compare
|
Maintainer rewrite and final review complete on exact head What changed:
Proof:
No UI changed, so before/after screenshots are not applicable. Review artifacts validate with zero findings. Ready for the repository-native prepare/merge flow. |
|
Final-head proof refresh:
The focused Testbox, credentialed OpenRouter extension, and real-Gateway prompt/tool/image proofs remain documented in the PR body. Ready for the native prepare/merge lane. |
|
Merged via squash.
|
* fix(usage): preserve provider-billed zero totals * fix(usage): harden provider-billed cost provenance * fix(openrouter): retry delayed generation metadata * fix(openrouter): satisfy retry lint * refactor(openrouter): consume streamed billed cost * chore: keep release notes out of contributor PR --------- Co-authored-by: snowzlmbot <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
* fix(usage): preserve provider-billed zero totals * fix(usage): harden provider-billed cost provenance * fix(openrouter): retry delayed generation metadata * fix(openrouter): satisfy retry lint * refactor(openrouter): consume streamed billed cost * chore: keep release notes out of contributor PR --------- Co-authored-by: snowzlmbot <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
* fix(usage): preserve provider-billed zero totals * fix(usage): harden provider-billed cost provenance * fix(openrouter): retry delayed generation metadata * fix(openrouter): satisfy retry lint * refactor(openrouter): consume streamed billed cost * chore: keep release notes out of contributor PR --------- Co-authored-by: snowzlmbot <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
Persisted
usage.cost.total: 0is ambiguous: it can be an estimated placeholder that should be recomputed, or an authoritative billed zero from a free provider route. Without provenance, transcript summaries can replace a legitimate free-route total with catalog pricing.This follows up #97047 and supersedes the closed #97134 and #101163 attempts.
Why This Change Was Made
OpenRouter includes detailed usage, including
cost, in the final streaming chunk. The first maintainer rewrite tried to reconcile cost through OpenRouter's generation-metadata endpoint, but credentialed live proof exposed an asynchronous materialization race: the completed stream could still be followed by repeated generation lookup 404s.The final implementation consumes the provider-reported final-chunk cost directly in both OpenAI-compatible stream parsers. A shared validator accepts only finite, non-negative numeric totals and marks them
provider-billed; missing or malformed costs keep the existing catalog estimate. This removes the extra network request, retry policy, response wrapper, and provider/model-specific core logic.Official contracts checked:
User Impact
What Changed
usage.cost.totalOrigin: "provider-billed"marker to the canonical usage type.Evidence
Exact head:
9b20ff17137f1326ded9e7c2a56f8c8b8616ffd8.extensions/openrouter/openrouter.live.test.tspassed its live free-route billed-zero assertion.0b9758d93d5and pinned the catalog-backedopenrouter/openrouter/automodel through a temporary harness branch. Final head9b20ff17137differs only by removing the release-owned root changelog entry required by the native prepare guard.runs meaningful prompts across models with available keystarget passed (109/110 tests overall).git diff --check: passed.The earlier live attempts are useful negative proof: generation-metadata polling failed to observe the completed free-route generation reliably, which prompted the direct final-stream contract rewrite now under test.
Risk / Compatibility
The marker is optional and additive. Existing transcript rows remain valid. Only a finite, non-negative provider-reported numeric total becomes authoritative; absent, string, negative, or non-finite values retain catalog estimation. Cache version 7 rebuilds older summaries under the new semantics.
No config, CLI, protocol, dependency, lockfile, secret, or UI surface changes. Screenshots are not applicable.