Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(usage): Codex Fast and Ultrafast now cost what they bill #15101

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/15101/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

The Usage tab priced every Codex request at the standard rate. Ultrafast bills at 6x and Fast at 2x for GPT-6 Astra, so heavy Ultrafast use looked far cheaper than it was.

On one machine, the last 30 days of Codex went from $1,408 to $3,364. Ultrafast Astra alone went from $353 to $2,116.

Fix

Codex writes the service tier (default, priority, ultrafast) to thread_settings_applied events. The usage scan skipped those events.

  • The Codex reducer now carries the tier forward, the same way it carries the model.
  • Pricing reads LiteLLM's _priority and _ultrafast rates. Claude fast mode keeps its published multiple. If a model publishes no rates for a tier, that tier bills at the standard rate.
  • When Codex leaves out service_tier, no tier was requested, so the request bills as standard.

Saved usage is kept across the cache upgrade

The scan cache keeps usage for transcripts that were deleted from disk. Earlier cache version bumps lost that history.

  • v4 Codex entries are kept. A rollout that is still on disk re-parses with its tier. A deleted rollout keeps its saved usage at the standard rate.
  • Each cache version now writes its own file (usage-scan-cache-v5.json). An older server that shares ~/.t3/userdata keeps its own cache, and neither version overwrites the other.

ccusage reads the same event but treats ultrafast as unknown, so it under-reports Ultrafast too.

Proof: new tests for tier parsing, tier pricing, resume across the parse boundary, and a v4 cache upgrade with one deleted rollout. The upgrade test fails for each of three broken variants. I also ran the new reader and pricing over 431 real Codex rollouts.

Reviewed with sol-loop: 3 rounds with GPT-6.1 Sol on high.

Created with Claude Opus 5.5 in Claude Code.

🤖 Generated with Claude Code

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. juliusmarminge added labelsmacroscope-review

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — The PR changes production usage parsing, model-rate selection, cache migration, and displayed cost calculations, including potentially large cost changes for existing Codex Fast and Ultrafast requests. Because it directly affects billing and metering behavior, human review is required.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire4.9 KiB4.9 KiB−40 B (−0.8%)6.8 KiB✅
      CodexThread snapshot wire3.7 KiB3.7 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.1 KiB−40 B (−3.3%)2.0 KiB✅
      CodexLive turn WebSocket decoded20.4 KiB20.4 KiB−41 B (−0.2%)29.3 KiB✅
      CodexLive turn messages21−1 (−50.0%)8✅
      ClaudeTotal thread wire4.9 KiB4.9 KiB−41 B (−0.8%)6.8 KiB✅
      ClaudeThread snapshot wire3.7 KiB3.7 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB−41 B (−3.4%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded20.8 KiB20.7 KiB−41 B (−0.2%)29.3 KiB✅
      ClaudeLive turn messages21−1 (−50.0%)8✅

      Baseline: 6108ef3 · PR result: 40adc07 · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 106.1 KiB
      • Claude decoded thread snapshot: 106.4 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    5. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
      • Review profile: CHILL
      • Plan: Team
      • Run ID: 86606b7b-af98-4196-9989-84b9939fd111
      📥 Commits

      Reviewing files that changed from the base of the PR and between 3e4f0d1a597282f5c83015d1e1b7c68b9f622c5f and 40adc07dd703e1122c171271078dc0b6b5a5e915.

      📒 Files selected for processing (4)
      • apps/server/src/usage/UsageService.test.ts
      • apps/server/src/usage/UsageService.ts
      • apps/server/src/usage/usageScanCache.test.ts
      • apps/server/src/usage/usageScanCache.ts
      🚧 Files skipped from review as they are similar to previous changes (1)
      • apps/server/src/usage/usageScanCache.test.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.


      📝 Walkthrough

      Walkthrough

      Usage records now carry standard, fast, or ultrafast speed. Codex transcript parsing tracks service tiers, pricing selects tier-specific rates, and the scan cache stores and validates speed values.

      Changes

      Usage speed attribution and billing

      Layer / File(s)Summary
      Record and carry usage speed
      apps/server/src/usage/usageTranscripts.ts, apps/server/src/usage/usageTranscriptReader.ts, apps/server/src/usage/*UsageReader.ts, apps/server/src/usage/usageTranscripts.test.ts, apps/server/src/usage/usageTranscriptReader.test.ts, apps/server/src/usage/usageTranscriptStreaming.test.ts
      Usage records replace the boolean fast field with speed. Codex parsing carries service-tier settings into usage records. Other provider readers assign standard or fast speed as described by their parsers. Tests cover tier mapping and resume behavior.
      Tier-specific usage pricing
      apps/server/src/usage/usagePricing.ts, apps/server/src/usage/usagePricing.test.ts, apps/server/src/usage/usageAggregation.test.ts
      Rate entries support standard, fast, and ultrafast token rates. Pricing and cache-savings calculations select rates by record speed and fall back to standard rates when a speed-specific rate is unavailable. Tests cover published Codex rates and fallback behavior.
      Speed-aware scan-cache format and migration
      apps/server/src/usage/usageScanCache.ts, apps/server/src/usage/usageScanCache.test.ts, apps/server/src/usage/UsageService.ts, apps/server/src/usage/UsageService.test.ts
      The cache advances to version 5 and stores speed indexes. Decoding validates speed values and resets the scan position for older Codex entries. UsageService can load a legacy cache and mark it for migration.

      Priority: ➖ Normal

      Estimated code review effort: 3 (Moderate) | ~20 minutes

      Change: Bug fix

      Sequence Diagram(s)

      sequenceDiagram
        participant usageTranscriptReader
        participant parseCodexLine
        participant CodexScanState
        usageTranscriptReader->>parseCodexLine: forwards Codex transcript lines
        parseCodexLine->>CodexScanState: updates speed from service tier
        parseCodexLine-->>usageTranscriptReader: returns usage record with speed

      Suggested reviewers: maria-rcks, juliusmarminge

      Merge Risk: ⚪ Minimal · up to 40adc

      No issue identified here needs resolution before merge; normal checks remain appropriate.

      🚥 Pre-merge checks | ✅ 4 | ❌ 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 45.16% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 31 functions across 15 files.Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Title check✅ PassedThe title clearly summarizes the main change: Codex Fast and Ultrafast requests now use tier-specific pricing.
      Description check✅ PassedThe description explains the problem, the pricing and cache changes, and the verification performed. It does not include the template’s Scope and approval section or state explicit test outcomes, but …
      • Fix all pre-merge checks with AI
      ✨ Finishing Touches 💡 1
      📝 Generate docstrings 💡
      • Commit to this branch
      • Create a new PR
      🧪 Generate unit tests (beta)
      • Commit to this branch
      • Create a new PR
      • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Comment `@coderabbitai help` to get the list of available commands.

Sign in to join this conversation.