Skip to content

Track service tier and Codex credit consumption - #526

Merged
GraciousGazelles merged 9 commits into
mainfrom
fix/usage-credit-ledger-current
Jul 27, 2026
Merged

GraciousGazelles merged 9 commits into
mainfrom
fix/usage-credit-ledger-current

Conversation

@GraciousGazelles

@GraciousGazelles GraciousGazelles commented Jul 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • persist requested and actual service-tier evidence, Fast-mode use, billing surface, and account plan for each usage-provider call
  • add versioned Codex credit policies and model/tier rates plus call, thread, and turn estimate views
  • fail closed when actual model/tier, Fast-mode state, token breakdown, policy, or rate evidence is missing; preserve provider-reported credits when available
  • cover standard, Fast, API-priority, effective-date, cache-write, ambiguity, provider-reported, unknown-Fast, and partial-summary cases

Rate-card handling

Fast requests use the priority service tier. Codex credit rates remain versioned by model and effective date rather than applying one global multiplier. GPT-5.6 Fast rows use the current 2.5x Codex rate card; API-key Priority traffic remains outside the Codex-credit estimate view.

Sources:

Validation

GitHub-hosted validation only (no local Rust compute), exact head fab6ca8e5f6173062c55d37e90ef2a48087894a8:

A comparison run on the unchanged base identified a pre-existing clippy failure; this branch includes the minimal lint correction required for the full suite to evaluate successfully:

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements tracking and estimation of Codex credits and service tiers for provider calls. It adds fields to the TokenCountEvent protocol, updates the session runtime to populate these fields, introduces a new database migration (0005_usage_codex_credits.sql) with tables and views for credit rates, policies, and summaries, and adds comprehensive test coverage. The review feedback highlights three key areas for improvement: failing closed when fast_mode_used is unknown by avoiding a default speed mode, optimizing the SQL query by combining the rate_matches and model_matches CTEs, and resolving potential test flakiness caused by asserting on non-deterministic group_concat outputs in SQLite.

Comment thread codex-rs/state/src/runtime/usage.rs Resolved
@GraciousGazelles
GraciousGazelles marked this pull request as ready for review July 27, 2026 09:43
@GraciousGazelles
GraciousGazelles merged commit cb9874e into main Jul 27, 2026
110 of 112 checks passed
@GraciousGazelles
GraciousGazelles deleted the fix/usage-credit-ledger-current branch July 27, 2026 13:26
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.

1 participant