From 482ac7ec61c5ef6ec2e836e085c8801e03798897 Mon Sep 17 00:00:00 2001 From: Praveen Ghuge Date: Tue, 23 Jun 2026 16:36:12 +0530 Subject: [PATCH] fix(mavvrik): use now as end_time for yesterday's export window LiteLLM_DailyUserSpend rows for a given date get their updated_at bumped by the spend flush job throughout the next morning. The core database query filters on updated_at, so capping end_time at midnight (yesterday + 1 day) missed any spend rows flushed after midnight. Fix: pass now (cron fire time) as end_time for the daily "yesterday" window so all fully-settled rows are captured regardless of when the flush job ran. Verified: claude-3-5-sonnet BilledCost went from 0.0 to ~$2.40 per row in the exported FOCUS CSV. --- .../mavvrik_focus/mavvrik_focus_logger.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/litellm/integrations/mavvrik_focus/mavvrik_focus_logger.py b/litellm/integrations/mavvrik_focus/mavvrik_focus_logger.py index 26c5efd7ea7..d53b5ea1a31 100644 --- a/litellm/integrations/mavvrik_focus/mavvrik_focus_logger.py +++ b/litellm/integrations/mavvrik_focus/mavvrik_focus_logger.py @@ -178,7 +178,7 @@ class MavvrikFocusLogger(FocusLogger): last_ingested = _parse_metrics_marker(marker) # Catch up missed dates, capped at _MAX_CATCHUP_DAYS. - # last_ingested=None means metricsMarker=0 (fresh connector, never ingested) -- + # last_ingested=None means metricsMarker=0 (fresh connector, never ingested) — # treat the same as being _MAX_CATCHUP_DAYS behind so we export all available history. earliest_catchup = yesterday - timedelta(days=self._MAX_CATCHUP_DAYS - 1) if last_ingested is None or last_ingested < yesterday: @@ -188,7 +188,10 @@ class MavvrikFocusLogger(FocusLogger): else max(last_ingested + timedelta(days=1), earliest_catchup) ) - if last_ingested is not None and last_ingested + timedelta(days=1) < earliest_catchup: + if ( + last_ingested is not None + and last_ingested + timedelta(days=1) < earliest_catchup + ): verbose_proxy_logger.warning( "Mavvrik FOCUS export: metricsMarker is more than %d days behind " "(%s). Catching up from %s only; earlier data will not be re-exported.", @@ -210,10 +213,13 @@ class MavvrikFocusLogger(FocusLogger): await self._export_window(window=window, limit=None) catch_up_date += timedelta(days=1) - # Export yesterday's window (the normal daily run) + # Export yesterday's window (the normal daily run). + # Use `now` as end_time so spend rows flushed after midnight are included. + # LiteLLM's DailyUserSpend rows for a given date keep getting updated_at + # bumped as the flush job runs; capping at midnight would miss those updates. window = FocusTimeWindow( start_time=yesterday, - end_time=yesterday + timedelta(days=1), + end_time=now, frequency="daily", ) await self._export_window(window=window, limit=None)