Repository navigation
Conversation
wenbaolu6666-design
force-pushed
the
WenPaul/sync-home-overview-usage-range
branch
from
December 4, 2026 14:43
0dbd161 to
f8a8abf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Syncs the Home Overview usage window with the time range selected in Usage Records (one-way follow: users continue changing the time range in Usage Records, and Home automatically follows it instead of being locked to the last 24 hours).
Root Cause
loadHomeOverviewinsrc/services/homeOverview.tshardcoded a rolling 24-hour window (nowMs - 24htonowMs) instead of reading the persisted Usage Records range preference (cpa-gui.usage-records-range.v1).HomeOverviewCardsinsrc/pages/HomeOverviewCards.tsxhardcoded the statichome.overview.periodlabel ("Last 24 hours").UsageRecordsPagepersistedrange = 'custom'without persistingcustomStart/customEnd, causing custom bounds to be lost after leaving the page or reopening the app (falling back to an unbounded all-time query).useHomeOverviewdid not subscribe toonUsageRecordsUpdatedevents and only refreshed every 60 seconds, causing noticeable lag relative to Usage Records.Changes
src/services/usageRange.ts,src/services/usagePreferences.ts,src/pages/UsageRecordsPage.tsx):UsageRange/UsageRangeSelectiontypes,loadUsageRangeSelection(),buildUsageRangeQuery(), andformatUsageRangePeriod().cpa-gui.usage-records-custom-start.v1andcpa-gui.usage-records-custom-end.v1(both match the existingcpa-gui.usage-preference allowlist in Rust; no backend changes required).subscribe()andsyncFromStorage()support toUsagePreferencesfor in-app and cross-tab updates.UsageRecordsPageto persist range and custom timestamp changes immediately and reset pagination when custom bounds change.src/services/homeOverview.ts,src/pages/useHomeOverview.ts,src/pages/HomeOverviewCards.tsx,src/pages/Kernel.tsx):loadHomeUsage()and updatedloadHomeOverview()to queryget_usage_overviewwith the shared range selection (defaulting to rolling 24 hours when unset for backward compatibility).useHomeOverviewto track usage range preference changes and listen toonUsageRecordsUpdatedvia a throttledcreateRefreshScheduler(1_000)that refreshes only usage metrics (avoiding extra credential/model reloads or disturbing model health checks), with monotonic request ID guards against out-of-order responses.HomeOverviewCardsto render the activeusage.range.*label dynamically (and formatted custom date-time bounds with a full-yeartitletooltip when custom bounds are set).tests/usageRange.test.ts,tests/homeOverview.test.ts,tests/homeOverviewCards.test.tsx):4h,24h,today,7d,30d,all,custom), custom bound persistence, invalid range fallback, cross-tab storage synchronization, and Home overview heading period rendering.Verification
bun run check(tsc --noEmit): passed with 0 errors.bun run build(tsc && vite build): passed.bun testacross 8 related test suites (usageRange,homeOverview,homeOverviewCards,usagePreferences,usageBackgroundRefresh,usageViewScope,refreshScheduler,activePolling): 41 passed, 0 failed (1,213 assertions).v0.3.130-test.home-usage-range.1) via GitHub Actions and verified live on Windows: switching between preset ranges (4h,24h,today,7d,all) andcustombounds updates the Home overview period label, request count, and success rate to match Usage Records, preserves custom bounds across restarts, and refreshes promptly on new requests.