Skip to content

revert(usage): remove the top-N key cap and global spend rollup code from rc/1.103.0 - #43326

Merged
yuneng-berri merged 1 commit into
rc/1.103.0from
litellm_revert_top_n_usage_rc_1_103_0
Sep 26, 2026
Merged

yuneng-berri merged 1 commit into
rc/1.103.0from
litellm_revert_top_n_usage_rc_1_103_0

Conversation

@yuneng-berri

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • rc.1 Usage views only load spend for the top-N keys
  • Per-key widgets, exports and searches silently drop the long tail
  • The follow-up work to restore parity lives on main, not on this rc

How it solves it:

User 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

  1. The admin opens http://localhost:4000/ui/?page=usage with a date range covering more than 100 active keys
  2. The key widgets list only the top 100 keys by spend, and the page notes that only the top-spend keys were loaded
  3. The admin picks Export on the global usage view and the export is blocked because the key cap was reached

After: the same admin sees every key again, the way v1.102 behaved

  1. The admin opens http://localhost:4000/ui/?page=usage with the same date range
  2. The key widgets cover all keys, with no top-N note
  3. Export on the global usage view downloads the full data

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

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to 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

  • The table and migration stay on purpose
    • rc.1 databases already applied the migration
    • Dropping the model would let a later boot drop the table while the rollup marker survives
    • That would show $0 history when the feature returns
  • The committed UI bundle still ships the top-N UI
    • A separate UI rebuild PR for rc/1.103.0 lands after this one
  • Live proxy proof is not captured yet

Low

  • LiteLLM_DailyGlobalSpend sits idle on this rc since nothing writes or reads it

…pend rollup code from rc/1.103.0

Reverts the code from #41324 (merge 87694c2) and #41293 (merge 2e46b10).
The LiteLLM_DailyGlobalSpend model and migration stay so databases that applied
rc.1 keep a consistent table and rollup marker when the feature returns.
@yuneng-berri
yuneng-berri merged commit a78a439 into rc/1.103.0 Sep 26, 2026
7 checks passed
@yuneng-berri
yuneng-berri deleted the litellm_revert_top_n_usage_rc_1_103_0 branch September 26, 2026 18:14
@greptile-apps

greptile-apps Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Removes API key truncation and global spend rollup features.

The behavior change appears sound, but the explicit repository requirements for functional tests and source comments must be satisfied before merging

Findings

  1. P2 Behavioral coverage was lost ▶
  2. P2 Unnecessary implementation comments ▶

Summary

This revert restores uncapped per-key usage aggregation and retires reads and scheduled writes for the daily global spend rollup while retaining its database model. It also removes the cap indicators from UI source and API metadata

  • The replacement model-group test checks SQL structure rather than database behavior
  • Added explanatory comments conflict with the repository’s source-comment guidance

Reviews (1) · Last reviewed commit: "revert(usage): remove the top-N aggregat..."

Comment on lines +1337 to +1346
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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!

Comment on lines +746 to +753
# 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.
#

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@veria-ai

veria-ai Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

PR overview

This 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant