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

#35537 [Bug]: Spend entity updates are launched fire-and-forget and failures are swallowed

  • State: open
  • Author: @emerzon

### Summary

`DBSpendUpdateWriter.update_database()` awaits the spend-log insert but launches the user, key, team, organization, tag, agent, and daily spend updates with `asyncio.create_task()`. The returned coroutine completes before those updates run, and each helper failure is caught and logged at debug level inside the background task

### Current behavior

The writer contains:

~~~python asyncio.create_task( self._batch_database_updates(...) ) ~~~

`_batch_database_updates()` runs the entity and daily update helpers sequentially, but wraps every helper in its own `try/except Exception` and only emits a debug message. The task is not retained by the writer for a later await, retry, or graceful-shutdown drain

The cost callback therefore treats `await update_database()` as completion even though the durable entity counters may not have been queued or written

This is different from the spend-log write failure covered by [#33873](https://github.com/BerriAI/litellm/issues/33873), because the spend-log insert is awaited before this background task is created

### Reproduction

Patch one of the helper methods to fail and call `update_database()`:

~~~python writer._update_team_d…

GitHub resolver

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

Refresh page
vote history (1 events)
#0 of 0 Ā· 31d19h3m43s ago — entered Ā· #import:https:::github.com:berriai:litellm post #1904
The left issue requires redesigning asynchronous persistence semantics across several update paths, including completion guarantees, failure propagation, retry or shutdown handling, and regression coverage. The right issue is more localized to request validation and error handling in the MCP gateway, with narrower integration impact.
discussed in #import:https:::github.com:berriai:litellm

ranked child groups

no voted pairs yet in this scope

cli
src
spread
search