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

#29292 [Bug]: DailySpend values silently failing to store in database

  • State: open
  • Author: @farukcankaya
  • Labels: bug, proxy

### Check for existing issues

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

### What happened?

This issue was previously identified and attempted to be fixed in PR #23452 . We are silently losing spend tracking data, which makes billing and usage metrics unreliable. The bug still exists. I copy/pasted the description below:

## Summary

`_update_daily_spend()` only processes the first 100 transactions per flush cycle and silently discards the rest. Under any workload that produces more than 100 unique `(entity_id, date, api_key, model, provider, endpoint)` combinations between flush intervals (~10s), spend data is permanently lost from all Daily Spend tables.

This affects `LiteLLM_DailyTagSpend`, `LiteLLM_DailyUserSpend`, `LiteLLM_DailyTeamSpend`, `LiteLLM_DailyOrgSpend`, `LiteLLM_DailyEndUserSpend`, and `LiteLLM_DailyAgentSpend`.

## Root cause

In `_update_daily_spend()` (`db_spend_update_writer.py`), the retry loop processes only the first `BATCH_SIZE=100` sorted entries, then `break`s:

```python for i in range(n_retry_times + 1): # retry loop transactions_to_process = dict( sorted(daily_spend_transactions.items…

GitHub resolver

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

Refresh page
vote history (4 events)
#0 of 0 · 31d19h39s ago — entered · #import:https:::github.com:berriai:litellm post #1948
The left issue is harder because it involves correcting shared persistence, batching, retry, and data-integrity behavior across multiple spend paths, with higher concurrency and regression risk. The right issue is comparatively localized to response normalization in one provider integration and can likely be addressed with focused parsing and tests.
The left issue spans multiple translation paths and external API compatibility contracts, requiring coordinated code changes and broad regression coverage. The right appears more localized to batching and persistence-loop behavior, with focused validation and database tests.
Issue #29292 spans shared persistence and retry/batching behavior across multiple spend dimensions, requiring broader correctness, load, and regression testing. Issue #33330 is comparatively localized to budget validation and choosing the authoritative spend source, though distributed-state behavior adds some risk.
#0 of 0 · 31d18h39m26s ago — current · #import:https:::github.com:berriai:litellm post #2304
The right issue spans shared persistence, batching, retries, and multiple spend dimensions, requiring broader regression coverage and greater data-integrity risk. The left is narrower, primarily involving authentication error mapping and response headers.
discussed in #import:https:::github.com:berriai:litellm

ranked child groups

no voted pairs yet in this scope

cli
src
spread
search