Repository navigation
revert(usage): remove the top-N key cap and global spend rollup code from rc/1.103.0 - #43326
Conversation
|
| normalized = " ".join(sql.split()) | ||
| fallback = "COALESCE(NULLIF(model_group, ''), model)" | ||
| assert f"{fallback} AS model_group" in normalized | ||
| assert ( | ||
| f"GROUPING(date, api_key, model, {fallback}, " | ||
| "custom_llm_provider, mcp_namespaced_tool_name, endpoint) AS group_level" in normalized | ||
| ) | ||
| assert f"(date, {fallback}), (date, {fallback}, api_key)," in normalized | ||
| assert "(date, model_group)" not in normalized | ||
| assert "COALESCE(model_group, model)" not in normalized |
There was a problem hiding this comment.
Behavioral coverage was lost The replacement test checks SQL text after the PostgreSQL-backed test was deleted. Repository guidance requires functional regression tests; restore that coverage before merging.
Context Used: AGENTS.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| # Postgres computes every rollup level the response needs — per-date | ||
| # totals, per-(date, model), per-(date, model, api_key), per-provider, | ||
| # etc. — in a single pass via GROUPING SETS. The GROUPING() bitmask | ||
| # encodes which level a row belongs to so Python can dispatch rows | ||
| # straight into their buckets without re-summing. The leaf grouping | ||
| # is omitted on purpose: nothing in the response shape needs it once | ||
| # all the rollups are present. | ||
| # |
There was a problem hiding this comment.
Unnecessary implementation comments This block narrates the query and dispatcher, as do other added explanations. Repository guidance restricts source comments to specific exceptions; remove these before merging.
Context Used: AGENTS.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| SUM(failed_requests)::bigint AS failed_requests, | ||
| SUM(total_response_time_ms)::bigint AS total_response_time_ms, | ||
| SUM(timed_requests)::bigint AS timed_requests | ||
| FROM "{pg_table}" |
There was a problem hiding this comment.
Low: Unbounded usage aggregation
This query now groups the full per-key table without a key limit. An authenticated user can populate spend under many personal keys and repeatedly call /user/daily/activity/aggregated, causing the database and proxy worker to materialize and serialize every key across multiple grouping sets. Retain a bounded key ranking, paginate these breakdowns, or enforce a strict result-cardinality limit.
PR overviewThis PR reverts usage aggregation changes from rc/1.103.0 by removing the top-N API key cap and global spend rollup logic from the daily activity aggregation endpoint. One resource-exhaustion concern remains open: an authenticated user with many personal keys can repeatedly request the aggregated daily activity breakdown, forcing unbounded database aggregation and response serialization. This could degrade database and proxy-worker availability until result cardinality is bounded or paginated. Open issues (1)
Fixed/addressed: 0 · PR risk: 5/10 |
TLDR
Problem this solves:
How it solves it:
LiteLLM_DailyGlobalSpendmodel and migration in placeUser Flow
Before: an admin on v1.103.0-rc.1 with more keys than the cap sees only the top-spend keys on the Usage pages
After: the same admin sees every key again, the way v1.102 behaved
Affected release
Regression since v1.103.0-rc.1
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/test_litellm/<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 more@greptileaito re-request a review after pushing changes)No new tests since this is a revert. The reverted tests go away with the code they covered, and the remaining usage tests pass on this branch (703 Python, 351 vitest)
Type
🐛 Bug Fix
Caveats (if any)
Medium
Low
LiteLLM_DailyGlobalSpendsits idle on this rc since nothing writes or reads it