Skip to content

Regression in v0.48.0: Standard/Fast cost split re-inflates deduplicated fork usage #2754

Description

@1328189205

Summary

CodexBar 0.48.0 can preserve the correct canonical Codex token total for a day/model while the new Standard/Fast cost split re-inflates the same usage by summing physical per-file pricing rows, including copied fork/subagent prefixes.

This appears to be a report-layer regression related to, but distinct from, #2037 and #2108: canonical token ownership is already deduplicated, but the mode-split cost path bypasses that ownership when building the final report.

Environment

  • CodexBar 0.48.0 (build 112)
  • Codex CLI 0.147.0-alpha.1.2
  • macOS 27.0
  • Apple Silicon
  • High-fanout Codex workload with forks/subagents
  • Full 90-day catch-up completed:
    • historyCoverageIsEstablished = true
    • codexScanCatchUpPending = false
    • 2,590 / 2,590 files
    • about 10.5 GB scanned

Verified invariant violation

For one day/model (2026-08-06, gpt-5.6-sol):

canonical totalTokens:       461,400,373
cached standardTokens:    11,311,061,683
cached priorityTokens:        30,472,681
split token total:        11,341,534,364
split / canonical ratio:             24.6x

For a single day/model, standardTokens + priorityTokens should not exceed canonical totalTokens.

Observed cost before applying a local guardrail:

2026-08-06: $7,972.81
90-day total: $29,048.93

After constraining the split to the canonical owned total:

2026-08-06: $369.33
90-day total: $9,199.41

The corrected 90-day result also independently cross-checks against the canonical aggregate input/cached-input/output totals and published model rates (within about 0.06%).

These values are API-equivalent estimates, not a claim about an actual subscription bill.

Source-level cause

In CostUsageScanner+CacheHelpers.swift:

  1. Canonical report tokens come from reportCache.days[day][model].
  2. codexNanosByDayModel and codexIntByDayModel independently sum the cached mode-split maps across every physical cache.files.values entry.
  3. Those per-file maps are derived from codexRows, which can retain copied parent rows for pricing/audit.
  4. When a split is present, buildCodexReportFromCache prefers:
splitTotalCost = standardCost + priorityCost

over cachedBaseCost and canonical-token fallback pricing, without checking that the split token count is consistent with totalTokens.

As a result, the main token totals can be correct while the displayed Standard/Fast costs are multiplied by copied fork rows.

Relevant current-main file:

Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+CacheHelpers.swift

Reproduction outline

  1. Use Codex with a high-fanout parent task and multiple forks/subagents.
  2. Complete a full native Codex history refresh:
codexbar cost --provider codex --days 90 --refresh --format json
  1. In codex-v11.json, compare each canonical days[day][model] token total with the sum of per-file codexStandardTokens and codexPriorityTokens for the same day/model.
  2. Build the report and compare the resulting Standard/Fast cost with the canonical day/model total.

No prompt text, responses, account identifiers, session IDs, filenames, or local paths are needed to reproduce the invariant failure.

Expected behavior

  • Mode-split tokens and costs should use the same fork-family ownership/deduplication as canonical totals.
  • For every day/model:
standardTokens + priorityTokens <= totalTokens
  • If split ownership is inconsistent or ambiguous, the report should either:
    • fall back to canonical model pricing,
    • normalize the split to the canonical owned token total, or
    • mark the split estimate incomplete instead of displaying a precise inflated value.

Local guardrail tested

A local guardrail normalizes the Standard/Fast split only when its token sum exceeds canonical totalTokens, preserving the relative Standard/Fast pricing mix while scaling it back to canonical ownership.

Validation completed locally:

  • make check passed
  • 19 focused CostUsageScannerPriorityTests passed
  • full 90-day cache rebuilt successfully
  • repeated cached reads remained stable

I can provide the small patch and regression tests if that direction is useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal priority bug or improvement with limited blast radius.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions