From cd362841389dcc6adaee01e086eb0ad1bbda3b7b Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Wed, 28 Oct 2026 23:11:25 -0700 Subject: [PATCH] fix(responses): pin a comparison id's deployment only when it decodes exactly A member key could prefix a forged wrapper with an extra resp_ and the loose decoder still read its model_id, so the request (or a whole WebSocket) was pinned to a deployment the caller picked Also calls drops_params in the compact transform, since main renamed the helper and left one caller on the old name --- litellm/llms/openai/responses/transformation.py | 2 +- litellm/responses/utils.py | 8 ++++++-- .../pre_call_checks/test_deployment_affinity_check.py | 10 ++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/litellm/llms/openai/responses/transformation.py b/litellm/llms/openai/responses/transformation.py index 2a5565151f2..ba8208106c5 100644 --- a/litellm/llms/openai/responses/transformation.py +++ b/litellm/llms/openai/responses/transformation.py @@ -1237,7 +1237,7 @@ class OpenAIResponsesAPIConfig(BaseResponsesAPIConfig): def compact_dropped_params(self, litellm_params: GenericLiteLLMParams) -> frozenset[str]: if self.custom_llm_provider not in _PROVIDERS_WITH_STRICT_COMPACT_PARAMS: return frozenset() - if _drops_params(litellm_params): + if drops_params(litellm_params): return _COMPACT_TRACKING_PARAMS | _COMPACT_REJECTED_PARAMS return _COMPACT_TRACKING_PARAMS diff --git a/litellm/responses/utils.py b/litellm/responses/utils.py index 105e500a91a..d88292fcfc8 100644 --- a/litellm/responses/utils.py +++ b/litellm/responses/utils.py @@ -837,9 +837,13 @@ class ResponsesAPIRequestUtils: previous_response_id: Final = request.get("previous_response_id") if previous_response_id is not None: return ResponsesAPIRequestUtils.get_model_id_from_response_id(str(previous_response_id)) - compared_model_id: Final = ResponsesAPIRequestUtils.get_model_id_from_response_id( - ResponsesAPIRequestUtils.comparison_response_id(request) + comparison_id: Final = ResponsesAPIRequestUtils.comparison_response_id(request) + decoded: Final = ( + None + if comparison_id is None + else ResponsesAPIRequestUtils.decode_exact_responses_api_response_id(comparison_id) ) + compared_model_id: Final = None if decoded is None else decoded.get("model_id") or None return None if compared_model_id in failed_deployment_ids else compared_model_id @staticmethod diff --git a/tests/unit/router_utils/pre_call_checks/test_deployment_affinity_check.py b/tests/unit/router_utils/pre_call_checks/test_deployment_affinity_check.py index 32dd075de6b..1261f04548b 100644 --- a/tests/unit/router_utils/pre_call_checks/test_deployment_affinity_check.py +++ b/tests/unit/router_utils/pre_call_checks/test_deployment_affinity_check.py @@ -1341,6 +1341,16 @@ def _response_id_from(model_id: str) -> str: ("C",), id="websocket-first-frame-routing-hint", ), + pytest.param( + {"prompt_cache_options": {"comparison_response_id": f"resp_{_response_id_from('B')}"}}, + ("A", "B", "C"), + id="comparison-with-an-extra-resp-prefix-pins-nothing", + ), + pytest.param( + {COMPARISON_RESPONSE_ID_ROUTING_HINT: ComparisonRoutingHint(f"resp_{_response_id_from('C')}")}, + ("A", "B", "C"), + id="websocket-routing-hint-with-an-extra-resp-prefix-pins-nothing", + ), pytest.param( {COMPARISON_RESPONSE_ID_ROUTING_HINT: _response_id_from("C")}, ("A", "B", "C"),