Repository navigation
feat(ui): usage pages consume bounded daily activity routes instead of storing all keys client-side - #43409
Conversation
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
|
|
|
Fixed in 8c3fe18: |
|
Fixed in 8c3fe18: |
|
Fixed in 8c3fe18: merge order is now |
|
Same fix as the thread above (8c3fe18): local rows win the merge, remote rows only fill in keys absent from the aggregate. |
|
By design: the agent breakdown is intentionally unscoped by the selected teams (the base also fetched agents with a |
|
Fixed in 8c3fe18: when the key-leakage request fails the card renders "Could not load key usage for this range." instead of the empty-state text. Test added in CacheLeakageCard.test.tsx. |
|
Fixed in 8c3fe18: the search result records the |
|
Intentional, unchanged from the base: |
|
Fixed in 8c3fe18: the agent breakdown now uses |
|
Fixed in 428c262: |
1 similar comment
edaddb4 to
7570138
Compare
c5981eb to
986a59f
Compare
58a4f66 to
590bb17
Compare
|
@greptileai review 590bb172e9: same single layer-3 commit re-stacked onto litellm_usage_service tip bd00c35521 (layer 2 rebased onto main after layer 1 merged as aa601ce); no code delta from 58a4f66b08 |
|
bugbot run |
|
@greptileai review b4f6f42bbd: same single layer-3 commit re-stacked onto litellm_usage_service tip dbbf22e795 (layer 2 moved again, agent_endpoints only); no code delta from 590bb172e9 |
|
bugbot run |
590bb17 to
b4f6f42
Compare
b4f6f42 to
14673bc
Compare
|
@greptileai review 14673bcd05: same single layer-3 commit re-stacked onto litellm_usage_service tip 02d0337 (layer 2 moved again, Python-only base changes); no code delta from b4f6f42bbd |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 14673bcd053f637fb955faf3a2d166fc4b3cf124. Configure here.
Resolves LIT-8899 Usage, cost optimization, user and team pages read the aggregate, paginated key, search, model top key, cache leakage and export routes added by the lower layers instead of downloading every key's daily rows into the browser. Key detail, model top key and search failures render explicit errors with retry controls, Overall Usage shows a loader while the aggregate is in flight, Retry on a failed first key page shows the loading state while it refetches, a short query keeps the loader or first page error visible instead of No keys match, key paging advances by the server offset so a page of already loaded keys moves on and only an empty page ends paging, and search results are stored as rows so a new teams array from the parent does not restart an in-flight search, and the global Cost tab shows a loader instead of zero totals while the aggregate reloads. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
14673bc to
84e7d45
Compare
|
@greptileai review 84e7d45: layer 2 (#43408) merged into main as 54a51c8, so the single layer-3 commit is now rebased directly onto main; tree is identical to 14673bcd05, no code delta |
|
bugbot run |
…t budget back under its ceiling (#44114) Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> #43409 landed three four-condition boolean chains in KeyActivityPanel.tsx, putting local/no-long-condition-chain at 197 against a max of 196, so frontend-lint fails on every PR that touches the dashboard. Name the shared isFiltering && !searching and localOnly && pageRows.length === 0 sub-expressions so each remaining chain has three conditions, and ratchet the max down to the new count of 194. Co-authored-by: yassin <yassin@berri.ai>
TLDR
Problem this solves:
/{entity}/daily/activity?page_size=1000&page=Nand kept every key's rows in React stateHow it solves it:
/{entity}/daily/activity/aggregatedresponse for totals and charts/{entity}/daily/activity/aggregated/keysas the user scrolls, until every key is listedschema.d.tsinstead of hand-written interfacesmain(User: <email or id>, hidden when it equals the alias), now read from the server row's metadataIntentional product change: Key Activity rows start collapsed with key totals only, and each key's charts load on first expand. The "Overall Usage" summary always shows complete totals, and the user never sees a top-N limit or a "Load more" control. When an aggregate request fails, the page shows an error (with Retry where the panel has one) instead of falling back to draining
/{entity}/daily/activity?page=N; that fallback was the unbounded download this stack removes, and both routes are served by the same proxy build from the same tableLayer 3 of 3: UI, stacked on #43408 (LIT-8898, one commit on current main at tip 02d0337); layer 1 #43398 (LIT-8897) is merged into main as aa601ce. This PR contains no Python changes; the routes it consumes come from the service layer. The stack replaces #41293 instead of building on it, and the #41293 revert (#43596) is already in main
Files changed
src/components/UsagePage/dailyActivityApi.tsschema.d.tssrc/components/UsagePage/keyActivityData.tssrc/components/UsagePage/components/keySearch.tssrc/components/UsagePage/components/KeyActivityPanel.tsxfetchKeyPagewith a scroll sentinel, searches throughsearchKeys, loads a key's charts throughfetchKeyDetailon first expand. Failed first page, later page, search and key detail each render an error with Retry instead of an empty state, a failed later page does not retry through the sentinel, and the summary shows a loader whilesummaryLoadingis truesrc/components/UsagePage/types.tsschema.d.tssrc/components/activity_metrics.tsxfetchTopApiKeyswhen a model row expands (the row open by default fetches on mount). A failed request renders an error with Retry; an empty success stays hidden. Agent rows do not receivefetchTopApiKeys, since agent IDs are not model groupssrc/app/(dashboard)/usage/_components/hooks/useAggregatedDailyActivity.tssrc/app/(dashboard)/usage/_components/hooks/usePaginatedDailyActivity.tssrc/app/(dashboard)/usage/_components/components/EntityUsage/entityFetchFns.tsENTITY_APImaps team, tag, user, org and agent to their route family so the view does not switch on entity type inlinesrc/app/(dashboard)/usage/_components/components/EntityUsage/EntityUsage.tsxKeyActivityPanelto the entity's key page, search and detail routes; the Cost panel and Key Activity show a loader while the aggregate loadssrc/app/(dashboard)/usage/_components/components/UsagePageView.tsxsrc/app/(dashboard)/cost-optimization/_components/useCacheLeakageKeys.tssrc/app/(dashboard)/cost-optimization/_components/CacheLeakageCard.tsxuseCacheLeakageKeys; model rows still derive from the aggregate model rollupssrc/app/(dashboard)/cost-optimization/_components/costOptimizationUtils.tssrc/app/(dashboard)/cost-optimization/_components/CostOptimizationView.tsx,UsageTab.tsx,useDailyActivityRange.tssrc/components/EntityUsageExport/EntityUsageExportModal.tsx,ExportTypeSelector.tsx,UsageExportHeader.tsx,types.ts,utils.ts/{entity}/daily/activity/export?export_type=...&format=...and saves the response body. The in-browser CSV/JSON assembly and the "export blocked" reason are deleted;daily_with_usersis offered only where the server route offers itsrc/components/EntityUsageExport/exportBlockedReason.tssrc/components/shared/PaginationStatusAlerts.tsxsrc/components/shared/ScopedSavingsTab.tsx,src/components/chat/UsagePanel.tsxsrc/components/networking.tsxsrc/lib/http/client.tseslint-suppressions.jsonUser Flow
Before: an admin on a large deployment opens Team Usage and the browser holds every key's rows, ranks keys from what it downloaded, and builds the export itself
After: the same admin sees complete totals and every key, but the browser only ever holds one page of key totals at a time plus the rows they expand
/team/daily/activity/aggregated?...for totals and one GET/team/daily/activity/aggregated/keys?offset=0&limit=50; Key Activity shows "Overall Usage" with the complete totals and the key countoffset=50andoffset=100, and every key is listed with no limit notice/team/daily/activity/aggregated/search?...&search=<query>, and expanding the result loads its daily charts/team/daily/activity/export?...&export_type=daily_with_keys&format=csvLinear ticket
Resolves LIT-8899
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreScreenshots / Proof of Fix
Proxy on :4000 from this checkout, Postgres seeded by writing directly into the daily spend tables, dashboard on
next dev:3000. After was captured on the working tree that became 689c868e19, minus the "Search failed" label that replaced "0 matching keys" on a failed empty search. The behavior changes between 689c868e19 and the current head are that Retry on a failed first key page shows "Loading keys..." while it refetches instead of leaving the error on screen (covered byKeyActivityPanel.integration.test.tsx), that each model top key row shows its owner under the alias where the server reports one, the same line #43642 added to the client-side list onmain(covered byactivity_metrics.test.tsx), and the three Bugbot fixes from the 914d8b2 round: a one-character query keeps the loader or the first page error instead of "No keys match", key paging advances by the server offset rather than the deduplicated row count, so a page of already loaded keys moves on and only an empty page ends paging, and search results are stored as rows so a newteamsarray from the parent does not restart an in-flight search (all covered byKeyActivityPanel.integration.test.tsxandkeyActivityData.test.ts). The head was rebased onto the rewrittenlitellm_usage_servicetip a7b05c3 (layers 1 and 2 now onmain); the three conflicts were all in the client-side top-key aggregation this PR deletes. Every request the browser made is in the captured request log; nodaily/activity?page=request appears in any After flowBefore (d116e70)
Key Activity totals and paging
Failure states
daily/activity?page=Nrequest leaves the page showing whatever pages arrived, with no error and no way to retryExport
After (689c868e19)
Key Activity totals and paging
/user/daily/activity/aggregated/keys?offset=0&limit=50loads, then the first 50 collapsed rows/user/daily/activity/aggregated?...&api_key=<key>&api_key_limit=1and shows that key's daily charts/team/daily/activity/aggregatedis in flight, then the complete totals and chartsagent-betashows $2.80, 210 requests and a daily spend chart, and nomodel_top_keysrequest is made for an agent row (agent IDs are not model groups). Model Activity: expanding a model row is the first time GET/team/daily/activity/aggregated/model_top_keys?...&model_group=<model>&by_model_group=truefires, and its ranking matches the aggregateoffset=0were captured on the 130-key fixture at 3de7231ddd; those paths did not change between 3de7231ddd and this headFailure states
offset=0and the rows appearExport
/team/daily/activity/export?...&export_type=daily_with_keys&format=csvreturns 200 and the file covers every key, including rows for a key that was never paged into the browser (captured at 3de7231ddd on the 130-key fixture; the export path did not change since)/user/daily/activity/aggregated/cache_leakage_keysranks keys by uncached prompt tokens server-side (captured at 3de7231ddd; unchanged since)Known fixture artifact, not a change in this PR: the Global Cost tab's request tiles read
/gateway/daily/activity, backed byLiteLLM_DailyGatewayRequests, which the ASGI middleware writes for real traffic. The seed wrote spend rows directly, so those tiles show 0 requests while spend and tokens are correct. The gateway tile code is unchanged on this branchTest diff note:
git diff <base> -- '*test*' | grep '^-.*expect'shows one removed line inKeyActivityPanel.integration.test.tsx, thekey-after-retryrow assertion; it was moved later in the same test so the loading state can be asserted before the retried request resolves, not droppedType
🆕 New Feature
🧹 Refactoring
Caveats (if any)
Medium
Low
next devthe first key page and some aggregate and model calls are requested twice per navigation (React strict mode). Rendered rows stay uniquedaily_with_usersexport is hidden for the user entity because the server route does not offer it thereusePaginatedDailyActivity.test.ts,PaginationStatusAlerts.test.tsx,exportBlockedReason.test.tsand the oldKeyActivityPanel.test.tsxasserted on the client-side paging, top-N notice and in-browser export that this PR deletes; their replacements (useAggregatedDailyActivity.test.ts,KeyActivityPanel.integration.test.tsx,keyActivityData.test.ts,networking.dailyActivity.test.ts) assert the server call and the rendered effect for each pathrequestId/scope checks; effects list every dependency), A4 (loading resets before each refetch and on range change), L5 (a failed request renders an error and Retry, never "No keys" or zero totals), S2 (offset paging over the server's stable spend ordering; the next request uses the server offset rather than the deduplicated row count, so a page of already loaded keys advances and only an empty page or reaching the reported total stops paging), T13 and T17 (every new failure and loading path has a test that asserts the call and the rendered effect, and each fails on the unfixed code). Not applicable: B1 and J4 (no writes, the client holds one page of key totals plus expanded details), V1 (no caller-chosenapi_base), H5 (no new Python;schema.d.tsis regenerated, not hand-edited)osv-scanwas red on the earlier head f7b5671 because the stack's old base carried lockfile versions (tornado 6.5.8, gitpython 3.1.61, moment 2.30.1, brace-expansion 5.0.9) thatmainhad already bumped; the lockfiles were byte-identical to that base. After the rebase onto themain-basedlitellm_usage_servicetip the job is green (914d8b2 and later heads)ui-unit-testswas red once on 9429a18427 becauseKeyActivityPanel.integration.test.tsxfired the sentinel intersection before the observer effect had attached under full-suite load (the test passed on every earlier head and in isolation). The test now waits for the observer to attach before triggering, so the second request is asserted deterministicallyFinal Attestation
Link to Devin session: https://app.devin.ai/sessions/f9bc96b46dfc4647b7ed2b71d5323e81
Open in Devin Desktop: https://app.devin.ai/desktop/session/f9bc96b46dfc4647b7ed2b71d5323e81?variant=devin
Requested by: @yassin-berriai