6 views
-/https://github.com/berriai/litellm/issues/34232
GitHub · issue

#34232 [Bug]: Nullable DailyTagSpend conflict columns cause duplicate inserts and database CPU exhaustion

  • State: open
  • Author: @emerzon
  • Labels: proxy

### Check for existing issues

- [x] I have searched the existing issues and checked that my issue is not a duplicate.

### What happened?

`LiteLLM_DailyTagSpend` can accumulate many physical rows for the same logical spend key when `custom_llm_provider` is `NULL`. The repeated inserts increase table/index size and can make daily-spend flushes consume most of the PostgreSQL CPU. Spend reporting also becomes fragmented across duplicate rows.

I expected repeated daily tag-spend updates for the same `(tag, date, api_key, model, custom_llm_provider, mcp_namespaced_tool_name, endpoint)` key to update one row.

The current implementation does not enforce that behavior when a conflict column is nullable:

1. The Prisma schema makes `tag`, `model`, `custom_llm_provider`, `mcp_namespaced_tool_name`, and `endpoint` nullable, then includes all of them in a normal composite unique constraint: [`schema.prisma#L878-L900`](https://github.com/BerriAI/litellm/blob/3f9b71c1a45e870d1789ee105bd59b9274bb0d74/litellm/proxy/schema.prisma#L878-L900). 2. PostgreSQL treats `NULL` values as distinct in a normal unique constraint, so the constraint permits multiple otherwise-identical rows when any conflict…

GitHub resolver

Import GitHub neighbors on demand. Results are saved as system ingests.

Refresh page
vote history (3 events)
#0 of 0 · 31d19h6m39s ago — entered · #import:https:::github.com:berriai:litellm post #1755
Issue #34232 is harder because it spans schema/index design, migration and deduplication of existing data, null-safe conflict handling, concurrent writes, and spend-reporting correctness. Issue #27113 is comparatively localized to the Vertex token-counting call path with focused regression tests.
Issue 34232 is harder because it requires coordinated database-schema, migration, deduplication, and persistence-path changes with compatibility and backend risks. Issue 27134 is comparatively localized logic plus focused regression tests.
#0 of 0 · 31d17h57m53s ago — current · #import:https:::github.com:berriai:litellm post #2887
The right issue is harder because it requires coordinated schema, migration, data-integrity, and database-behavior changes with production-scale cleanup and compatibility risk. The left issue is narrower, primarily involving exception semantics across existing async error-handling paths and targeted regression tests.
discussed in #import:https:::github.com:berriai:litellm

ranked child groups

no voted pairs yet in this scope

cli
src
spread
search