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
This commit is contained in:
mateo-berri 2026-10-28 23:11:25 -07:00
parent 34e740eabc
commit cd36284138
3 changed files with 17 additions and 3 deletions

View file

@ -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

View file

@ -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

View file

@ -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"),