fix(usage): update dashboard stats in real time - #3388
Open
ndhao164 wants to merge 1 commit into
Open
Conversation
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 Usage dashboard does not update aggregate metrics after a request completes. Total requests, input tokens, output tokens, cached tokens, estimated cost, breakdown tables, and the chart remain stale until the page is reloaded or the selected period changes.
For providers that report Anthropic-shaped usage (
input_tokensandoutput_tokens), Today and 24h totals can also remain at zero even though the request was persisted.Root cause
The SSE endpoint recalculates usage after persisted requests, but the client discards the aggregate fields and only merges active requests, recent requests, pending state, and provider errors.
The stream also calls
getUsageStats()without the selected period, producing an all-time snapshot that cannot safely replace the period-filtered REST response. In addition, the Today/24h aggregation path reads onlyprompt_tokensandcompletion_tokensfrom the raw token payload instead of using the normalized SQLite columns.Fix
input_tokensandoutput_tokensVerification
git diff --checkThe full Vitest and ESLint suites were not run because dependencies are not installed in this workspace.