Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/rotator_library/background_refresher.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,10 @@ async def _run_provider_background_job(

async def _run(self):
"""The main loop for OAuth token refresh."""
await self._client.initialize_usage_managers()
# Initialize credentials (load persisted tiers) before starting
# Initialize credentials first to populate tier/project caches
await self._initialize_credentials()
# Then initialize usage managers which reads from those caches
await self._client.initialize_usage_managers()
Comment on lines +270 to +273
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reordering correctly addresses the initialization dependency within the refresher loop. By calling _initialize_credentials() first, you ensure that the provider plugins have performed their discovery (populating the tier caches) before initialize_usage_managers() attempts to read that metadata.

One thing to note: RotatingClient.initialize_usage_managers() is also called in RotatingClient.__aenter__ and at line 606 of src/proxy_app/main.py. Because of the self._usage_initialized guard in that method, those early calls might still "win" and initialize the managers with None tiers before this background task reaches line 271.

To fully resolve this across the application, you might consider removing the early call in main.py or having initialize_usage_managers ensure that discovery has completed before proceeding.


# Start provider-specific background jobs with their own timers
self._start_provider_background_jobs()
Expand Down
Loading