-
-
Notifications
You must be signed in to change notification settings - Fork 11.7k
fix(responses): register cooldowns on failure + fail fast on stale encrypted_content #27820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mateo-berri
merged 3 commits into
litellm_internal_staging
from
litellm_responses_cooldown_and_affinity_failfast
May 13, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
tests/test_litellm/responses/test_responses_router_cooldown.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| """ | ||
| Regression: Responses API router must register cooldowns on deployment | ||
| failures. Previously the Responses API path built ``litellm_params`` without | ||
| ``model_info``, so ``Router.deployment_callback_on_failure`` exited early via | ||
| the "No model_info found" branch and the failing deployment was never added | ||
| to the cooldown set. | ||
| """ | ||
|
|
||
| import os | ||
| import sys | ||
| from unittest.mock import AsyncMock, patch | ||
|
|
||
| import httpx | ||
| import pytest | ||
|
|
||
| sys.path.insert(0, os.path.abspath("../..")) | ||
|
|
||
| import litellm | ||
| from litellm.router_utils.cooldown_handlers import _async_get_cooldown_deployments | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_responses_api_rate_limit_marks_deployment_for_cooldown(): | ||
| failing_deployment_id = "deployment-rate-limited" | ||
|
|
||
| router = litellm.Router( | ||
| model_list=[ | ||
| { | ||
| "model_name": "openai.gpt-5.1-codex", | ||
| "litellm_params": { | ||
| "model": "openai/gpt-5.1-codex", | ||
| "api_key": "mock-api-key-1", | ||
| }, | ||
| "model_info": {"id": failing_deployment_id}, | ||
| }, | ||
| { | ||
| "model_name": "openai.gpt-5.1-codex", | ||
| "litellm_params": { | ||
| "model": "openai/gpt-5.1-codex", | ||
| "api_key": "mock-api-key-2", | ||
| }, | ||
| "model_info": {"id": "deployment-healthy"}, | ||
| }, | ||
| ], | ||
| num_retries=0, | ||
| cooldown_time=60, | ||
| ) | ||
|
|
||
| rate_limit_error = litellm.RateLimitError( | ||
| message="upstream throttled", | ||
| llm_provider="openai", | ||
| model="openai/gpt-5.1-codex", | ||
| response=httpx.Response( | ||
| status_code=429, | ||
| request=httpx.Request("POST", "https://api.openai.com/v1/responses"), | ||
| ), | ||
| ) | ||
|
|
||
| def pin_to_failing_deployment(seq): | ||
| for d in seq: | ||
| if d["model_info"]["id"] == failing_deployment_id: | ||
| return d | ||
| return seq[0] | ||
|
|
||
| with ( | ||
| patch( | ||
| "litellm.llms.custom_httpx.llm_http_handler.BaseLLMHTTPHandler.async_response_api_handler", | ||
| new_callable=AsyncMock, | ||
| side_effect=rate_limit_error, | ||
| ), | ||
| patch( | ||
| "litellm.router_strategy.simple_shuffle.random.choice", | ||
| side_effect=pin_to_failing_deployment, | ||
| ), | ||
| ): | ||
| with pytest.raises(litellm.RateLimitError): | ||
| await router.aresponses( | ||
| model="openai.gpt-5.1-codex", | ||
| input="hi", | ||
| ) | ||
|
|
||
| cooldown_ids = await _async_get_cooldown_deployments( | ||
| litellm_router_instance=router, parent_otel_span=None | ||
| ) | ||
| assert failing_deployment_id in cooldown_ids, ( | ||
| f"Responses API failure callback did not register cooldown for " | ||
| f"{failing_deployment_id!r}; cooldown set was {cooldown_ids}" | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RateLimitError discards passed retry-after headers internally
Medium Severity
The
RateLimitErrorconstructor internally rebuildsself.responsefrom scratch, extracting only the headers from the passedresponse. While theretry-afterheader is preserved through this extraction, the constructed error'sself.responseURL is hardcoded to" https://cloud.google.com/vertex-ai/"(note the leading space) inside the exception class. This is a pre-existing quirk, but importantly the PR description promises that "OpenAI-compatible SDKs respectRetry-Afteron 429s." In practice, the router's own retry logic inasync_function_with_retriesreadsretry-afterfromexception_headersvia_get_response_headers, not fromexception.response.headers. Since the exception raised here escapes fromasync_filter_deployments(a pre-call check) — which is before the LLM call — the router's retry-with-fallback machinery inasync_function_with_retriescatches it, but_get_response_headersmay not extract headers the same way from this synthetically-constructed exception, potentially causing the router to ignore theRetry-Aftervalue during its own retry logic and use its default cooldown time instead.Reviewed by Cursor Bugbot for commit e27110d. Configure here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bugbot Autofix determined this is a false positive.
RateLimitError preserves the
retry-afterheader on self.response.headers (only the request URL is rebuilt), and both_get_response_headersand_time_to_sleep_before_retrycorrectly fall back toexception.response.headers, so the router's retry/cooldown logic does honor the Retry-After value from this synthetic exception.You can send follow-ups to the cloud agent here.