Skip to content

Fix cost history dates for non-Gregorian calendars#2417

Open
mijatovicmilan wants to merge 3 commits into
steipete:mainfrom
mijatovicmilan:agent/fix-gregorian-cost-usage-dates
Open

Fix cost history dates for non-Gregorian calendars#2417
mijatovicmilan wants to merge 3 commits into
steipete:mainfrom
mijatovicmilan:agent/fix-gregorian-cost-usage-dates

Conversation

@mijatovicmilan

@mijatovicmilan mijatovicmilan commented Jul 23, 2026

Copy link
Copy Markdown

Summary

  • Keep persisted cost-history day keys and local session partition traversal Gregorian while preserving the selected time zone.
  • Propagate the selected calendar through Codex, Claude, Pi, current-day selection, project/session breakdowns, and cached snapshot hydration.
  • Persist the time-zone identifier in cost caches and rebuild cached day buckets when the system time zone changes.
  • Rotate affected Claude, Vertex AI, and Pi cache artifacts; Codex cache invalidation follows the regenerated parser hash.
  • Add boundary-focused regression coverage for non-Gregorian calendars, time-zone changes, warm caches, and appended sessions.

Root cause

The local cost scanner used Calendar.current both for persisted YYYY-MM-DD keys and for YYYY/MM/DD session-directory traversal. With a Thai/Buddhist calendar, that produced year 2569, while Codex session files are stored under Gregorian 2026/... paths. Incremental refreshes therefore stopped discovering new session files, even though a cache rebuild during an app update could appear to catch the chart up.

Day buckets also depend on the calendar's time zone, but the persisted cache identity did not record it, and several scan/fetch paths discarded the injected calendar. After travel or a system time-zone change, unchanged history could remain assigned using the old zone while newly parsed records used the new zone.

Impact

Local token/cost history now updates correctly for users whose system calendar is non-Gregorian and is fully re-bucketed after a time-zone change. Existing users receive one cold cache rebuild after updating. Remote quota fetching and UI presentation are unchanged.

Validation

  • swift test --filter CostUsageCalendarTests — 6 passed
  • Related cache/fetcher/Pi/Claude regression suites — 49 passed
  • make check — passed; parser hash, SwiftFormat, and SwiftLint are clean
  • make test — completed 48 groups before an existing global SwiftPM test-helper preference (settingsSpendDashboardDays=7) contaminated the Spend Dashboard group. Both affected suites pass independently after restoring the expected 30-day preference; no code in that path is changed by this PR.
  • Fresh review of commit 83794e87 — no actionable P0–P3 findings

Related reports

This is distinct from #1705 / #1710 (selecting the actual current-day bucket), #2089 (refresh debounce and TTL staleness), and #2397 (showing validated cache data while refreshing). None address Gregorian session paths being traversed with a non-Gregorian calendar or persisted buckets surviving a time-zone change.

No UI changes; screenshots are not applicable.

@mijatovicmilan
mijatovicmilan marked this pull request as ready for review July 23, 2026 11:54
@clawsweeper

clawsweeper Bot commented Jul 23, 2026

Copy link
Copy Markdown

ClawSweeper status: review started.

I am starting a fresh review of this pull request: Fix cost history dates for non-Gregorian calendars This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

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