CodexBar Bug Report: "Today" Cost Shows Last Historical Usage Day
Summary
CodexBar has a usage-accuracy bug where UI surfaces labeled Today can show the newest non-empty historical cost bucket instead of the actual current local day. If a user has no usage today, and also no usage yesterday, the app may keep showing the last day with usage as "Today" until a newer bucket appears.
Example failure:
- Current local date:
2026-05-18 - Latest cost-history row:
2026-05-15,$1.50,300 tokens - Expected Today display:
$0.00 · 0 tokens - Actual buggy display:
$1.50 · 300 tokens
This affects trust in cost/usage monitoring because the app appears to report current-day activity where none occurred.
User-Visible Symptoms
When there is a gap after the latest recorded usage day, the menu card and inline dashboard can keep reporting that old usage as today's usage.
Likely affected displays:
- Token-cost menu card line:
Today: $X.XX · N tokens - Inline cost dashboard KPI titled
Today - OpenAI Admin API usage notes/submenus titled
Today - Claude Admin API usage notes/submenus titled
Today - Any future provider that reuses the same "latest bucket" helper under a "Today" label
The cost-history chart itself should still preserve historical rows. The bug is specifically about using historical rows as current-day summary values.
Root Cause
Several code paths use "latest available daily bucket" semantics while the UI text says "Today".
That conflates two different concepts:
- Latest historical bucket: the newest day in the data set, useful for "Latest" labels and historical charts.
- Current local day bucket: entries whose date maps to the user's current local day, required for "Today" labels.
When the data set has no row for the current local day, selecting the latest row is incorrect for "Today". The result is stale historical usage presented as current usage.
The critical local-cost path was in CostUsageFetcher.tokenSnapshot(...). The old behavior selected the newest parseable day:
// Old behavior, simplified:
let currentDay = daily.data
.compactMap { parse(entry.date) }
.max { lhs.date < rhs.date }?
.entry
sessionTokens = currentDay?.totalTokens
sessionCostUSD = currentDay?.costUSD
This should not be used for fields named sessionTokens / sessionCostUSD when those fields feed UI text labeled "Today".
Correct Semantics
For displays titled Today:
- Match against the actual current local day.
- If the data set has historical rows but none for today, report zero.
- Preserve the historical totals, such as Last 30 days, separately.
For displays titled Latest:
- Continue using the newest valid historical bucket.
- This is appropriate for providers where current-day semantics are unavailable or not intended.
Recommended invariant:
A UI label of "Today" must never be backed by a "latest non-empty historical bucket" helper.
Proposed Fix
1. Add explicit current-day helpers to cost snapshots
Add helpers on CostUsageTokenSnapshot:
public func currentDayEntry(calendar: Calendar = .current) -> CostUsageDailyReport.Entry? {
Self.entry(in: self.daily, forLocalDayContaining: self.updatedAt, calendar: calendar)
}
public static func latestEntry(in entries: [CostUsageDailyReport.Entry]) -> CostUsageDailyReport.Entry? {
// Existing latest-day tie-breaking behavior lives here.
}
public static func entry(
in entries: [CostUsageDailyReport.Entry],
forLocalDayContaining date: Date,
calendar: Calendar = .current
) -> CostUsageDailyReport.Entry? {
let todayKey = localDayKey(from: date, calendar: calendar)
return entries.first { entry in
let rawDate = entry.date.trimmingCharacters(in: .whitespacesAndNewlines)
if rawDate == todayKey { return true }
guard let parsed = CostUsageDateParser.parse(rawDate) else { return false }
return localDayKey(from: parsed, calendar: calendar) == todayKey
}
}
The important part is that date comparison should happen at the local calendar-day level, not by "newest timestamp".
2. Make CostUsageFetcher.tokenSnapshot(...) choose current day by default
Update CostUsageFetcher.tokenSnapshot(...) so the default path uses the current local day:
let sessionEntry = useCurrentLocalDayForSession
? CostUsageTokenSnapshot.entry(in: daily.data, forLocalDayContaining: now)
: CostUsageTokenSnapshot.latestEntry(in: daily.data)
let hasHistoricalRows = !daily.data.isEmpty
return CostUsageTokenSnapshot(
sessionTokens: sessionEntry?.totalTokens ?? (hasHistoricalRows ? 0 : nil),
sessionCostUSD: sessionEntry?.costUSD ?? (hasHistoricalRows ? 0 : nil),
last30DaysTokens: last30DaysTokens,
last30DaysCostUSD: last30DaysCostUSD,
historyDays: historyDays,
daily: daily.data,
updatedAt: now
)
This keeps two important cases distinct:
- Empty history:
nilstill means "no known data". - Non-empty history but no current-day row:
0means "known zero today".
3. Keep explicit latest-day semantics where the UI says "Latest"
Add a parameter like:
useCurrentLocalDayForSession: Bool = true
Then call with false only for providers/surfaces that intentionally show "Latest".
In the local patch, Bedrock keeps latest semantics because its dashboard text uses "Latest" rather than "Today".
4. Add current-day summaries for Admin API snapshots
OpenAI and Claude Admin API snapshots have rolling summaries and a latestDay summary. They also need a currentDay summary:
public var currentDay: Summary {
self.summary(forLocalDayContaining: self.updatedAt)
}
public func summary(forLocalDayContaining date: Date, calendar: Calendar = .current) -> Summary {
let dayKey = Self.localDayKey(from: date, calendar: calendar)
let selected = self.daily.filter { bucket in
if bucket.day == dayKey { return true }
return Self.localDayKey(from: bucket.startTime, calendar: calendar) == dayKey
}
return Summary(
costUSD: selected.reduce(0) { $0 + $1.costUSD },
...
)
}
Then change UI sites labeled "Today" to use currentDay, not latestDay.
Edge Cases to Cover
- History has no rows: Today should remain unavailable/unknown, not necessarily zero.
- History has rows but none for current local day: Today should be zero.
- History has a current local day row with zero cost/tokens: Today should be zero.
- History has current local day plus older rows: Today should use only current local day; Last 30 days should include all rows.
- Date strings may be plain
yyyy-MM-dd, ISO timestamps, or legacy month/day strings; matching should normalize through a local day key. - Invalid future calendar date strings, such as
2026-06-31, should not win latest-day selection. - Providers intentionally labeled
Latestshould keep newest-bucket behavior.
Why This Fix Is Low Risk
The fix separates semantics instead of changing all historical aggregation:
- Last 7/30/90 day totals continue to sum over the history window.
- Cost-history charts continue to use the available daily data.
- Latest-bucket behavior remains available through
latestEntry/latestDay. - Only UI fields labeled "Today" move to current-local-day semantics.
The biggest behavior change is intentional: users with historical usage but no current-day usage now see $0.00 · 0 tokens under Today.
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 22, 2026, 9:39 AM ET / 13:39 UTC.
Summary Keep open: current main still backs Today-labeled cost and Admin API summaries with latest historical bucket semantics, so the reported stale Today display remains necessary to fix.
Reproducibility: yes. by source inspection: a non-empty historical daily report whose newest entry is before now is still selected as the session entry and displayed under Today. I did not run a fixture because this review must keep the checkout read-only.
Next step Queue a focused fix PR because the bug is source-reproducible, VISION-aligned, and has clear model/menu test seams.
Review details
Best possible solution:
Make Today labels consume current-local-day summaries, while leaving latest-bucket behavior available for surfaces explicitly labeled Latest.
Do we have a high-confidence way to reproduce the issue?
Yes, by source inspection: a non-empty historical daily report whose newest entry is before now is still selected as the session entry and displayed under Today. I did not run a fixture because this review must keep the checkout read-only.
Is this the best way to solve the issue?
Yes: explicit current-local-day helpers plus preserved latest-bucket helpers are the narrow maintainable fix for the label/semantics mismatch without changing historical charts.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
- No tests were executed because this was a read-only review and test runs can create build artifacts; the reproduction is from source inspection rather than a runtime fixture.
Codex review notes: model internal, reasoning high; reviewed against ef8007fc16ce.
Label changes
Label changes:
- add
P2: The issue describes a normal-priority usage accuracy bug with limited blast radius in cost display surfaces. - add
impact:other: The affected problem is user-visible usage/cost accuracy, which is meaningful but outside the more specific owned impact taxonomy. - add
issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label. - add
clawsweeper:source-repro: Current issue advisory state selects this label. - add
clawsweeper:queueable-fix: Current issue advisory state selects this label. - add
clawsweeper:fix-shape-clear: Current issue advisory state selects this label.
Label justifications:
P2: The issue describes a normal-priority usage accuracy bug with limited blast radius in cost display surfaces.impact:other: The affected problem is user-visible usage/cost accuracy, which is meaningful but outside the more specific owned impact taxonomy.
Evidence reviewed
Acceptance criteria:
- swift test --filter CostUsageFetcherTests
- swift test --filter MenuDescriptorOpenAIAPITests
- swift test --filter OpenAIAPIMenuCardModelTests
- make test
- make check
What I checked:
- Repository policy read: AGENTS.md was read fully; its guidance favors focused parser/model tests and avoiding live provider or Keychain-touching validation for this kind of usage logic. (
AGENTS.md:1, ef8007fc16ce) - Vision fit: VISION.md describes CodexBar as a provider limits, credits, spend, and usage control surface and lists bounded bug fixes as merge-by-default. (
VISION.md:1, ef8007fc16ce) - Local cost source path: CostUsageFetcher.tokenSnapshot(from:now:historyDays:) selects the most recent parseable daily entry with max and assigns it to sessionTokens/sessionCostUSD, which feed Today-labeled UI surfaces. (
Sources/CodexBarCore/CostUsageFetcher.swift:276, ef8007fc16ce) - Admin API menu source path: MenuDescriptor renders OpenAI and Claude Admin API summaries with a Today label while reading usage.latestDay. (
Sources/CodexBar/MenuDescriptor.swift:292, ef8007fc16ce) - OpenAI Admin API snapshot source path: OpenAIAPIUsageSnapshot.latestDay is summary(days: 1), summary(days:) selects daily.suffix(...), and toCostUsageTokenSnapshot copies that latest summary into session values. (
Sources/CodexBarCore/Providers/OpenAI/OpenAIAPIUsageSnapshot.swift:144, ef8007fc16ce) - Claude Admin API snapshot source path: ClaudeAdminAPIUsageSnapshot.latestDay is also summary(days: 1), backed by daily.suffix(...), so it has latest-bucket rather than current-local-day semantics. (
Sources/CodexBarCore/Providers/Claude/ClaudeAdminAPIUsageSnapshot.swift:132, ef8007fc16ce)
Likely related people:
- steipete: Blame attributes the affected cost snapshot and Admin API summary code in this checkout to Peter Steinberger's v0.37.2 release commit, and the current main follow-up is also authored by Peter Steinberger. (role: recent area contributor; confidence: medium; commits: f380287041b8, ef8007fc16ce; files:
Sources/CodexBarCore/CostUsageFetcher.swift,Sources/CodexBar/MenuDescriptor.swift,Sources/CodexBarCore/Providers/OpenAI/OpenAIAPIUsageSnapshot.swift)
How this review workflow works
- ClawSweeper keeps one durable marker-backed review comment per issue or PR.
- Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
- A fresh review can be triggered by eligible
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch. - PR/issue authors and users with repository write access can comment
@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only. - Maintainers can also comment
@clawsweeper reviewto request a fresh review only. - Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
- Maintainer-only repair and merge flows require explicit commands such as
@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review. - Maintainers can comment
@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.