Repository navigation
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Reviewed by Codex gpt-6-luna (xhigh); verified and validated by Claude Thermo-nuclear review findings:
No other findings. |
|
The P2 finding is fixed and pushed ( Commands: |
Port upstream 0.67.0 tokenCostUsageBucketTimeZone: a saved IANA zone (settings cost_usage_bucket_time_zone) buckets local cost history for Codex, Claude, Pi, Muse, Antigravity and OpenCodex, so day keys and month-to-date bounds survive a machine zone change. Codex caches record the zone and rebuild when it changes; unstamped caches are kept. Grok and OpenCode Go stay on the machine calendar as upstream.
|
Lane B review: fixes at 72fafbf I reviewed this PR against upstream Gap fixed in this push: the PR deferred the pinned cost time zone, but the 0.67.0 bullet requires it ("keep rolling windows and the pinned cost time zone"). Upstream buckets local cost history in a saved zone, so day keys and month-to-date bounds do not move when the machine zone changes. This push ports it:
Divergences, listed in the PR body:
Validation (
UI proof: not applicable, because nothing in the UI changes. |
…erve /cost (stacked on #648)
…d-aware spend surfaces (stacked on #648)
|
Adversarial validation passed at 545d39d Scope: add CostReportingPeriod core and range-aware cost scanners (#648, upstream 0.67.0), validated as merged into release/v0.70.0 (merge 545d39d). Attacks (highest-risk semantics, from the merged tree):
No defects found. READY for the un-draft rule. |
Summary
Adds the core cost reporting period model, the pinned cost time zone, and range-aware local cost scanners. This is part A of upstream 0.67.0 item 1. Nothing user-visible changes in this PR: the saved default is
rolling:30,CostScanner::new(days)keeps its exact rolling behavior, and history stays bucketed in the machine zone until a caller applies a saved zone. The CLI--periodandservewiring (#653) and the desktop wiring (#665) are separate follow-up PRs.rust/src/cost_reporting_period.rs:CostReportingPeriod=Rolling(1..=365)|MonthToDate|AllAvailable, raw formsrolling:N,month-to-date,all.bounds(now, tz, earliest),days,entriesfiltering andidentity(now, tz)(raw|tz|start|end) for cache keys. Month and day arithmetic is done on calendar dates, so leap years and 23/25 hour DST days are exact. Legacy integer selections migrate unchanged (migrated).Settings.cost_reporting_period(settings.rs,settings/raw.rs), defaultrolling:30. A missing or unreadable value loads as the default.CostScannerholds a period instead ofdays.new(days)isfor_period(Rolling(days)). A newcost_scanner/window.rsresolves the period into scan windows.clamp_window_days(1..=36,500), so All is not clamped to 365.YYYYpartition (first_codex_partition_date), so the date-partition walk does not probe empty history. The existing range-keyed Codex cache already covers wider windows.daily_range(since, now); month to date is the current UTC month start, All is the current month plus 13 months, end is tomorrow (Cost Explorer buckets are UTC).Pinned cost time zone (upstream
tokenCostUsageBucketTimeZone)Settings.cost_usage_bucket_time_zone: an IANA zone name; empty means the machine zone. Values are trimmed on load and anything that is not an IANA zone reads as empty, like the upstream setter.settings/cost_time_zone.rs(new):pin_cost_usage_bucket_time_zone()saves the machine zone when nothing valid is saved and returns whether the caller must save. When the system zone cannot be read safely it pins nothing, so theUTCfallback is never persisted.apply_cost_usage_bucket_zone()applies the saved zone to the process.cost_reporting_period.rs:cost_bucket_zone()/set_cost_bucket_zone()hold the process-wide zone; the default is the machine zone.CostTimeZone::from_identifier,is_valid_identifierandpin_identifiermirror upstreamCostUsageBucketTimeZone.core::try_local_timezone_name()returnsNoneinstead of the fallback.costandservecommands apply the saved zone without pinning (Port upstream 0.67.0: cost --period and period-aware serve /cost (stacked on #648) #653, upstreamCLICostCommand/CLIServeCommand).Each local source buckets days according to the calendar upstream gives it:
CostUsageFetcheroptions.calendarCostUsageFetcheroptions.calendarMuseLocalUsageCachefallbackOptions.calendarbucketCalendarservedashboard "today"CLIServeCommandGrokLocalSessionScannerusesCalendar.currentOpenCodeGoLocalUsageReaderCache behavior:
bucket_time_zone(upstreamtimeZoneIdentifier). A cache bucketed in a different zone is rebuilt, and status reads ignore it. Caches written before the stamp existed are kept, because they were bucketed in the machine zone, which is what first launch pins.Upstream reference
9f76e1194, feat(cost): add shared calendar reporting periods steipete/CodexBar#3981).v0.67.0ofsteipete/CodexBar(GET only, no upstream writes):Sources/CodexBarCore/CostReportingPeriod.swiftSources/CodexBarCore/CostProvenance.swift(CostUsageBucketTimeZone)Sources/CodexBar/SettingsStore.swift,SettingsStore+Defaults.swift(tokenCostUsageBucketTimeZone,pinCostUsageBucketTimeZoneIfNeeded)Sources/CodexBarCore/CostUsageFetcher.swiftSources/CodexBarCore/Vendored/CostUsage/CostUsageScanner.swift(firstPartitionDate,timeZoneIdentifiercache checks),CostUsageCacheModels.swiftSources/CodexBarCore/Providers/Muse/MuseLocalUsageCache.swiftSources/CodexBarCore/Providers/Bedrock/BedrockUsageStats.swift(dailyRange)docs/cost-reporting-periods.mdTests/CodexBarTests/CostReportingPeriodTests.swift,CostReportingPeriodProofTests.swift(date-math cases ported in spirit)Ported / Deferred
Ported: everything listed in the summary.
Deferred, with the follow-up that owns it:
--period,serve/costand desktop Usage & Spend wiring (Port upstream 0.67.0: cost --period and period-aware serve /cost (stacked on #648) #653 and Port upstream 0.67.0: History window setting and period-aware spend surfaces (stacked on #648) #665). Applying and pinning the saved bucket zone lands there too.usage_spend.rs,codex_workspacesandagent_sessions/remote.rs.--remoteand--summary-onlystay limited to 1..=365.daily_rangehelper lands here. The consumer (DAILY Cost Explorer fetch intoCostSnapshot.daily) is in Port upstream 0.67.0: History window setting and period-aware spend surfaces (stacked on #648) #665.Intentional divergences from upstream:
now - N*24hcutoff and a UTCtoday - Nreported start. Month to date and All use pinned-zone midnights.calendarIdentifierstamp. Windows always buckets with the Gregorian calendar.Validation
Run with
+1.98.0on E-cores (head72fafbfa):cargo fmt --all --check: cleancargo clippy --workspace --all-targets -- -D warnings: passcargo test -p codexbar: 2195 passed, 0 failed, 1 ignored (unit); main 1 passed; doc 0cargo test -p codexbar-desktop-tauri: 461 passed, 1 failed. The failure iscommands::tests::bootstrap_payload_exposes_every_provider_variant, which reads host settings; it is known and fixed by Make the bootstrap catalog test hermetic (#684) #711. The Tauri crate is not modified here.cost_reporting_period: upstream month table, leap year, DST, identity, bounds, migration, entries, serde, plus saved-zone resolution, the pin identifier and the process-wide bucket zone.settings::cost_time_zone: normalization, settings file round trip, pinning.core::jsonl_scannercache_zone: zone mismatch rebuild, legacy unstamped cache kept, save stamp, status ignores another zone.cost_scanner/tests/period.rs: window shapes, first partition, Codex All beyond a year, Codex MTD excludes previous month.daily_range.Affected areas
rust/src/cost_reporting_period.rs,cost_scanner/window.rs,settings/cost_time_zone.rs.rust/src/cost_scanner.rs,cost_scanner/codex*,pi_session_cost.rs,codex_costs.rs,codex_costs/quota_windows.rs,codex_workspaces/indexer.rs.core/jsonl_scanner*(Codex cache zone stamp),core/timezone.rs.settings.rs,settings/raw.rs.spend_contract/opencodex.rs,cli/serve/dashboard/source.rs, and providersopencodego,muse,antigravity,bedrock.There are no Tauri or frontend changes and no new dependencies.
UI proof
Not applicable. No UI, tray, settings surface, float bar or theme change.