8 views
-/https://github.com/berriai/litellm/issues/35531
GitHub · issue

#35531 [Bug]: In-memory spend transactions are lost when the database commit fails

  • State: open
  • Author: @emerzon

### Summary

The default non-Redis spend update path drains its in-memory queues before committing them to the database. If the commit fails, the drained transactions are not restored, so spend updates disappear

### Current behavior

The default for `use_redis_transaction_buffer` is `False`

`_commit_spend_updates_to_db_without_redis_buffer()` first calls:

~~~python db_spend_update_transactions = await ( self.spend_update_queue .flush_and_get_aggregated_db_spend_update_transactions() ) await self._commit_spend_updates_to_db( db_spend_update_transactions=db_spend_update_transactions, ... ) ~~~

There is no `try/except` that restores the flushed batch when `_commit_spend_updates_to_db()` fails. The daily user, team, organization, end-user, and agent queues are flushed in the same method and are also not restored if their subsequent database update fails

### Reproduction

A focused unit test can inject one transaction and force the commit to fail:

~~~python queue = writer.spend_update_queue await queue.add_update(transaction)

with patch.object( writer, "_commit_spend_updates_to_db", new=AsyncMock(side_effect=RuntimeError("database unavailable")), ): …

GitHub resolver

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

Refresh page
vote history (2 events)
#0 of 0 · 31d18h37m28s ago — entered · #import:https:::github.com:berriai:litellm post #2346
31343 is harder because it spans cross-provider request translation, tool-schema normalization, fallback execution, and external SDK compatibility, while 35531 is a more localized queue-restoration and error-handling change.
#0 of 0 · 31d17h44m42s ago — current · #import:https:::github.com:berriai:litellm post #3233
The right issue is harder because it requires failure-safe queue semantics across multiple update paths, retry/idempotency validation, and concurrency-sensitive tests; the left issue is comparatively localized route-authorization compatibility work.
discussed in #import:https:::github.com:berriai:litellm

ranked child groups

no voted pairs yet in this scope

cli
src
spread
search