fix: keep chart in sync with toolbar on background stat refreshes#830
Merged
Conversation
When updateTokenStats() runs every 5 minutes, it refreshes lastDailyStats (fresh 30-day data) and correctly updates the toolbar. However, when pushing data to the chart it prefers lastFullDailyStats (the 365-day dataset computed once when the chart was first opened) -- which is never refreshed by the background timer. This caused the chart to show stale session/token counts for today while the toolbar showed the correct (much higher) numbers. Fix: after each calculateDetailedStats() call, merge the fresh 30-day dailyStats entries into lastFullDailyStats. Sessions older than 30 days are unaffected (their historical dates don't change), while the recent 30-day window now stays accurate on every background refresh. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Problem
The chart and toolbar were showing different "today" token counts. For example, the toolbar would show 17M tokens used today while the chart only showed ~4.3M for the same day. The details screen was also counting more sessions (20) than the chart (3).
Root cause
_runUpdateTokenStats()runs every 5 minutes and correctly refresheslastDailyStats(fresh 30-day window) to update the toolbar and details panel. When it also pushes an update to the open chart panel, it preferslastFullDailyStats(the 365-day dataset computed once when the chart was first opened) -- but that full-year dataset is never refreshed by the background timer. So the chart always displayed the stale snapshot from when the chart was opened, while the toolbar reflected current data.Fix
After each
calculateDetailedStats()run, merge the fresh 30-daydailyStatsentries intolastFullDailyStatsby upsert on the date key. Sessions older than 30 days are unaffected (their historical dates are stable), while the recent window stays accurate on every background refresh.This is a surgical 9-line addition in
extension.tswith no API or schema changes.