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

#29342 [Bug]: LiteLLM_SpendLogToolIndex is never pruned — grows unbounded, orphaned after spend log retention cleanup

  • State: open
  • Author: @psarma89

## Description

`LiteLLM_SpendLogToolIndex` is insert-only and has **no retention / pruning anywhere in the codebase**. When the spend-log retention cleanup (`maximum_spend_logs_retention_period`) deletes old `LiteLLM_SpendLogs` rows, the matching `SpendLogToolIndex` rows are **left behind**, so orphaned tool-index rows accumulate and the table grows without bound — even when retention is correctly configured.

## Root cause

1. **No cascade.** `LiteLLM_SpendLogToolIndex` has no foreign key to `LiteLLM_SpendLogs`; its only constraint is `PRIMARY KEY (request_id, tool_name)` (see `schema.prisma` and the `..._add_spend_log_tool_index/migration.sql`). So deleting a `SpendLogs` row does not remove its tool-index rows.

2. **Cleanup deletes `SpendLogs` only.** `SpendLogCleanup._delete_old_logs` (`litellm/proxy/db/db_transaction_queue/spend_log_cleanup.py`) runs: ```sql DELETE FROM "LiteLLM_SpendLogs" WHERE "request_id" IN ( SELECT "request_id" FROM "LiteLLM_SpendLogs" WHERE "startTime" < $1::timestamptz LIMIT $2 ) ``` It never touches `LiteLLM_SpendLogToolIndex`.

3. **No delete path exists anywhere.** The only references to `SpendLogToolIndex` in the rep…

GitHub resolver

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

Refresh page
vote history (2 events)
#0 of 0 · 31d18h20m47s ago — entered · #import:https:::github.com:berriai:litellm post #2712
The right issue is harder because it requires changing cache-key semantics across multiple cache backends and request paths, incorporating authenticated tenant context, preserving configurable behavior and compatibility, and validating isolation under both exact and semantic matching. The left issue is comparatively localized to retention cleanup and database consistency, with bounded schema/query and migration considerations.
#0 of 0 · 31d17h50m55s ago — current · #import:https:::github.com:berriai:litellm post #3234
The right-hand issue is harder because it spans retention semantics, database cleanup ordering, migration or indexing decisions, batching, and compatibility testing across supported databases. The left-hand issue is narrower: coordinating existing shutdown lifecycle, draining buffers safely, and adding race/failure-path tests.
discussed in #import:https:::github.com:berriai:litellm

ranked child groups

no voted pairs yet in this scope

cli
src
spread
search