Skip to content

fix(azure): include effective max_retries in client cache key - #44315

Closed
huhumeng2 wants to merge 2 commits into
BerriAI:mainfrom
huhumeng2:fix-azure-client-cache-retries
Closed

huhumeng2 wants to merge 2 commits into
BerriAI:mainfrom
huhumeng2:fix-azure-client-cache-retries

Conversation

@huhumeng2

@huhumeng2 huhumeng2 commented Oct 3, 2026 •

Copy link
Copy Markdown

TLDR

Problem this solves:

  • Azure retries reuse clients with outdated retry limits

How it solves it:

  • Include the effective retry limit in the client cache key
  • Preserve zero retries and reuse equivalent default configurations

User Flow

Before: an Azure chat request retries more often than configured

  1. Configure an Azure deployment with num_retries=3
  2. Send a chat request to an endpoint that consistently returns HTTP 429
  3. Receive RateLimitError after 16 upstream requests

After: the same request follows the retry behavior of the OpenAI route

  1. Configure an Azure deployment with num_retries=3
  2. Send a chat request to an endpoint that consistently returns HTTP 429
  3. Receive RateLimitError after 7 upstream requests

Relevant issues

Fixes #44180

Pre-Submission checklist

  • I have added meaningful tests
  • The handful of test files covering my change pass locally
  • My PR passes all required CI/CD checks
  • My PR only solves one specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review

This remains a draft pending real Azure validation and current CI and automated review results

Local validation

Validated on Windows with Python 3.12, OpenAI SDK 2.54.0 and httpx 0.28.1 at eeef7c77b88b8c5e26d2c102a470df1f07ebf9e0, after merging main at 98465fe2. The diff against that main still changes only the Azure utility and its existing unit test file

The regression constructs real SDK clients and uses the real client cache. It covers synchronous and asynchronous clients with dated Azure API versions and v1, switching retries from 3 to 0 and back, the reverse order, and reuse for omitted, None, and explicit default values

python -m pytest tests/unit/llms/azure/test_azure_common_utils.py -q --tb=short --basetemp=../pytest-temp-azure
1 failed, 114 passed, 33 skipped

The failure is the existing test_default_max_retries_env_var_reaches_azure_sdk_client. The shared host-environment fixture removes Windows system variables, causing its child process to fail while importing asyncio with WinError 10106, before any Azure code runs. The same test passes when run separately without the parent fixture:

python -m pytest tests/unit/llms/azure/test_azure_common_utils.py --confcutdir=tests/unit/llms/azure -k default_max_retries_env_var -q
1 passed, 147 deselected

All 12 new cases pass with the normal shared fixtures:

python -m pytest tests/unit/llms/azure/test_azure_common_utils.py -k azure_client_cache_respects_effective_max_retries -q
12 passed, 136 deselected

Mutation check: removing the four production lines makes the eight retry-switching cases fail on the SDK clients' actual max_retries values, while the four equivalent-default controls still pass. Restoring the lines returns all 12 cases to passing

Ruff 0.16.10 reports no added diagnostics against the matching files on main. The production file passes formatting; the existing test file has formatting differences outside this change. git diff --check passes. Full lint and the Linux suite remain for current CI

The previously failing OSV check reported an unchanged frontend dependency. Upstream #44347 already added its policy exception for the unfixed advisory. This branch now includes that upstream change through the main merge; this PR adds no security exception of its own. The current-tip OSV scan now passes: https://github.com/BerriAI/litellm/actions/runs/37807038030/job/113413912259

Local HTTP 429 reproduction

Fresh runs use the local scripted HTTP 429 server from #44180 with real LiteLLM and SDK HTTP requests. These are integration evidence only. No Azure deployment is available, so they do not satisfy the template's real-provider proof requirement

For each checkout, run the issue's server and completion loop with num_retries=3, recording x-stainless-retry-count. Include an OpenAI control, dated Azure API 2025-04-01-preview, and Azure v1. The v1 case uses the same server root and api_version="v1"

Before (98465fe)

  1. Run the local reproduction against main at the current merge base
  2. Observe:
OpenAI:      7 requests [0, 1, 2, 3, 0, 0, 0]
Azure dated: 16 requests [0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3]
Azure v1:    16 requests [0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3]

After (eeef7c7)

  1. Repeat the same local reproduction against this PR tip
  2. Observe:
OpenAI:      7 requests [0, 1, 2, 3, 0, 0, 0]
Azure dated: 7 requests [0, 1, 2, 3, 0, 0, 0]
Azure v1:    7 requests [0, 1, 2, 3, 0, 0, 0]

Type

Bug Fix

Caveats

Low

  • Real Azure end-to-end validation remains outstanding
  • Current CI and automated review results remain outstanding
  • Windows shared-fixture subprocess failure remains outside this fix
  • Explicitly supplied clients retain their own retry configuration

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov

codecov Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment thread litellm/llms/azure/common_utils.py Fixed
@codspeed

codspeed Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing huhumeng2:fix-azure-client-cache-retries (eeef7c7) with main (f824d11)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (98465fe) during the generation of this report, so f824d11 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

Copy link
Copy Markdown
Author

Status follow-up: I checked and resolved the CodeQL locals() review thread with an explanation of the actual cache-key data flow and an isolated source-level verification; no code change was needed for that warning.

The remaining red OSV job reports braces@3.0.3 in ui/litellm-dashboard/package-lock.json (GHSA-vfj7-8cjw-p6xm). This PR changes only the Azure utility and its unit tests, not that lockfile, so this appears unrelated to the retry-cache fix: https://github.com/BerriAI/litellm/actions/runs/37091816018/job/111113566449

The PR remains a draft because real Azure service validation and the remaining repository requirements are still outstanding. I have not rerun the SDK suite or claimed a live Azure pass in this follow-up.

@huhumeng2 huhumeng2 closed this Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Azure route: cached client ignores max_retries, so num_retries re-attempts keep the SDK's retries (16 requests instead of 7)

3 participants