From 2f6742a700ea54a8e2946b40f8ec2825914e9a16 Mon Sep 17 00:00:00 2001 From: Praveen Ghuge Date: Sun, 26 Apr 2026 21:43:43 +0530 Subject: [PATCH] fix(mavvrik): reschedule background job after update_settings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PUT /mavvrik/settings saved new credentials to DB but the running Orchestrator kept its old Client with stale api_endpoint/connection_id — directly contradicting "update credentials without restarting". Fix: after saving merged credentials, reschedule the job with a new Client/Uploader/Orchestrator built from the merged values using replace_existing=True — same pattern as initialize(). The updated credentials take effect on the next scheduler tick. Co-Authored-By: Claude Sonnet 4.6 (1M context) --- litellm/integrations/mavvrik/__init__.py | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/litellm/integrations/mavvrik/__init__.py b/litellm/integrations/mavvrik/__init__.py index c98aebf22ec..40ad45eeb65 100644 --- a/litellm/integrations/mavvrik/__init__.py +++ b/litellm/integrations/mavvrik/__init__.py @@ -221,6 +221,37 @@ class Service: ) await self._settings.save(**merged) + + # Reschedule the background job with the new credentials so the + # running Orchestrator uses the merged values immediately — + # without this, the in-memory Client keeps old credentials until restart. + from litellm.constants import ( + MAVVRIK_EXPORT_INTERVAL_MINUTES, + MAVVRIK_EXPORT_USAGE_DATA_JOB_NAME, + ) + + import litellm.proxy.proxy_server as _pserver + + _scheduler = getattr(_pserver, "scheduler", None) + if _scheduler is not None: + client = Client( + api_key=merged["api_key"], + api_endpoint=merged["api_endpoint"], + connection_id=merged["connection_id"], + ) + uploader = Uploader(client=client) + orchestrator = Orchestrator(client=client, uploader=uploader) + _scheduler.add_job( + orchestrator.run, + "interval", + minutes=MAVVRIK_EXPORT_INTERVAL_MINUTES, + id=MAVVRIK_EXPORT_USAGE_DATA_JOB_NAME, + replace_existing=True, + ) + verbose_proxy_logger.info( + "mavvrik: background job rescheduled with updated credentials" + ) + return {"message": "Mavvrik settings updated successfully", "status": "success"} # ------------------------------------------------------------------