﻿# LiteLLM retains provably unsent usage rollups after a database disconnect

Test unsent, partially flushed and ambiguous rollup failures separately; recovery should restore missing usage without replaying writes that may already have committed.

Author: Retrivium team
Updated: 2026-11-15
Canonical URL: https://retrivium.ai/journal/week46-agent-litellm-usage-rollup-unsent-recovery/
Language: en

LiteLLM v1.111.0-dev.4 fixes tool-usage and auto-router rollups lost after database disconnection. The November 15 prerelease requeues work known not to have reached the database, while preserving the existing treatment of ambiguous failures. This boundary matters: reconnecting successfully and replaying every uncertain write are different behaviors, and only the latter can create duplicate accounting.

## Build an independent usage oracle

Send a known number of synthetic routed turns and harmless tool calls while recording their identities outside the rollup path. Compare those observations with spend logs and rollup totals. The PR targets cases where request logs can recover while aggregate usage remains incomplete. A test checking only HTTP success or only individual spend rows would miss the missing totals that operators use to understand tool and routing activity.

## Confirmed-unsent failure has a safe replay boundary

Block a synthetic database write before it is sent, restore connectivity and verify the queued rollup appears once. Keep the worker alive for this initial fixture so the test targets reconnect recovery rather than process durability. Record retry count and final queue state. The release does not turn an in-memory retained item into a guaranteed durable record across every possible crash or restart.

## Partial flushes must retain only the remainder

Allow part of a synthetic batch to finish and fail the remaining unsent portion. After recovery, inspect each turn identity and its contribution to the total. Replaying the entire batch can make the aggregate look healthy while double-counting completed turns. Use distinct amounts so duplicate records are easy to identify. This acceptance case checks the documented selective recovery boundary rather than treating every batch-level exception as evidence that nothing was written.

## Ambiguity should remain visible

Simulate a lost acknowledgement after a possible commit and inspect the existing ambiguous-failure behavior separately. The PR deliberately does not replay these writes. Report any unreconciled difference instead of inventing exact accounting from a recovered connection. A useful adoption result identifies what was confirmed unsent, what was already written and what remains uncertain, allowing operators to understand the limits of the repaired rollup path.

## Sources

- [LiteLLM v1.111.0-dev.4 prerelease notes](https://github.com/BerriAI/litellm/releases/tag/v1.111.0-dev.4)
- [LiteLLM implementation and review #51706](https://github.com/BerriAI/litellm/pull/51706)

## Related reading

- [Retrying generation POSTs: idempotency must be explicit](/journal/provider-post-retry-idempotency-ledger/)
- [LiteLLM budgets: periods, shared limits and overrun tests](/journal/litellm-budget-reset/)
