fix(accounting): prioritize unattempted usage before compilation retries

This commit is contained in:
Joshua Valluru 2026-10-31 13:21:27 -07:00
parent ed4d3ae6cc
commit 2f4fa0399d
2 changed files with 6 additions and 1 deletions

View file

@ -165,7 +165,7 @@ _PENDING_COMPILATION: Final = """
SELECT payload::text AS payload FROM "LiteLLM_AccountingEvent"
WHERE kind = 'outbound_usage' AND compilation_state = 'pending'
AND (compilation_retry_at IS NULL OR compilation_retry_at <= CURRENT_TIMESTAMP)
ORDER BY recorded_at, event_id LIMIT $1::int
ORDER BY compilation_retry_at NULLS FIRST, recorded_at, event_id LIMIT $1::int
"""
_COMPILATION_RESULT: Final = """
UPDATE "LiteLLM_AccountingEvent" SET compilation_state = $2, compilation_error = $3, compilation_retry_at = NULL

View file

@ -1010,6 +1010,11 @@ async def test_failing_compilation_page_does_not_starve_later_usage(writer: _Wri
return _cost().snapshot
await LoggingCostCompiler(store, price, _TARGETS).compile_pending(limit=1)
_rows(
ledger_database,
'UPDATE "LiteLLM_AccountingEvent" SET compilation_retry_at = CURRENT_TIMESTAMP WHERE event_id = %s',
(broken.event_id,),
)
await LoggingCostCompiler(store, price, _TARGETS).compile_pending(limit=1)
assert _rows(ledger_database, "SELECT source_event_id FROM \"LiteLLM_AccountingEvent\" WHERE kind = 'cost'") == [
(healthy.event_id,)